diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3b8b5..c8ba386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ## Changes +* [#190](https://github.com/cleverage/ui-process-bundle/issues/190) Add aliases named after their class to `ProcessExecutionManager`, `ProcessConfigurationsManager`, `ProcessExecutionRepository` and `ProcessScheduleRepository` (as the Monolog handlers): they can be autowired. Update documentation, add tests. * [#192](https://github.com/cleverage/ui-process-bundle/issues/192) The controllers and the HTTP value resolver are defined explicitly, without autowiring nor autoconfiguration (Symfony best practices for bundles, as [cleverage/process-bundle#149](https://github.com/cleverage/process-bundle/issues/149)): same arguments, tags and calls. The `$context` binding of the controllers no longer registers the `AdminContextFactory` service for the `AdminContext $context` arguments of the EasyAdmin actions (never used: EasyAdmin resolves the context first). Add tests. * [#187](https://github.com/cleverage/ui-process-bundle/issues/187) Composer: require PHP `^8.2` instead of `>=8.2` (PHP 9 is no longer accepted before being tested), remove the authorization of the `symfony/flex` plugin, which is not required (the CI installs it globally), as [cleverage/process-bundle#319](https://github.com/cleverage/process-bundle/issues/319). * [#181](https://github.com/cleverage/ui-process-bundle/issues/181) Fix the deprecations revealed by the tests, which now fail on deprecations: `ProcessExecutionRepository::getLastProcessExecution()` passes the `\SortDirection` enum to `orderBy()` when doctrine/orm accepts it (3.7 or later, where a string direction is deprecated, [#152](https://github.com/cleverage/ui-process-bundle/issues/152)); `ProcessExecutionRepository::hasLogs()` counts the log records without an arbitrary join (`WITH` deprecated by doctrine/orm 3.7, same result); the date filters of the log records (`createdAt`) and of the process executions (`startDate`) use the `single_text` widget (not configuring it is deprecated by Symfony 6.4, already the default since Symfony 7.0); `User::eraseCredentials()` is marked `#[\Deprecated]`, as required by Symfony 7.3 (with Symfony 6.4 and PHP 8.4 or later, which still call it, set `security.erase_credentials: false` to avoid the deprecation). diff --git a/config/services/manager.yaml b/config/services/manager.yaml index 7764241..555f736 100644 --- a/config/services/manager.yaml +++ b/config/services/manager.yaml @@ -6,12 +6,16 @@ services: - '@cleverage_ui_process.repository.process_execution' tags: - { name: kernel.reset, method: reset } + CleverAge\UiProcessBundle\Manager\ProcessExecutionManager: + alias: cleverage_ui_process.manager.process_execution cleverage_ui_process.manager.process_configuration: class: CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager public: false arguments: - '@cleverage_process.registry.process_configuration' + CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager: + alias: cleverage_ui_process.manager.process_configuration cleverage_ui_process.stop_checker.process_execution: class: CleverAge\UiProcessBundle\StopChecker\ProcessExecutionStopChecker diff --git a/config/services/repository.yaml b/config/services/repository.yaml index f3d9c37..1c2eedf 100644 --- a/config/services/repository.yaml +++ b/config/services/repository.yaml @@ -5,9 +5,13 @@ services: arguments: - '@doctrine.orm.entity_manager' - '@doctrine' + CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository: + alias: cleverage_ui_process.repository.process_execution cleverage_ui_process.repository.process_schedule: class: CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository public: false arguments: - '@doctrine.orm.entity_manager' + CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository: + alias: cleverage_ui_process.repository.process_schedule diff --git a/docs/reference/04-process_executions_and_logs.md b/docs/reference/04-process_executions_and_logs.md index 6ff4eec..bc0c25d 100644 --- a/docs/reference/04-process_executions_and_logs.md +++ b/docs/reference/04-process_executions_and_logs.md @@ -107,6 +107,34 @@ When a log record has a level greater than or equal to `report_increment_level` execution report, e.g. `{"Warning": 12, "Error": 1}`. This gives an overview of the problems of an execution without opening its logs. +### In your code + +The services of the bundle can be autowired by their class name: + +| Class | Service | Usage | +|-------------------------------------------------------------------|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `CleverAge\UiProcessBundle\Manager\ProcessExecutionManager` | `cleverage_ui_process.manager.process_execution` | Execution of the running process: `getCurrentProcessExecution()`, `increment('')` / `setReport('', '')` to add your own entries to its report. | +| `CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository` | `cleverage_ui_process.repository.process_execution` | `getLastProcessExecution('')`: last execution of a process. | +| `CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository` | `cleverage_ui_process.repository.process_schedule` | `findEnabled()`: enabled [schedules](05-scheduler.md). | +| `CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager` | `cleverage_ui_process.manager.process_configuration` | `getPublicProcesses()`, `getPrivateProcesses()` and the resolved [UI options](02-process_ui_options.md) of a process (`getUiOptions('')`). | + +```php +use CleverAge\UiProcessBundle\Manager\ProcessExecutionManager; + +final class MyService +{ + public function __construct(private readonly ProcessExecutionManager $processExecutionManager) + { + } + + public function doSomething(): void + { + // Counted in the report of the running execution (nothing happens outside of a process) + $this->processExecutionManager->increment('imported'); + } +} +``` + Logs ---- diff --git a/tests/DependencyInjection/CleverAgeUiProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeUiProcessExtensionTest.php index 51416a5..e5f2e83 100644 --- a/tests/DependencyInjection/CleverAgeUiProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeUiProcessExtensionTest.php @@ -19,8 +19,14 @@ use CleverAge\UiProcessBundle\DependencyInjection\CleverAgeUiProcessExtension; use CleverAge\UiProcessBundle\DependencyInjection\Configuration; use CleverAge\UiProcessBundle\Entity\User; +use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager; +use CleverAge\UiProcessBundle\Manager\ProcessExecutionManager; use CleverAge\UiProcessBundle\Message\ProcessExecuteMessage; +use CleverAge\UiProcessBundle\Monolog\Handler\DoctrineProcessHandler; +use CleverAge\UiProcessBundle\Monolog\Handler\ProcessHandler; use CleverAge\UiProcessBundle\Notifier\NotificationTrigger; +use CleverAge\UiProcessBundle\Repository\ProcessExecutionRepository; +use CleverAge\UiProcessBundle\Repository\ProcessScheduleRepository; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\UsesClass; @@ -159,6 +165,35 @@ public function testLoadWithDefaultConfiguration(): void ); } + /** + * @return iterable + */ + public static function provideAutowiringAliases(): iterable + { + yield 'process execution manager' => [ProcessExecutionManager::class, 'cleverage_ui_process.manager.process_execution']; + yield 'process configurations manager' => [ProcessConfigurationsManager::class, 'cleverage_ui_process.manager.process_configuration']; + yield 'process execution repository' => [ProcessExecutionRepository::class, 'cleverage_ui_process.repository.process_execution']; + yield 'process schedule repository' => [ProcessScheduleRepository::class, 'cleverage_ui_process.repository.process_schedule']; + yield 'process handler' => [ProcessHandler::class, 'cleverage_ui_process.monolog_handler.process']; + yield 'doctrine process handler' => [DoctrineProcessHandler::class, 'cleverage_ui_process.monolog_handler.doctrine_process']; + } + + /** + * @param class-string $class + */ + #[DataProvider('provideAutowiringAliases')] + public function testServiceCanBeAutowired(string $class, string $id): void + { + $container = $this->createContainer('prod'); + (new CleverAgeUiProcessExtension())->load([], $container); + + // Private alias named after the class of the service + $alias = $container->getAlias($class); + self::assertSame($id, (string) $alias); + self::assertFalse($alias->isPublic()); + self::assertSame($class, $container->getDefinition($id)->getClass()); + } + /** * @return iterable */