Skip to content

Commit fe4d885

Browse files
Merge branch '2.8' into 3.2
* 2.8: 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 8d609d9 + 7632bed commit fe4d885

File tree

14 files changed

+61
-18
lines changed

14 files changed

+61
-18
lines changed

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ private function getPhpType($doctrineType)
174174
{
175175
switch ($doctrineType) {
176176
case DBALType::SMALLINT:
177-
case DBALType::BIGINT:
178177
case DBALType::INTEGER:
179178
return Type::BUILTIN_TYPE_INT;
180179

181180
case DBALType::FLOAT:
182181
return Type::BUILTIN_TYPE_FLOAT;
183182

183+
case DBALType::BIGINT:
184184
case DBALType::STRING:
185185
case DBALType::TEXT:
186186
case DBALType::GUID:
@@ -196,9 +196,6 @@ private function getPhpType($doctrineType)
196196

197197
case DBALType::OBJECT:
198198
return Type::BUILTIN_TYPE_OBJECT;
199-
200-
default:
201-
return;
202199
}
203200
}
204201
}

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function testGetProperties()
5555
'bool',
5656
'binary',
5757
'customFoo',
58+
'bigint',
5859
'foo',
5960
'bar',
6061
'indexedBar',
@@ -76,6 +77,7 @@ public function typesProvider()
7677
return array(
7778
array('id', array(new Type(Type::BUILTIN_TYPE_INT))),
7879
array('guid', array(new Type(Type::BUILTIN_TYPE_STRING))),
80+
array('bigint', array(new Type(Type::BUILTIN_TYPE_STRING))),
7981
array('float', array(new Type(Type::BUILTIN_TYPE_FLOAT))),
8082
array('decimal', array(new Type(Type::BUILTIN_TYPE_STRING))),
8183
array('bool', array(new Type(Type::BUILTIN_TYPE_BOOL))),

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php

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

1212
namespace Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
1313

14+
use Doctrine\ORM\Mapping as ORM;
1415
use Doctrine\ORM\Mapping\Column;
1516
use Doctrine\ORM\Mapping\Entity;
1617
use Doctrine\ORM\Mapping\Id;
@@ -90,5 +91,10 @@ class DoctrineDummy
9091
*/
9192
private $customFoo;
9293

94+
/**
95+
* @Column(type="bigint")
96+
*/
97+
private $bigint;
98+
9399
public $notMapped;
94100
}

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
error_reporting(-1);
1717

1818
// PHPUnit 4.8 does not support PHP 7, while 5.1 requires PHP 5.6+
19-
$PHPUNIT_VERSION = PHP_VERSION_ID >= 50600 ? getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.4' : '4.8';
19+
$PHPUNIT_VERSION = \PHP_VERSION_ID >= 50600 ? getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.4' : '4.8';
2020
$oldPwd = getcwd();
2121
$PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: (__DIR__.'/.phpunit');
2222
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';

src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testOneVar()
8686

8787
EOTXT;
8888

89-
if (PHP_VERSION_ID >= 70000) {
89+
if (\PHP_VERSION_ID >= 70000) {
9090
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
9191
} else {
9292
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);

src/Symfony/Bundle/FrameworkBundle/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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
<service id="translation.writer" class="Symfony\Component\Translation\Writer\TranslationWriter"/>
129129

130130
<service id="translation.warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer" public="false">
131-
<argument type="service" id="translator" />
131+
<argument type="service" id="service_container" />
132132
<tag name="kernel.cache_warmer" />
133133
</service>
134134

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

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

1212
namespace Symfony\Bundle\TwigBundle\CacheWarmer;
1313

14+
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1516
use Twig\Environment;
1617
use Twig\Error\Error;
@@ -22,12 +23,27 @@
2223
*/
2324
class TemplateCacheWarmer implements CacheWarmerInterface
2425
{
26+
private $container;
2527
private $twig;
2628
private $iterator;
2729

28-
public function __construct(Environment $twig, \Traversable $iterator)
30+
/**
31+
* TemplateCacheWarmer constructor.
32+
*
33+
* @param ContainerInterface|Environment $container
34+
* @param \Traversable $iterator
35+
*/
36+
public function __construct($container, \Traversable $iterator)
2937
{
30-
$this->twig = $twig;
38+
// As this cache warmer is optional, dependencies should be lazy-loaded, that's why a container should be injected.
39+
if ($container instanceof ContainerInterface) {
40+
$this->container = $container;
41+
} elseif ($container instanceof Environment) {
42+
$this->twig = $container;
43+
} else {
44+
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Environment as first argument.', __CLASS__));
45+
}
46+
3147
$this->iterator = $iterator;
3248
}
3349

@@ -36,6 +52,10 @@ public function __construct(Environment $twig, \Traversable $iterator)
3652
*/
3753
public function warmUp($cacheDir)
3854
{
55+
if (null === $this->twig) {
56+
$this->twig = $this->container->get('twig');
57+
}
58+
3959
foreach ($this->iterator as $template) {
4060
try {
4161
$this->twig->loadTemplate($template);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<service id="twig.template_cache_warmer" class="Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer" public="false">
4242
<tag name="kernel.cache_warmer" />
43-
<argument type="service" id="twig" />
43+
<argument type="service" id="service_container" />
4444
<argument type="service" id="twig.template_iterator" />
4545
</service>
4646

src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function ($key, $value, $isHit) {
6565
public static function create($file, CacheItemPoolInterface $fallbackPool)
6666
{
6767
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
68-
if ((PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
68+
if ((\PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || defined('HHVM_VERSION')) {
6969
if (!$fallbackPool instanceof AdapterInterface) {
7070
$fallbackPool = new ProxyAdapter($fallbackPool);
7171
}

0 commit comments

Comments
 (0)