Skip to content

Commit f386664

Browse files
Merge pull request #58 from cleverage/55
#55 - Load the service definitions with a glob pattern instead of a Finder
2 parents 657f43d + fd52eaa commit f386664

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Latest
22
------
33

44
### Changes
5+
* [#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.
56
* [#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.
67
* [#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`.
78
* [#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.

‎composer.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"symfony/cache": "^6.4 || ^7.4 || ^8",
3838
"symfony/config": "^6.4 || ^7.4 || ^8",
3939
"symfony/dependency-injection": "^6.4 || ^7.4 || ^8",
40-
"symfony/finder": "^6.4 || ^7.4 || ^8",
4140
"symfony/http-kernel": "^6.4 || ^7.4 || ^8",
4241
"symfony/options-resolver": "^6.4 || ^7.4 || ^8",
4342
"symfony/polyfill-php83": "^1.33",

‎src/DependencyInjection/CleverAgeCacheProcessExtension.php‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Extension\Extension;
2121
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
22-
use Symfony\Component\Finder\Finder;
2322

2423
/**
2524
* This is the class that loads and manages your bundle configuration.
2625
*
27-
* @see http://symfony.com/doc/current/cookbook/bundles/extension.html
26+
* @see https://symfony.com/doc/current/bundles/extension.html
2827
*/
2928
class CleverAgeCacheProcessExtension extends Extension
3029
{
@@ -41,16 +40,11 @@ static function (ChildDefinition $definition, AsCacheAdapter $attribute): void {
4140
}
4241

4342
/**
44-
* Recursively import config files into container.
43+
* Import the service definition files of a directory into the container.
4544
*/
4645
protected function findServices(ContainerBuilder $container, string $path, string $extension = 'yaml'): void
4746
{
48-
$finder = new Finder();
49-
$finder->in($path)
50-
->name('*.'.$extension)->files();
5147
$loader = new YamlFileLoader($container, new FileLocator($path));
52-
foreach ($finder as $file) {
53-
$loader->load($file->getFilename());
54-
}
48+
$loader->import('*.'.$extension, 'glob');
5549
}
5650
}

‎tests/DependencyInjection/CleverAgeCacheProcessExtensionTest.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,46 @@
2929
use Symfony\Component\DependencyInjection\ContainerBuilder;
3030
use Symfony\Component\DependencyInjection\Definition;
3131
use Symfony\Component\DependencyInjection\Reference;
32+
use Symfony\Component\Yaml\Yaml;
3233

3334
#[CoversClass(CleverAgeCacheProcessExtension::class)]
3435
#[UsesClass(AdapterRegistry::class)]
3536
#[CoversClass(AsCacheAdapter::class)]
3637
class CleverAgeCacheProcessExtensionTest extends TestCase
3738
{
39+
public function testEveryServiceDefinitionFileIsLoaded(): void
40+
{
41+
$container = new ContainerBuilder();
42+
(new CleverAgeCacheProcessExtension())->load([], $container);
43+
44+
$files = glob(\dirname(__DIR__, 2).'/config/services/*.yaml');
45+
self::assertIsArray($files);
46+
self::assertNotEmpty($files);
47+
foreach ($files as $file) {
48+
$config = Yaml::parseFile($file, Yaml::PARSE_CUSTOM_TAGS);
49+
self::assertIsArray($config);
50+
if (!isset($config['services'])) {
51+
continue;
52+
}
53+
self::assertIsArray($config['services']);
54+
foreach (array_keys($config['services']) as $id) {
55+
if ('_defaults' === $id) {
56+
continue;
57+
}
58+
if (str_ends_with((string) $id, '\\')) {
59+
// Resource: at least one service registered under the namespace prefix
60+
$registered = array_filter(
61+
array_keys($container->getDefinitions()),
62+
static fn (string $definitionId): bool => str_starts_with($definitionId, (string) $id)
63+
);
64+
self::assertNotEmpty($registered, \sprintf('No service registered for the "%s" resource of %s', $id, basename($file)));
65+
continue;
66+
}
67+
self::assertTrue($container->has((string) $id), \sprintf('Service "%s" of %s is not registered', $id, basename($file)));
68+
}
69+
}
70+
}
71+
3872
public function testRegistryIsRegistered(): void
3973
{
4074
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)