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 @@ -13,6 +13,7 @@ Latest
* [#292](https://github.com/cleverage/process-bundle/issues/292) Reject the process configuration errors deprecated during v5: the `errors` task configuration key is removed (use `error_outputs`), with `TaskConfiguration::getErrors()` and `$logErrors`; an unknown `error_strategy` (#310) and an unknown task reference (#426) fail the container compilation; a task listed several times in the `outputs` / `error_outputs` of a task throws an `InvalidProcessConfigurationException` (#414); a shared service used by several tasks of a process fails the container compilation (#382). The former names of the codes with a dash, with underscores, are no longer found (#412, #475): processes, tasks, generic transformers, transformer codes and contextual options of the generic transformers; `DeprecatedCodeAliases` and the second argument of the `TransformerRegistry` constructor are removed (see `UPGRADE.md`). Update documentation and tests.
* [#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.

## 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
72 changes: 57 additions & 15 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ Flex recipe (`config/packages/clever_age_process.yaml`) is free, you can rename

### Typed class constants

The class constants of the bundle are typed. A class extending a class of the bundle and redeclaring one of its
protected constants must declare it with the same type:

- `string`: `ProcessHelpCommand::CHAR_*` (`protected const string CHAR_NODE = '●';`);
- `int`: `ProcessHelpCommand::BRANCH_SIZE` / `INDENT_SIZE`, `ProcessManager::EXECUTE_*`,
`ProcessLauncherTask::STOP_TIMEOUT` (`protected const int INDENT_SIZE = 2;`);
- `array`: `ArrayMergeTask::MERGE_FUNC`.
The class constants of the bundle are typed. A class extending `ProcessHelpCommand` (internal) and redeclaring one of
its protected constants must declare it with the same type: `ProcessHelpCommand::CHAR_*` are `string`
(`protected const string CHAR_NODE = '●';`), `ProcessHelpCommand::BRANCH_SIZE` / `INDENT_SIZE` are `int`. The other
classes declaring typed constants are `final` (see [Final classes](#final-classes)).

### Narrowed native types

Native types that were never `null` in practice no longer accept it. A class extending a class of the bundle and
overriding one of these members must declare the narrowed type (a nullable type is a fatal error):

- `AbstractConfigurableTask::getOptions()` and `ProcessState::getContextualizedOptions()` return `array` (instead of
`?array`): `protected function getOptions(ProcessState $state): array`;
- `CsvResource::$lineNumber` is an `int` (instead of `?int`), `ProcessHistory::$startDate` a `\DateTimeInterface`
(instead of `?\DateTimeInterface`).
- `AbstractConfigurableTask::getOptions()` returns `array` (instead of `?array`):
`protected function getOptions(ProcessState $state): array`;
- `CsvResource::$lineNumber` is an `int` (instead of `?int`).

`ProcessState::getContextualizedOptions()` returns `array` and `ProcessHistory::$startDate` is a `\DateTimeInterface`
(both classes are `final`): remove a `?? []` or a `null` check on them, now useless.

### `array_first` transformer

Expand Down Expand Up @@ -97,10 +96,9 @@ The code of a transformer is only given by the `code` attribute of its `cleverag
- `TransformerRegistryInterface` declares `getTransformerCodes()` (the codes, without instantiating the transformers):
implement it in your own implementations;
- `RegistryCompilerPass` is removed (deprecated since 5.4), it was no longer used by the bundle;
- a class extending `TransformerRegistry` (`@final` since 5.4) must declare the `$locator` property as non-nullable
(`protected ServiceProviderInterface $locator`), and the transformers it adds to `$transformers` itself are no longer
given by `hasTransformer()`, `getTransformer()` and `getTransformers()`, which only read the locator: register them in
the locator.
- `TransformerRegistry` only reads its locator: a transformer must be registered in the locator (a tagged service) to be
given by `hasTransformer()`, `getTransformer()` and `getTransformers()`; the class is `final` (see
[Final classes](#final-classes)).

### Tasks and service container

Expand Down Expand Up @@ -197,6 +195,50 @@ The former names of the codes with a dash, with underscores instead of dashes, a
- a negative `flush_every` option of the `counter` task is rejected with an `InvalidOptionsException` (it worked as
its absolute value, deprecated since 5.10): use a positive integer.

### Final classes

The classes marked `@final since 5.4` are `final`: the engine (`ProcessManager`, `ProcessConfigurationRegistry`,
`TransformerRegistry`, `ContextualOptionResolver`), the models (`ProcessState`, `ProcessHistory`, the configurations,
the events), `SubprocessInstance`, the files of `Filesystem` (`SplFile`, `CsvFile`, `JsonStreamFile`, `XmlFile`),
`ConstraintLoader`, `CleverAgeProcessBundle` and the concrete tasks and transformers. A class extending one of them
fails with `Class ... cannot extend final class ...`, and PHPUnit can no longer create a mock or a stub of them:

- write your own task (extending `AbstractConfigurableTask`) or transformer, and inject the services of the bundle it
needs, or decorate a service of the bundle;
- type your services and your test doubles on the interfaces (`ProcessManagerInterface`,
`ProcessConfigurationRegistryInterface`, `TransformerRegistryInterface`, `TaskRegistryInterface`); the services of
the bundle are typed on them, so a decorator implementing the interface is injected everywhere;
- build a real `ProcessState` in your tests instead of a double:
`new ProcessState($processConfiguration, new ProcessHistory($processConfiguration))`;
- autowire the services by their interface, not by their class: the aliases on the classes (`ProcessManager`,
`ProcessConfigurationRegistry`, `TransformerRegistry`, `TaskRegistry`) still exist, but once the service is decorated
they give the decorator, which fails a parameter typed on the class with a `TypeError`;
- `ContextualOptionResolver` has no interface: it cannot be decorated (the process manager, `ProcessState` and the
`generic` transformers are typed on it).

`ProcessManagerInterface` declares `getProcessHistory()` and `getTaskConfiguration()` (read by the Monolog processors),
and `ProcessConfigurationRegistryInterface` declares `getProcessCodes()` (the codes, without resolving the
configurations). Both interfaces extend `Symfony\Contracts\Service\ResetInterface`: the `kernel.reset` tag of the
service moves to its decorator, so `reset()` is called on the decorator (e.g. between two messages of a worker).
Implement these methods in your own implementations; a decorator delegates them to the decorated service, `reset()`
included, otherwise the locks and the states of the processes are kept from one message to the next:

```php
public function reset(): void
{
$this->inner->reset();
}
```

Other signatures:

- `PregFilterTransformer::transform()` returns `?string` (instead of `array|string|null`, the subject is always a
string);
- the `$transformerRegistry` property of `TransformerTrait` is a `?TransformerRegistryInterface` (instead of
`?TransformerRegistry`): a class using the trait and redeclaring the property must use the new type;
- `SplFile::readLine()` no longer has the unused `$length` parameter: remove the argument (a positional one is
ignored, a named one fails with `Unknown named parameter $length`).

## v5.10

### Stop strategy and error branch ending on a stop
Expand Down
2 changes: 1 addition & 1 deletion docs/01-quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Example:

### Contextual values

Values passed with `--context` (or with the `$context` argument of `ProcessManager::execute()`, see
Values passed with `--context` (or with the `$context` argument of `ProcessManagerInterface::execute()`, see
[executing a process from PHP](04-advanced_workflow.md#executing-a-process-from-php)) are available in every
task of the process:
- in the task options, a string `{{ key }}` is replaced by the value of the `key` context entry. If the whole option
Expand Down
15 changes: 8 additions & 7 deletions docs/03-custom_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,14 @@ services:
- { name: cleverage.transformer, code: app_vat }
```

Once properly set up, they are registered in the `CleverAge\ProcessBundle\Registry\TransformerRegistry` (used by the
`TransformerTask` and every transformer using a sub-list of transformers) under their code, in a service locator: a
transformer is only instantiated when a process uses it. Two transformers cannot share the same code, and a transformer
tagged without `code` (e.g. autoconfigured without the attribute) cannot be registered: in both cases, the container
compilation fails. A service tagged with several codes is registered under each of them.

`TransformerRegistry::getTransformerCodes()` gives the registered codes without instantiating the transformers.
Once properly set up, they are registered in the transformer registry
(`CleverAge\ProcessBundle\Registry\TransformerRegistryInterface`, used by the `TransformerTask` and every transformer
using a sub-list of transformers) under their code, in a service locator: a transformer is only instantiated when a
process uses it. Two transformers cannot share the same code, and a transformer tagged without `code` (e.g.
autoconfigured without the attribute) cannot be registered: in both cases, the container compilation fails. A service
tagged with several codes is registered under each of them.

`TransformerRegistryInterface::getTransformerCodes()` gives the registered codes without instantiating the transformers.

When creating a new transformer for your project, use an internal prefix in your codes to avoid conflicts with potential
standard additions.
Expand Down
14 changes: 9 additions & 5 deletions docs/04-advanced_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Advanced Workflow
## Process execution flow

When a process is executed (with the `cleverage:process:execute` command or with
`CleverAge\ProcessBundle\Manager\ProcessManager::execute($processCode, $input, $context)`), the process manager:
`CleverAge\ProcessBundle\Manager\ProcessManagerInterface::execute($processCode, $input, $context)`), the process
manager:

1. dispatches the `cleverage_process.start` event
2. checks the process: circular dependencies are forbidden, and the `entry_point` / `end_point` tasks must be part of
Expand Down Expand Up @@ -42,10 +43,13 @@ own tasks and transformers. The reference pages name these exceptions without th
### Executing a process from PHP

The process manager service (`cleverage_process.manager.process`, private) can be autowired by its interface,
`CleverAge\ProcessBundle\Manager\ProcessManagerInterface` (or by its class, `ProcessManager`), or injected
explicitly. Type your services on the interface: the class will be `final` in v6.0 (the services of the bundle will
then be typed on the interfaces, so that they can be decorated). The registries have their interface too: `ProcessConfigurationRegistryInterface`,
`TransformerRegistryInterface` and `TaskRegistryInterface` (namespace `CleverAge\ProcessBundle\Registry`).
`CleverAge\ProcessBundle\Manager\ProcessManagerInterface`, or injected explicitly. Type your services on the interface:
the class is `final`, and the services of the bundle are typed on the interfaces, so that they can be decorated (the
alias on the class `ProcessManager` gives the decorator too, which fails a parameter typed on the class). A decorator of
the process manager or of the process configuration registry receives their `kernel.reset` tag: its `reset()` method
(required by the interfaces) must call the one of the decorated service. The registries have their interface too:
`ProcessConfigurationRegistryInterface`, `TransformerRegistryInterface` and `TaskRegistryInterface` (namespace
`CleverAge\ProcessBundle\Registry`).

```yaml
# config/services.yaml
Expand Down
11 changes: 5 additions & 6 deletions docs/05-good_practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ The classes meant to be extended are the abstract ones (`AbstractConfigurableTas
a base by other tasks (`FileReaderTask`, `LineReaderTask`, `FolderBrowserTask`, `CsvReaderTask`, `InputCsvReaderTask`
and `Filesystem\CsvResource`).

The other classes are marked `@final since 5.4`, they will be `final` in v6.0: the engine (`ProcessManager`, the
registries, `ContextualOptionResolver`), the models (`ProcessState`, the configurations, the events) and the concrete
tasks and transformers. Extending one of them triggers a deprecation (with the Symfony `DebugClassLoader`, enabled by
`symfony/error-handler` in debug mode). Instead:
The other classes are `final`: the engine (`ProcessManager`, the registries, `ContextualOptionResolver`), the models
(`ProcessState`, the configurations, the events) and the concrete tasks and transformers. Instead of extending them:

- write your own task (extending `AbstractConfigurableTask`) or transformer, and inject the services of the bundle you
need;
- [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) a service, or listen to the
process [events](04-advanced_workflow.md);
- [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) a service having an
interface (`ProcessManagerInterface`, the registries; not `ContextualOptionResolver`), or listen to the process
[events](04-advanced_workflow.md);
- chain existing tasks and transformers in the process configuration.

The classes marked `@internal` (the dependency injection compiler passes, the commands, the event listeners, the Monolog
Expand Down
7 changes: 4 additions & 3 deletions docs/06-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ For iterable tasks, call `execute()` then `next()` in a loop; for blocking tasks
## Functional testing of processes

The best way to test a whole workflow is to execute the process, like the console command does, with the process
manager. Its service id is `cleverage_process.manager.process` (class `CleverAge\ProcessBundle\Manager\ProcessManager`);
manager. Its service id is `cleverage_process.manager.process` (interface
`CleverAge\ProcessBundle\Manager\ProcessManagerInterface`);
it is a private service, available through the test container of a `KernelTestCase`:

```php
Expand Down Expand Up @@ -143,7 +144,7 @@ cleverage_process:
```php
namespace App\Tests\Process;

use CleverAge\ProcessBundle\Manager\ProcessManager;
use CleverAge\ProcessBundle\Manager\ProcessManagerInterface;
use PHPUnit\Framework\Attributes\CoversNothing;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

Expand All @@ -153,7 +154,7 @@ class VatProcessTest extends KernelTestCase
public function testProcess(): void
{
self::bootKernel();
/** @var ProcessManager $processManager */
/** @var ProcessManagerInterface $processManager */
$processManager = self::getContainer()->get('cleverage_process.manager.process');

$result = $processManager->execute('test.app.vat', 100, ['rate' => 0.055]);
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/01-process_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ them: the former name is no longer found since v6.0.
empty.

**entry_point**: optional task code (default is none) that will receive the process input (`--input` option of the
execute command, or `$input` argument of `ProcessManager::execute()`). The referenced task cannot have ancestors, and
must be in the [main branch](#main-branch) of the process.
execute command, or `$input` argument of `ProcessManagerInterface::execute()`). The referenced task cannot have
ancestors, and must be in the [main branch](#main-branch) of the process.

**end_point**: optional task code (default is none) whose last output will be returned as the process output. It must
be in the main branch of the process. An ignored output (the task is skipped, filters its input or fails with the
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/tasks/iterable_batch_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ IterableBatchTask

Buffers inputs and, every `batch_count` inputs, iterates over the buffer to output its elements one by one. Remaining
elements are output (one by one as well) when the task is flushed, at the end of the upstream iteration. It is mainly
an example task: it is not really useful as is, but its `processInput()` method can be overridden to customize how
each input is transformed before being buffered.
an example task, not really useful as is. The class is `final`: to transform each input before it is buffered, put a
`transformer` task before it, or write your own task (extending `AbstractConfigurableTask`).

Task reference
--------------
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/traits/transformer_trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ transformers:

## Usage

* Set the `$transformerRegistry` property with the `TransformerRegistry` service (e.g. in the constructor)
* Set the `$transformerRegistry` property with the transformer registry (`TransformerRegistryInterface`, e.g. in the
constructor)
* Call `TransformerTrait::configureTransformersOptions` with your own `OptionsResolver`. You can change `$optionName`
if you want a custom option name
* Call `TransformerTrait::applyTransformers` with the resolved transformer option (i.e. `$options['transformers']`)
Expand Down
Loading