Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Latest
* [#292](https://github.com/cleverage/process-bundle/issues/292) Remove the classes, methods and options deprecated during v5: `ProcessState::getReturnCode()` / `setReturnCode()` (#503), the `cleverage_process.event_listener.data_queue` service and `DataQueueEventListener` (#311), `CheckSerializerCompilerPass`, the `KernelInterface` argument and the `$kernel` / `$logDir` properties of `CommandRunnerTask`, `ProcessLauncherTask` and `SubprocessInstance` (#318), the `process_options` option of the `process_launcher` task (see `UPGRADE.md`). Update documentation and tests.
* [#292](https://github.com/cleverage/process-bundle/issues/292) Apply the behaviours announced by the deprecations of v5: an exception thrown by the `initialize()` of a task makes the process fail before any task is executed, with a `ProcessFailedException` (#222); the `event_dispatcher` task no longer dispatches its event under the class name of the event too when `event_name` is set (#189); a target property of an array destination that is neither a simple property name nor an index notation (`address.city`) throws an `UnexpectedValueException` in the `mapping` transformer (#117); the `additional_parameters` option of the `callback` transformer is removed, use `right_parameters`; a negative `flush_every` of the `counter` task is rejected (#491) (see `UPGRADE.md`). Update documentation and tests.
* [#279](https://github.com/cleverage/process-bundle/issues/279) The 109 classes marked `@final since 5.4` are `final` (engine, registries, models, configurations, events, `CleverAgeProcessBundle`, concrete tasks and transformers): they can no longer be extended nor doubled by PHPUnit. The services of the bundle are typed on `ProcessManagerInterface`, `ProcessConfigurationRegistryInterface` and `TransformerRegistryInterface`, so that a decorator is injected everywhere; `ProcessManagerInterface` declares `getProcessHistory()` and `getTaskConfiguration()`, `ProcessConfigurationRegistryInterface` declares `getProcessCodes()`, and both extend `ResetInterface` (a decorator receives the `kernel.reset` tag and must delegate `reset()`). `PregFilterTransformer::transform()` returns `?string`, the `$transformerRegistry` property of `TransformerTrait` is typed on `TransformerRegistryInterface`, `SplFile::readLine()` no longer has its unused `$length` parameter (see `UPGRADE.md`). Update documentation and tests.
* [#505](https://github.com/cleverage/process-bundle/issues/505) Consistent names for the equivalent options of the tasks: `filename` is renamed `file_path` (`file_reader`, `file_writer`, `line_reader`) and `base_folder_path` is renamed `base_path` (`input_folder_browser`), without deprecation in 5.x; `input_folder_browser` adds a single `/` between a non-empty `base_path` and the input, as `input_csv_reader` does (see `UPGRADE.md`). Update documentation and tests.

## Changes
* [#428](https://github.com/cleverage/process-bundle/issues/428) Tests on PHPUnit 12.5 and 13 (PHPUnit 10 and 11 dropped), with the lowest dependencies on PHP 8.3 and 8.5.
Expand Down
28 changes: 28 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ A line that `csv_reader` or `input_csv_reader` cannot read (number of columns no
cannot be parsed) sends `['csv_file' => <path>, 'csv_line' => <line number>, 'csv_values' => <values read>]` to the
error output. Before, `input_csv_reader` sent its input, the file path: read it from `[csv_file]` in the error branch.

### Renamed task options

Equivalent options have the same name in every task (without deprecation in 5.x):

| Tasks | 5.x | 6.0 |
|---------------------------------------------|--------------------|-------------|
| `file_reader`, `file_writer`, `line_reader` | `filename` | `file_path` |
| `input_folder_browser` | `base_folder_path` | `base_path` |

A former name fails when the process starts with `The option "filename" does not exist. Defined options are: …`.
Find them in the processes:

```bash
grep -rnE '\b(filename|base_folder_path):' config/
```

and rename the occurrences in the options of the tasks listed above only. The search also finds a task named
`filename`, a `filename` key of the data built by the process (`constant_output`, `mapping`...), or the `filename`
option of a bridge task (`archive_zip` / `archive_unzip`, renamed in archive-process-bundle v3.0, see its upgrade
guide): leave those unchanged here. A class extending `FileReaderTask` or `LineReaderTask` reads
`$options['file_path']`.

`input_folder_browser` now adds a single `/` between a non-empty `base_path` and the input, as `input_csv_reader`
does: `base_path: /data` and the input `imports` browse `/data/imports` (`/dataimports` before). A base path used as a
prefix of the folder name (`/data/prefix_`) must be moved to the input. With a non-empty `base_path`, remove the
leading `/` of the input: `base_path: /data` and the input `/imports` browse `/data//imports` (the folder is found, but
the file paths output contain `//`).

### Code of the transformers

The code of a transformer is only given by the `code` attribute of its `cleverage.transformer` tag, or by the
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/tasks/file_reader_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Underlying method is [file_get_contents](https://www.php.net/manual/en/function.
Options
-------

| Code | Type | Required | Default | Description |
|------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------|
| `filename` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable |
| Code | Type | Required | Default | Description |
|-------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------|
| `file_path` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable |

Examples
--------
Expand All @@ -35,7 +35,7 @@ Examples
entry:
task: file_reader
options:
filename: '%kernel.project_dir%/var/data/sample.txt'
file_path: '%kernel.project_dir%/var/data/sample.txt'
outputs: [debug]
```

Expand Down
10 changes: 5 additions & 5 deletions docs/reference/tasks/file_writer_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Underlying method is Symfony `Filesystem::dumpFile()` (parent directories are cr
Possible outputs
----------------

`string`: path of the written file (value of the `filename` option).
`string`: path of the written file (value of the `file_path` option).

Options
-------

| Code | Type | Required | Default | Description |
|------------|----------|:--------:|---------|---------------------------|
| `filename` | `string` | **X** | | Path of the file to write |
| Code | Type | Required | Default | Description |
|-------------|----------|:--------:|---------|---------------------------|
| `file_path` | `string` | **X** | | Path of the file to write |

Examples
--------
Expand All @@ -35,7 +35,7 @@ Examples
write_file:
task: file_writer
options:
filename: '%kernel.project_dir%/var/data/result.txt'
file_path: '%kernel.project_dir%/var/data/result.txt'
```

Notes
Expand Down
16 changes: 8 additions & 8 deletions docs/reference/tasks/input_folder_browser_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Task reference
Accepted inputs
---------------

`string`: path of the folder to browse, prefixed by the `base_folder_path` option. It must be an existing readable
`string`: path of the folder to browse, prefixed by the `base_path` option. It must be an existing readable
directory.

The folder path is released once its files have all been iterated, so each input (the same path again or a different
Expand All @@ -35,11 +35,11 @@ set as error output.
Options
-------

| Code | Type | Required | Default | Description |
|--------------------|-----------------------|:--------:|-----------|----------------------------------------------------------------------------------------------------------------|
| `base_folder_path` | `string` | | `''` | Prepended to the input path, without adding any separator |
| `name_pattern` | `string\|array\|null` | | `null` | Restrict files by name using a pattern (glob, regexp or string) or an array of patterns (see `Finder::name()`) |
| `empty_log_level` | `string` | | `warning` | Log level used when no file is found, one of the `Psr\Log\LogLevel` constants |
| Code | Type | Required | Default | Description |
|-------------------|-----------------------|:--------:|-----------|----------------------------------------------------------------------------------------------------------------|
| `base_path` | `string` | | `''` | Prepended to the input path; when not empty, followed by a single `/` (a trailing `/` is not doubled) |
| `name_pattern` | `string\|array\|null` | | `null` | Restrict files by name using a pattern (glob, regexp or string) or an array of patterns (see `Finder::name()`) |
| `empty_log_level` | `string` | | `warning` | Log level used when no file is found, one of the `Psr\Log\LogLevel` constants |

The `folder_path` option of [FolderBrowserTask](folder_browser_task.md) is removed: the path comes from the input.

Expand All @@ -51,12 +51,12 @@ Examples
entry:
task: constant_output
options:
output: '/var/data'
output: 'var/data'
outputs: [directory]
directory:
task: input_folder_browser
options:
base_folder_path: '%kernel.project_dir%'
base_path: '%kernel.project_dir%'
outputs: [read]
read:
task: input_file_reader
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/tasks/line_reader_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Underlying class is [SplFileObject](https://www.php.net/manual/en/class.splfileo
Options
-------

| Code | Type | Required | Default | Description |
|------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------|
| `filename` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable |
| Code | Type | Required | Default | Description |
|-------------|----------|:--------:|---------|------------------------------------------------------------------------------------------------------------------|
| `file_path` | `string` | **X** | | Path of the file to read. An `UnexpectedValueException` is thrown if the file does not exist or is not readable |

Examples
--------
Expand All @@ -40,7 +40,7 @@ Examples
entry:
task: line_reader
options:
filename: '%kernel.project_dir%/var/data/sample.txt'
file_path: '%kernel.project_dir%/var/data/sample.txt'
outputs: [trim]
trim:
task: transformer
Expand Down
16 changes: 8 additions & 8 deletions src/Task/File/FileReaderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class FileReaderTask extends AbstractConfigurableTask
public function execute(ProcessState $state): void
{
$options = $this->getOptions($state);
$filename = $options['filename'];
$filePath = $options['file_path'];

if (!file_exists($filename)) {
throw new UnexpectedValueException("File does not exists: '{$filename}'");
if (!file_exists($filePath)) {
throw new UnexpectedValueException("File does not exists: '{$filePath}'");
}

if (!is_readable($filename)) {
throw new UnexpectedValueException("File is not readable: '{$filename}'");
if (!is_readable($filePath)) {
throw new UnexpectedValueException("File is not readable: '{$filePath}'");
}

$state->setOutput(file_get_contents($filename));
$state->setOutput(file_get_contents($filePath));
}

protected function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['filename']);
$resolver->setAllowedTypes('filename', ['string']);
$resolver->setRequired(['file_path']);
$resolver->setAllowedTypes('file_path', ['string']);
}
}
8 changes: 4 additions & 4 deletions src/Task/File/FileWriterTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function execute(ProcessState $state): void
$options = $this->getOptions($state);

$fs = new Filesystem();
$fs->dumpFile($options['filename'], $state->getInput());
$fs->dumpFile($options['file_path'], $state->getInput());

$state->setOutput($options['filename']);
$state->setOutput($options['file_path']);
}

protected function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['filename']);
$resolver->setAllowedTypes('filename', ['string']);
$resolver->setRequired(['file_path']);
$resolver->setAllowedTypes('file_path', ['string']);
}
}
8 changes: 4 additions & 4 deletions src/Task/File/InputFileReaderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function initialize(ProcessState $state): void
protected function getOptions(ProcessState $state): array
{
$options = parent::getOptions($state);
$filename = $state->getInput();
if (!\is_string($filename) || '' === $filename) {
$filePath = $state->getInput();
if (!\is_string($filePath) || '' === $filePath) {
throw new UnexpectedValueException('No file path given as input');
}
$options['filename'] = $filename;
$options['file_path'] = $filePath;

return $options;
}
Expand All @@ -49,6 +49,6 @@ protected function getOptions(ProcessState $state): array
protected function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->remove('filename');
$resolver->remove('file_path');
}
}
11 changes: 8 additions & 3 deletions src/Task/File/InputFolderBrowserTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ protected function configureOptions(OptionsResolver $resolver): void
$resolver->remove(['folder_path']);

$resolver->setDefaults([
'base_folder_path' => '',
'base_path' => '',
]);
$resolver->setAllowedTypes('base_folder_path', ['string']);
$resolver->setAllowedTypes('base_path', ['string']);
}

/**
Expand All @@ -71,7 +71,12 @@ protected function getOptions(ProcessState $state): array
{
$options = parent::getOptions($state);
if ($state->getInput()) {
$folderPath = $options['base_folder_path'].$state->getInput();
// As input_csv_reader: a non-empty base path is followed by a single separator
$basePath = (string) $options['base_path'];
if ('' !== $basePath) {
$basePath = rtrim($basePath, '/').'/';
}
$folderPath = $basePath.$state->getInput();
if ($this->folderPath && $folderPath !== $this->folderPath) {
throw new LogicException("Folder path '{$folderPath}' already initialized with a different value {$this->folderPath}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Task/File/InputLineReaderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getOptions(ProcessState $state): array
{
$options = parent::getOptions($state);
if (null !== $state->getInput()) {
$options['filename'] = $state->getInput();
$options['file_path'] = $state->getInput();
}

return $options;
Expand All @@ -39,6 +39,6 @@ protected function getOptions(ProcessState $state): array
protected function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->remove('filename');
$resolver->remove('file_path');
}
}
18 changes: 9 additions & 9 deletions src/Task/File/LineReaderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ class LineReaderTask extends AbstractConfigurableTask implements IterableTaskInt
public function execute(ProcessState $state): void
{
$options = $this->getOptions($state);
$filename = $options['filename'];
$filePath = $options['file_path'];

if ($this->file instanceof \SplFileObject
&& $this->file->getPathname() !== $filename) {
&& $this->file->getPathname() !== $filePath) {
$this->file = null;
}

if (!$this->file instanceof \SplFileObject) {
if (!file_exists($filename)) {
throw new UnexpectedValueException("File does not exist: '{$filename}'");
if (!file_exists($filePath)) {
throw new UnexpectedValueException("File does not exist: '{$filePath}'");
}

if (!is_readable($filename)) {
throw new UnexpectedValueException("File is not readable: '{$filename}'");
if (!is_readable($filePath)) {
throw new UnexpectedValueException("File is not readable: '{$filePath}'");
}

$this->file = new \SplFileObject($filename);
$this->file = new \SplFileObject($filePath);
$this->file->setFlags(\SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
$this->file->rewind();
}
Expand All @@ -73,7 +73,7 @@ public function next(ProcessState $state): bool

protected function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['filename']);
$resolver->setAllowedTypes('filename', ['string']);
$resolver->setRequired(['file_path']);
$resolver->setAllowedTypes('file_path', ['string']);
}
}
Loading