Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4fbc2a6

Browse filesBrowse files
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
2 parents 36a8160 + 4ba59c9 commit 4fbc2a6
Copy full SHA for 4fbc2a6

File tree

4 files changed

+32
-8
lines changed
Filter options

4 files changed

+32
-8
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14-
use Symfony\Component\DependencyInjection\ContainerInterface;
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1516
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1617
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
1718
use Symfony\Component\Translation\TranslatorInterface;
@@ -21,7 +22,7 @@
2122
*
2223
* @author Xavier Leune <xavier.leune@gmail.com>
2324
*/
24-
class TranslationsCacheWarmer implements CacheWarmerInterface
25+
class TranslationsCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
2526
{
2627
private $container;
2728
private $translator;
@@ -39,7 +40,7 @@ public function __construct($container)
3940
} elseif ($container instanceof TranslatorInterface) {
4041
$this->translator = $container;
4142
} else {
42-
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Translation\TranslatorInterface as first argument.', __CLASS__));
43+
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Psr\Container\ContainerInterface as first argument.', __CLASS__));
4344
}
4445
}
4546

@@ -64,4 +65,14 @@ public function isOptional()
6465
{
6566
return true;
6667
}
68+
69+
/**
70+
* {@inheritdoc}
71+
*/
72+
public static function getSubscribedServices()
73+
{
74+
return array(
75+
'translator' => TranslatorInterface::class,
76+
);
77+
}
6778
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@
123123
<service id="translation.writer" class="Symfony\Component\Translation\Writer\TranslationWriter" public="true" />
124124

125125
<service id="translation.warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer">
126-
<argument type="service" id="service_container" />
126+
<tag name="container.service_subscriber" id="translator" />
127127
<tag name="kernel.cache_warmer" />
128+
<argument type="service" id="Psr\Container\ContainerInterface" />
128129
</service>
129130

130131
<service id="translator_listener" class="Symfony\Component\HttpKernel\EventListener\TranslatorListener" public="true">

‎src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\CacheWarmer;
1313

14-
use Symfony\Component\DependencyInjection\ContainerInterface;
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1516
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1617
use Twig\Environment;
1718
use Twig\Error\Error;
@@ -21,7 +22,7 @@
2122
*
2223
* @author Fabien Potencier <fabien@symfony.com>
2324
*/
24-
class TemplateCacheWarmer implements CacheWarmerInterface
25+
class TemplateCacheWarmer implements CacheWarmerInterface, ServiceSubscriberInterface
2526
{
2627
private $container;
2728
private $twig;
@@ -41,7 +42,7 @@ public function __construct($container, \Traversable $iterator)
4142
} elseif ($container instanceof Environment) {
4243
$this->twig = $container;
4344
} else {
44-
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Environment as first argument.', __CLASS__));
45+
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Psr\Container\ContainerInterface as first argument.', __CLASS__));
4546
}
4647

4748
$this->iterator = $iterator;
@@ -73,4 +74,14 @@ public function isOptional()
7374
{
7475
return true;
7576
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*/
81+
public static function getSubscribedServices()
82+
{
83+
return array(
84+
'twig' => Environment::class,
85+
);
86+
}
7687
}

‎src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545

4646
<service id="twig.template_cache_warmer" class="Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer">
4747
<tag name="kernel.cache_warmer" />
48-
<argument type="service" id="service_container" />
48+
<tag name="container.service_subscriber" id="twig" />
49+
<argument type="service" id="Psr\Container\ContainerInterface" />
4950
<argument type="service" id="twig.template_iterator" />
5051
</service>
5152

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.