diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a4ad5e..3ed7e15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ### Changes +* [#55](https://github.com/cleverage/cache-process-bundle/issues/55) `CleverAgeCacheProcessExtension::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. * [#53](https://github.com/cleverage/cache-process-bundle/issues/53) AdapterRegistry: the adapters are loaded lazily from a service locator indexed by code: an adapter is only instantiated when a task uses it (an error in an adapter that a process does not use no longer makes it fail). The code is given by the new `code` attribute of the `cleverage.cache.adapter` tag, or by the new `#[AsCacheAdapter(code: '...')]` attribute (autoconfiguration); it must be the one returned by `getCode()`. Duplicate or empty codes fail the container compilation. An adapter tagged without `code` is still registered eagerly, with `AdapterRegistry::addAdapter()`, which is deprecated (the `code` will be required in 3.0). New optional `AdapterRegistry` constructor argument (the locator), new `hasAdapter()` and `getAdapters()` methods. Require `symfony/service-contracts`. Update documentation, add tests. * [#51](https://github.com/cleverage/cache-process-bundle/issues/51) Use the PHP 8.3 to 8.5 functions through the Symfony polyfills ([cleverage/process-bundle#299](https://github.com/cleverage/process-bundle/issues/299)): require `symfony/polyfill-php83`, `symfony/polyfill-php84` and `symfony/polyfill-php85`. Rector is configured with the minimum supported PHP version (`withPhpVersion(PhpVersion::PHP_82)`, it used PHP 8.5 features) and `withPhpSets()` without explicit version, which applies the rules using a newer function when its polyfill is required (no change on the current code). Document it in `CONTRIBUTING.md`. * [#49](https://github.com/cleverage/cache-process-bundle/issues/49) Add a `CleverAge\CacheProcessBundle\Registry\AdapterRegistry` alias of the `cleverage_cache_process.registry.adapter` service: the registry can be autowired, e.g. in a custom cache task extending `AbstractCacheTask`. Update documentation, add tests. diff --git a/composer.json b/composer.json index 94a69a1..e4ff89f 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,6 @@ "symfony/cache": "^6.4 || ^7.4 || ^8", "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/CleverAgeCacheProcessExtension.php b/src/DependencyInjection/CleverAgeCacheProcessExtension.php index ba53968..5a54f39 100644 --- a/src/DependencyInjection/CleverAgeCacheProcessExtension.php +++ b/src/DependencyInjection/CleverAgeCacheProcessExtension.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 CleverAgeCacheProcessExtension extends Extension { @@ -41,16 +40,11 @@ static function (ChildDefinition $definition, AsCacheAdapter $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/CleverAgeCacheProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeCacheProcessExtensionTest.php index 93b25e4..27c4678 100644 --- a/tests/DependencyInjection/CleverAgeCacheProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeCacheProcessExtensionTest.php @@ -29,12 +29,46 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\Yaml\Yaml; #[CoversClass(CleverAgeCacheProcessExtension::class)] #[UsesClass(AdapterRegistry::class)] #[CoversClass(AsCacheAdapter::class)] class CleverAgeCacheProcessExtensionTest extends TestCase { + public function testEveryServiceDefinitionFileIsLoaded(): void + { + $container = new ContainerBuilder(); + (new CleverAgeCacheProcessExtension())->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 testRegistryIsRegistered(): void { $container = new ContainerBuilder();