Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Latest
------

### Changes
* [#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.
* [#43](https://github.com/cleverage/cache-process-bundle/issues/43) Give a code to the tasks ([cleverage/process-bundle#91](https://github.com/cleverage/process-bundle/issues/91)): `cache_get` and `cache_set` (`task: cache_get`, 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 3.0. The former ids `cleverage_cache_process.task.get` / `cleverage_cache_process.task.set` are deprecated aliases, removed in 3.0. Update documentation, add tests.
* [#41](https://github.com/cleverage/cache-process-bundle/issues/41) CI: test the lowest versions allowed by `composer.json` (`--prefer-lowest`, PHP 8.2).
* [#39](https://github.com/cleverage/cache-process-bundle/issues/39) Add a `.gitattributes`: the development files (`.docker/`, `.github/`, `tests/`, quality tools and PHPUnit configurations, `Makefile`) are no longer part of the archive installed by Composer (`dist`).
Expand Down
4 changes: 4 additions & 0 deletions config/services/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ services:
cleverage_cache_process.registry.adapter:
class: CleverAge\CacheProcessBundle\Registry\AdapterRegistry
public: false

CleverAge\CacheProcessBundle\Registry\AdapterRegistry:
alias: cleverage_cache_process.registry.adapter
public: false
6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ class DeleteTask extends AbstractCacheTask

Its code is given by the `#[AsTask]` attribute (`cleverage/process-bundle` 5.4 or later), prefixed to avoid conflicts
with the codes of the bundles. With autoconfiguration, the task is also non-shared and logs in the
`cleverage_process_task` channel:
`cleverage_process_task` channel. The registry is autowired by its class (since 2.3; before, pass
`'@cleverage_cache_process.registry.adapter'` as argument), so the default `App\:` resource of a Symfony application is
enough, or explicitly:

```yaml
# config/services.yaml
services:
App\Task\DeleteTask:
autowire: true
autoconfigure: true
arguments: ['@cleverage_cache_process.registry.adapter']
```

```yaml
Expand Down
27 changes: 27 additions & 0 deletions tests/DependencyInjection/CleverAgeCacheProcessExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
use CleverAge\CacheProcessBundle\Task\SetTask;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

#[CoversClass(CleverAgeCacheProcessExtension::class)]
#[UsesClass(AdapterRegistry::class)]
class CleverAgeCacheProcessExtensionTest extends TestCase
{
public function testRegistryIsRegistered(): void
Expand All @@ -36,6 +38,24 @@ public function testRegistryIsRegistered(): void
self::assertTrue($definition->isShared());
}

public function testRegistryCanBeAutowired(): void
{
$container = new ContainerBuilder();
(new CleverAgeCacheProcessExtension())->load([], $container);

$alias = $container->getAlias(AdapterRegistry::class);
self::assertSame('cleverage_cache_process.registry.adapter', (string) $alias);
self::assertFalse($alias->isPublic());

// e.g. a custom cache task extending AbstractCacheTask, autowired by the application
$container->register('app.service', AutowiredRegistryConsumer::class)->setAutowired(true)->setPublic(true);
$container->compile(true);

$service = $container->get('app.service');
self::assertInstanceOf(AutowiredRegistryConsumer::class, $service);
self::assertInstanceOf(AdapterRegistry::class, $service->registry);
}

/**
* @return iterable<string, array{class-string, string, string}>
*/
Expand Down Expand Up @@ -76,3 +96,10 @@ public function testTaskIsRegistered(string $class, string $code, string $deprec
);
}
}

final readonly class AutowiredRegistryConsumer
{
public function __construct(public AdapterRegistry $registry)
{
}
}
Loading