cache.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Psr\Cache\CacheItemPoolInterface;
  12. use Symfony\Component\Cache\Adapter\TagAwareAdapter;
  13. use Symfony\Contracts\Cache\CacheInterface;
  14. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  15. use Twig\Extra\Cache\CacheExtension;
  16. use Twig\Extra\Cache\CacheRuntime;
  17. return static function (ContainerConfigurator $container) {
  18. $service = function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service') ? 'Symfony\Component\DependencyInjection\Loader\Configurator\service' : 'Symfony\Component\DependencyInjection\Loader\Configurator\ref';
  19. $container->services()
  20. ->set('twig.extension.cache', CacheExtension::class)
  21. ->tag('twig.extension')
  22. ->set('twig.runtime.cache', CacheRuntime::class)
  23. ->args([
  24. $service('twig.cache'),
  25. ])
  26. ->tag('twig.runtime')
  27. ->set('twig.cache', TagAwareAdapter::class)
  28. ->args([
  29. $service('.twig.cache.inner')
  30. ])
  31. ->set('.twig.cache.inner')
  32. ->parent('cache.app')
  33. ->tag('cache.pool', ['name' => 'twig.cache'])
  34. ->alias(TagAwareCacheInterface::class.' $twigCache', 'twig.cache')
  35. ->alias(CacheInterface::class.' $twigCache', '.twig.cache.inner')
  36. ->alias(CacheItemPoolInterface::class.' $twigCache', '.twig.cache.inner')
  37. ;
  38. };