diff --git a/CHANGELOG.md b/CHANGELOG.md index 550fb1c..9696c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Latest ------ ### Changes +* [#57](https://github.com/cleverage/flysystem-process-bundle/issues/57) `CleverAgeFlysystemProcessExtension::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. * [#55](https://github.com/cleverage/flysystem-process-bundle/issues/55) 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`. Configure Rector for the minimum PHP version (`withPhpVersion(PHP_82)` instead of `PHP_85`, `withPhpSets()` read from `composer.json` instead of the `php81` leftover, which also enables the polyfill rules; `UP_TO_PHP_82` set removed): no change proposed on the current code. Document the PHP version policy in CONTRIBUTING. * [#51](https://github.com/cleverage/flysystem-process-bundle/issues/51) Give a code to the tasks ([cleverage/process-bundle#91](https://github.com/cleverage/process-bundle/issues/91)): `flysystem_file_fetch`, `flysystem_list_content` and `flysystem_remove_file` (`task: flysystem_file_fetch`, with `cleverage/process-bundle` 5.4 or later, referencing them by `service` being deprecated there). The tasks have their class name as service id; fetching them directly from the service container is deprecated (`container.private`), they will be private in 4.0. The former ids `cleverage_flysystem_process.task.file_fetch` / `cleverage_flysystem_process.task.list_content` / `cleverage_flysystem_process.task.remove_file` are deprecated aliases, removed in 4.0. Update documentation, add tests. * [#49](https://github.com/cleverage/flysystem-process-bundle/issues/49) CI: test the lowest versions allowed by `composer.json` (`--prefer-lowest`, PHP 8.2). Require `psr/log` `^2|^3`: `cleverage/process-bundle` 5.x uses the typed `LoggerInterface` signatures (fatal error with `psr/log` 1). diff --git a/composer.json b/composer.json index 5975749..26e7161 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,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/CleverAgeFlysystemProcessExtension.php b/src/DependencyInjection/CleverAgeFlysystemProcessExtension.php index 3802c8c..7667390 100644 --- a/src/DependencyInjection/CleverAgeFlysystemProcessExtension.php +++ b/src/DependencyInjection/CleverAgeFlysystemProcessExtension.php @@ -17,12 +17,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 CleverAgeFlysystemProcessExtension extends Extension { @@ -32,16 +31,11 @@ public function load(array $configs, ContainerBuilder $container): 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/CleverAgeFlysystemProcessExtensionTest.php b/tests/DependencyInjection/CleverAgeFlysystemProcessExtensionTest.php index cea6766..ed374cb 100644 --- a/tests/DependencyInjection/CleverAgeFlysystemProcessExtensionTest.php +++ b/tests/DependencyInjection/CleverAgeFlysystemProcessExtensionTest.php @@ -23,10 +23,44 @@ use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Yaml\Yaml; #[CoversClass(CleverAgeFlysystemProcessExtension::class)] class CleverAgeFlysystemProcessExtensionTest extends TestCase { + public function testEveryServiceDefinitionFileIsLoaded(): void + { + $container = new ContainerBuilder(); + (new CleverAgeFlysystemProcessExtension())->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))); + } + } + } + /** * @return iterable */