Skip to content

Commit 1d8d9f6

Browse files
Merge branch '3.2' into 3.3
* 3.2: Fix optional cache warmers are always instantiated whereas they should be lazy-loaded add some \ on PHP_VERSION_ID for 2.8 [PropertyInfo][DoctrineBridge] The bigint Doctrine's type must be converted to string
2 parents 5fc47ac + 8a3ea57 commit 1d8d9f6

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

CacheWarmer/ClassCacheCacheWarmer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ClassCacheCacheWarmer implements CacheWarmerInterface
2727

2828
public function __construct(array $declaredClasses = null)
2929
{
30-
if (PHP_VERSION_ID >= 70000) {
30+
if (\PHP_VERSION_ID >= 70000) {
3131
@trigger_error('The '.__CLASS__.' class is deprecated since version 3.3 and will be removed in 4.0.', E_USER_DEPRECATED);
3232
}
3333

CacheWarmer/TranslationsCacheWarmer.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14+
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1516
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
1617
use Symfony\Component\Translation\TranslatorInterface;
@@ -22,18 +23,35 @@
2223
*/
2324
class TranslationsCacheWarmer implements CacheWarmerInterface
2425
{
26+
private $container;
2527
private $translator;
2628

27-
public function __construct(TranslatorInterface $translator)
29+
/**
30+
* TranslationsCacheWarmer constructor.
31+
*
32+
* @param ContainerInterface|TranslatorInterface $container
33+
*/
34+
public function __construct($container)
2835
{
29-
$this->translator = $translator;
36+
// As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
37+
if ($container instanceof ContainerInterface) {
38+
$this->container = $container;
39+
} elseif ($container instanceof TranslatorInterface) {
40+
$this->translator = $container;
41+
} 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+
}
3044
}
3145

3246
/**
3347
* {@inheritdoc}
3448
*/
3549
public function warmUp($cacheDir)
3650
{
51+
if (null === $this->translator) {
52+
$this->translator = $this->container->get('translator');
53+
}
54+
3755
if ($this->translator instanceof WarmableInterface) {
3856
$this->translator->warmUp($cacheDir);
3957
}

DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function load(array $configs, ContainerBuilder $container)
9696
$loader->load('web.xml');
9797
$loader->load('services.xml');
9898

99-
if (PHP_VERSION_ID < 70000) {
99+
if (\PHP_VERSION_ID < 70000) {
100100
$definition = $container->getDefinition('kernel.class_cache.cache_warmer');
101101
$definition->addTag('kernel.cache_warmer');
102102
// Ignore deprecation for PHP versions below 7.0
@@ -289,7 +289,7 @@ public function load(array $configs, ContainerBuilder $container)
289289
$container->registerForAutoconfiguration(ObjectInitializerInterface::class)
290290
->addTag('validator.initializer');
291291

292-
if (PHP_VERSION_ID < 70000) {
292+
if (\PHP_VERSION_ID < 70000) {
293293
$this->addClassesToCompile(array(
294294
'Symfony\\Component\\Config\\ConfigCache',
295295
'Symfony\\Component\\Config\\FileLocator',
@@ -674,7 +674,7 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
674674
$container->setParameter('request_listener.http_port', $config['http_port']);
675675
$container->setParameter('request_listener.https_port', $config['https_port']);
676676

677-
if (PHP_VERSION_ID < 70000) {
677+
if (\PHP_VERSION_ID < 70000) {
678678
$this->addClassesToCompile(array(
679679
'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
680680
'Symfony\\Component\\Routing\\RequestContext',
@@ -725,7 +725,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
725725

726726
$container->setParameter('session.save_path', $config['save_path']);
727727

728-
if (PHP_VERSION_ID < 70000) {
728+
if (\PHP_VERSION_ID < 70000) {
729729
$this->addClassesToCompile(array(
730730
'Symfony\\Component\\HttpKernel\\EventListener\\SessionListener',
731731
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage',
@@ -810,7 +810,7 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
810810
$container->setDefinition('templating.loader', $loaderCache);
811811
}
812812

813-
if (PHP_VERSION_ID < 70000) {
813+
if (\PHP_VERSION_ID < 70000) {
814814
$this->addClassesToCompile(array(
815815
'Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables',
816816
'Symfony\\Bundle\\FrameworkBundle\\Templating\\TemplateReference',
@@ -850,7 +850,7 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
850850
$container->setAlias('debug.templating.engine.php', 'templating.engine.php');
851851
}
852852

853-
if (PHP_VERSION_ID < 70000) {
853+
if (\PHP_VERSION_ID < 70000) {
854854
$this->addClassesToCompile(array(
855855
'Symfony\\Component\\Templating\\Storage\\FileStorage',
856856
'Symfony\\Bundle\\FrameworkBundle\\Templating\\PhpEngine',
@@ -1191,7 +1191,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
11911191
$definition = $container->findDefinition('annotations.cache_warmer');
11921192
$definition->addTag('kernel.cache_warmer');
11931193

1194-
if (PHP_VERSION_ID < 70000) {
1194+
if (\PHP_VERSION_ID < 70000) {
11951195
$this->addClassesToCompile(array(
11961196
'Symfony\Component\Cache\Adapter\PhpArrayAdapter',
11971197
'Symfony\Component\Cache\DoctrineProvider',
@@ -1448,7 +1448,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
14481448
}
14491449
}
14501450

1451-
if (PHP_VERSION_ID < 70000) {
1451+
if (\PHP_VERSION_ID < 70000) {
14521452
$this->addClassesToCompile(array(
14531453
'Symfony\Component\Cache\Adapter\ApcuAdapter',
14541454
'Symfony\Component\Cache\Adapter\FilesystemAdapter',

Resources/config/translation.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
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="translator" />
126+
<argument type="service" id="service_container" />
127127
<tag name="kernel.cache_warmer" />
128128
</service>
129129

0 commit comments

Comments
 (0)