|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * This file is part of the CleverAge/ProcessBundle package. |
| 4 | + * |
| 5 | + * Copyright (C) 2017-2019 Clever-Age |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace CleverAge\CacheProcessBundle\DependencyInjection\Compiler; |
| 12 | + |
| 13 | +use Psr\Cache\CacheItemPoolInterface; |
| 14 | +use Symfony\Component\DependencyInjection\ChildDefinition; |
| 15 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 16 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 17 | +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
| 18 | +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
| 19 | +use Symfony\Contracts\Cache\CacheInterface; |
| 20 | + |
| 21 | +/** |
| 22 | + * Generic compiler pass to add tagged services to a registry |
| 23 | + * |
| 24 | + * @author Madeline Veyrenc <[email protected]> |
| 25 | + */ |
| 26 | +class CachePoolPass implements CompilerPassInterface |
| 27 | +{ |
| 28 | + /** |
| 29 | + * Inject tagged services into defined registry |
| 30 | + * |
| 31 | + * @param ContainerBuilder $container |
| 32 | + * |
| 33 | + * @throws InvalidArgumentException |
| 34 | + * @throws \UnexpectedValueException |
| 35 | + * @throws ServiceNotFoundException |
| 36 | + * @throws \Exception |
| 37 | + * @api |
| 38 | + * |
| 39 | + */ |
| 40 | + public function process(ContainerBuilder $container) |
| 41 | + { |
| 42 | + $name = 'cache.app.cleverage_process'; |
| 43 | + $pool = [ |
| 44 | + 'adapter' => 'cache.app', |
| 45 | + 'public' => true, |
| 46 | + ]; |
| 47 | + $definition = new ChildDefinition($pool['adapter']); |
| 48 | + $container->registerAliasForArgument($name, CacheInterface::class); |
| 49 | + $container->registerAliasForArgument($name, CacheItemPoolInterface::class); |
| 50 | + $definition->setPublic($pool['public']); |
| 51 | + |
| 52 | + $definition->addTag('cache.pool'); |
| 53 | + $container->setDefinition($name, $definition); |
| 54 | + } |
| 55 | +} |
0 commit comments