From 9addeb3ba4a72e1b293709f652472014a9fbb48b Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Mon, 19 Oct 2026 11:48:35 +0200 Subject: [PATCH] #54 - Load the service definitions with a glob pattern instead of a Finder - CleverAgeSoapProcessExtension::findServices() imports the service definition files with a glob pattern ($loader->import('*.yaml', 'glob')) instead of a Finder and one load() call per file, as cleverage/process-bundle#271. Same signature, same files. - symfony/finder is no longer required (only used there). - Docblock link to the Symfony 2 cookbook updated. - Test that every service of config/services/*.yaml is registered. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + composer.json | 1 - .../CleverAgeSoapProcessExtension.php | 12 ++----- .../CleverAgeSoapProcessExtensionTest.php | 34 +++++++++++++++++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1553437..5bd3c25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ### Changes +* [#54](https://github.com/cleverage/soap-process-bundle/issues/54) `CleverAgeSoapProcessExtension::findServices()` loads the service definition files with a glob pattern instead of a `Finder` (same files, as [cleverage/process-bundle#271](https://github.com/cleverage/process-bundle/issues/271)), `symfony/finder` is no longer required. Add tests. * [#52](https://github.com/cleverage/soap-process-bundle/issues/52) ClientRegistry: the clients are loaded lazily from a service locator indexed by code: a client is only instantiated when a task or the transformer uses it (an error in a client that a process does not use no longer makes it fail). The code is given by the new `code` attribute of the `cleverage.soap.client` tag, or by the new `#[AsSoapClient(code: '...')]` attribute (autoconfiguration); it must be the one returned by `getCode()`. Duplicate or empty codes fail the container compilation. A client tagged without `code` is still registered eagerly, with `ClientRegistry::addClient()`, which is deprecated (the `code` will be required in 4.0). New optional `ClientRegistry` constructor argument (the locator); `ClientRegistry` is autowirable by its class name. Require `symfony/service-contracts`. Update documentation, add tests. * [#50](https://github.com/cleverage/soap-process-bundle/issues/50) Require `symfony/polyfill-php83`, `symfony/polyfill-php84` and `symfony/polyfill-php85` ([cleverage/process-bundle#299](https://github.com/cleverage/process-bundle/issues/299)), so the functions of PHP 8.3 to 8.5 can be used while supporting PHP 8.2. Configure Rector for PHP 8.2 with its polyfills set (it was configured for PHP 8.5, and could introduce PHP 8.3+ functions without polyfill). No code change: no Rector rule applies and no manual replacement keeps an identical behaviour. Document it in `CONTRIBUTING.md`. * [#46](https://github.com/cleverage/soap-process-bundle/issues/46) Give a code to the task ([cleverage/process-bundle#91](https://github.com/cleverage/process-bundle/issues/91)): `soap_request` (`task: soap_request`, with `cleverage/process-bundle` 5.4 or later, referencing it by `service` being deprecated there). The task has its class name as service id; fetching it directly from the service container is deprecated (`container.private`), it will be private in 4.0. The former id `cleverage_soap_process.task.request` is a deprecated alias, removed in 4.0. Update documentation, add tests. diff --git a/composer.json b/composer.json index 0e7bf36..307acaf 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,6 @@ "psr/log": "^2|^3", "symfony/config": "^6.4|^7.4|^8", "symfony/dependency-injection": "^6.4|^7.4|^8", - "symfony/finder": "^6.4|^7.4|^8", "symfony/http-kernel": "^6.4|^7.4|^8", "symfony/options-resolver": "^6.4|^7.4|^8", "symfony/polyfill-php83": "^1.33", diff --git a/src/DependencyInjection/CleverAgeSoapProcessExtension.php b/src/DependencyInjection/CleverAgeSoapProcessExtension.php index bc92895..eb3802a 100644 --- a/src/DependencyInjection/CleverAgeSoapProcessExtension.php +++ b/src/DependencyInjection/CleverAgeSoapProcessExtension.php @@ -19,12 +19,11 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Finder\Finder; /** * This is the class that loads and manages your bundle configuration. * - * @see http://symfony.com/doc/current/cookbook/bundles/extension.html + * @see https://symfony.com/doc/current/bundles/extension.html */ class CleverAgeSoapProcessExtension extends Extension { @@ -41,16 +40,11 @@ static function (ChildDefinition $definition, AsSoapClient $attribute): void { } /** - * Recursively import config files into container. + * Import the service definition files of a directory into the container. */ protected function findServices(ContainerBuilder $container, string $path, string $extension = 'yaml'): void { - $finder = new Finder(); - $finder->in($path) - ->name('*.'.$extension)->files(); $loader = new YamlFileLoader($container, new FileLocator($path)); - foreach ($finder as $file) { - $loader->load($file->getFilename()); - } + $loader->import('*.'.$extension, 'glob'); } } diff --git a/tests/DependencyInjection/CleverAgeSoapProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeSoapProcessExtensionTest.php index d11506f..df8d6f0 100644 --- a/tests/DependencyInjection/CleverAgeSoapProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeSoapProcessExtensionTest.php @@ -28,6 +28,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\Yaml\Yaml; #[CoversClass(CleverAgeSoapProcessExtension::class)] #[UsesClass(RequestTransformer::class)] @@ -35,6 +36,39 @@ #[UsesClass(ClientRegistry::class)] class CleverAgeSoapProcessExtensionTest extends TestCase { + public function testEveryServiceDefinitionFileIsLoaded(): void + { + $container = new ContainerBuilder(); + (new CleverAgeSoapProcessExtension())->load([], $container); + + $files = glob(\dirname(__DIR__, 2).'/config/services/*.yaml'); + self::assertIsArray($files); + self::assertNotEmpty($files); + foreach ($files as $file) { + $config = Yaml::parseFile($file, Yaml::PARSE_CUSTOM_TAGS); + self::assertIsArray($config); + if (!isset($config['services'])) { + continue; + } + self::assertIsArray($config['services']); + foreach (array_keys($config['services']) as $id) { + if ('_defaults' === $id) { + continue; + } + if (str_ends_with((string) $id, '\\')) { + // Resource: at least one service registered under the namespace prefix + $registered = array_filter( + array_keys($container->getDefinitions()), + static fn (string $definitionId): bool => str_starts_with($definitionId, (string) $id) + ); + self::assertNotEmpty($registered, \sprintf('No service registered for the "%s" resource of %s', $id, basename($file))); + continue; + } + self::assertTrue($container->has((string) $id), \sprintf('Service "%s" of %s is not registered', $id, basename($file))); + } + } + } + public function testServices(): void { $container = new ContainerBuilder();