From 4ba59c9cdd3fa14bcd012dd6eb35ac015d5c2cc5 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Fri, 2 Jun 2017 16:38:10 +0200 Subject: [PATCH] Implement ServiceSubscriberInterface in optional cache warmers --- .../CacheWarmer/TranslationsCacheWarmer.php | 17 ++++++++++++++--- .../Resources/config/translation.xml | 3 ++- .../CacheWarmer/TemplateCacheWarmer.php | 17 ++++++++++++++--- .../Bundle/TwigBundle/Resources/config/twig.xml | 3 ++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php index 33f94650449fb..ac08766b8fca0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php @@ -11,7 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Psr\Container\ContainerInterface; +use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface; use Symfony\Component\Translation\TranslatorInterface; @@ -21,7 +22,7 @@ * * @author Xavier Leune */ -class TranslationsCacheWarmer implements CacheWarmerInterface +class TranslationsCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface { private $container; private $translator; @@ -39,7 +40,7 @@ public function __construct($container) } elseif ($container instanceof TranslatorInterface) { $this->translator = $container; } else { - throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Translation\TranslatorInterface as first argument.', __CLASS__)); + throw new \InvalidArgumentException(sprintf('%s only accepts instance of Psr\Container\ContainerInterface as first argument.', __CLASS__)); } } @@ -64,4 +65,14 @@ public function isOptional() { return true; } + + /** + * {@inheritdoc} + */ + public static function getSubscribedServices() + { + return array( + 'translator' => TranslatorInterface::class, + ); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml index 5f98febda6304..4f8999d0cb647 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml @@ -123,8 +123,9 @@ - + + diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php index 9a60a92e85375..133743662f474 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php @@ -11,7 +11,8 @@ namespace Symfony\Bundle\TwigBundle\CacheWarmer; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Psr\Container\ContainerInterface; +use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Twig\Environment; use Twig\Error\Error; @@ -21,7 +22,7 @@ * * @author Fabien Potencier */ -class TemplateCacheWarmer implements CacheWarmerInterface +class TemplateCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface { private $container; private $twig; @@ -41,7 +42,7 @@ public function __construct($container, \Traversable $iterator) } elseif ($container instanceof Environment) { $this->twig = $container; } else { - throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Environment as first argument.', __CLASS__)); + throw new \InvalidArgumentException(sprintf('%s only accepts instance of Psr\Container\ContainerInterface as first argument.', __CLASS__)); } $this->iterator = $iterator; @@ -73,4 +74,14 @@ public function isOptional() { return true; } + + /** + * {@inheritdoc} + */ + public static function getSubscribedServices() + { + return array( + 'twig' => Environment::class, + ); + } } diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 310ab14063a0b..bf53c2b2b28f6 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -45,7 +45,8 @@ - + +