feature #23036 [3.4] Implement ServiceSubscriberInterface in optional cache warmers (romainneutron)
This PR was merged into the 3.4 branch.
Discussion
----------
[3.4] Implement ServiceSubscriberInterface in optional cache warmers
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass? | yes
| Fixed tickets |
| License | MIT
Commits
-------
4ba59c9
Implement ServiceSubscriberInterface in optional cache warmers
This commit is contained in:
commit
4fbc2a6d08
@ -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 @@ use Symfony\Component\Translation\TranslatorInterface;
|
||||
*
|
||||
* @author Xavier Leune <xavier.leune@gmail.com>
|
||||
*/
|
||||
class TranslationsCacheWarmer implements CacheWarmerInterface
|
||||
class TranslationsCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
|
||||
{
|
||||
private $container;
|
||||
private $translator;
|
||||
@ -39,7 +40,7 @@ class TranslationsCacheWarmer implements CacheWarmerInterface
|
||||
} 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 @@ class TranslationsCacheWarmer implements CacheWarmerInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return array(
|
||||
'translator' => TranslatorInterface::class,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -123,8 +123,9 @@
|
||||
<service id="translation.writer" class="Symfony\Component\Translation\Writer\TranslationWriter" public="true" />
|
||||
|
||||
<service id="translation.warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer">
|
||||
<argument type="service" id="service_container" />
|
||||
<tag name="container.service_subscriber" id="translator" />
|
||||
<tag name="kernel.cache_warmer" />
|
||||
<argument type="service" id="Psr\Container\ContainerInterface" />
|
||||
</service>
|
||||
|
||||
<service id="translator_listener" class="Symfony\Component\HttpKernel\EventListener\TranslatorListener" public="true">
|
||||
|
@ -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 @@ use Twig\Error\Error;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TemplateCacheWarmer implements CacheWarmerInterface
|
||||
class TemplateCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
|
||||
{
|
||||
private $container;
|
||||
private $twig;
|
||||
@ -41,7 +42,7 @@ class TemplateCacheWarmer implements CacheWarmerInterface
|
||||
} 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 @@ class TemplateCacheWarmer implements CacheWarmerInterface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return array(
|
||||
'twig' => Environment::class,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,8 @@
|
||||
|
||||
<service id="twig.template_cache_warmer" class="Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer">
|
||||
<tag name="kernel.cache_warmer" />
|
||||
<argument type="service" id="service_container" />
|
||||
<tag name="container.service_subscriber" id="twig" />
|
||||
<argument type="service" id="Psr\Container\ContainerInterface" />
|
||||
<argument type="service" id="twig.template_iterator" />
|
||||
</service>
|
||||
|
||||
|
Reference in New Issue
Block a user