Skip to content

Commit e9a61a0

Browse files
Merge branch '3.2'
* 3.2: [VarDumper] Add missing isset() checks in some casters [VarDumper] Add missing isset() checks in some casters [Form] Choice type int values (BC Fix) bumped Symfony version to 3.2.7 updated VERSION for 3.2.6 updated CHANGELOG for 3.2.6 Use PHPUnit 5.4 instead of 5.3 [PropertyAccess] Use ArrayAdapter in debug mode bumped Symfony version to 3.2.6 updated VERSION for 3.2.5 updated CHANGELOG for 3.2.5 cached files rely on umask
2 parents 9157375 + b5ea84b commit e9a61a0

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Annotations\Reader;
1515
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1616
use Symfony\Component\Cache\Adapter\AdapterInterface;
17+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1718
use Symfony\Component\Config\Loader\LoaderInterface;
1819
use Symfony\Component\Config\Resource\DirectoryResource;
1920
use Symfony\Component\DependencyInjection\Alias;
@@ -1313,10 +1314,16 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
13131314
if (method_exists(PropertyAccessor::class, 'createCache')) {
13141315
$propertyAccessDefinition = $container->register('cache.property_access', AdapterInterface::class);
13151316
$propertyAccessDefinition->setPublic(false);
1316-
$propertyAccessDefinition->setFactory(array(PropertyAccessor::class, 'createCache'));
1317-
$propertyAccessDefinition->setArguments(array(null, null, $version, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
1318-
$propertyAccessDefinition->addTag('cache.pool', array('clearer' => 'cache.default_clearer'));
1319-
$propertyAccessDefinition->addTag('monolog.logger', array('channel' => 'cache'));
1317+
1318+
if (!$container->getParameter('kernel.debug')) {
1319+
$propertyAccessDefinition->setFactory(array(PropertyAccessor::class, 'createCache'));
1320+
$propertyAccessDefinition->setArguments(array(null, null, $version, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
1321+
$propertyAccessDefinition->addTag('cache.pool', array('clearer' => 'cache.default_clearer'));
1322+
$propertyAccessDefinition->addTag('monolog.logger', array('channel' => 'cache'));
1323+
} else {
1324+
$propertyAccessDefinition->setClass(ArrayAdapter::class);
1325+
$propertyAccessDefinition->setArguments(array(0, false));
1326+
}
13201327
}
13211328

13221329
if (PHP_VERSION_ID < 70000) {

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
19+
use Symfony\Component\Cache\Adapter\AdapterInterface;
1920
use Symfony\Component\Cache\Adapter\ApcuAdapter;
21+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2022
use Symfony\Component\Cache\Adapter\ChainAdapter;
2123
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
2224
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
@@ -27,6 +29,7 @@
2729
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
2830
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2931
use Symfony\Component\DependencyInjection\Reference;
32+
use Symfony\Component\PropertyAccess\PropertyAccessor;
3033
use Symfony\Component\Serializer\Serializer;
3134
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
3235
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
@@ -70,6 +73,32 @@ public function testPropertyAccessWithOverriddenValues()
7073
$this->assertTrue($def->getArgument(1));
7174
}
7275

76+
public function testPropertyAccessCache()
77+
{
78+
$container = $this->createContainerFromFile('property_accessor');
79+
80+
if (!method_exists(PropertyAccessor::class, 'createCache')) {
81+
return $this->assertFalse($container->hasDefinition('cache.property_access'));
82+
}
83+
84+
$cache = $container->getDefinition('cache.property_access');
85+
$this->assertSame(array(PropertyAccessor::class, 'createCache'), $cache->getFactory(), 'PropertyAccessor::createCache() should be used in non-debug mode');
86+
$this->assertSame(AdapterInterface::class, $cache->getClass());
87+
}
88+
89+
public function testPropertyAccessCacheWithDebug()
90+
{
91+
$container = $this->createContainerFromFile('property_accessor', array('kernel.debug' => true));
92+
93+
if (!method_exists(PropertyAccessor::class, 'createCache')) {
94+
return $this->assertFalse($container->hasDefinition('cache.property_access'));
95+
}
96+
97+
$cache = $container->getDefinition('cache.property_access');
98+
$this->assertNull($cache->getFactory());
99+
$this->assertSame(ArrayAdapter::class, $cache->getClass(), 'ArrayAdapter should be used in debug mode');
100+
}
101+
73102
/**
74103
* @expectedException \LogicException
75104
* @expectedExceptionMessage CSRF protection needs sessions to be enabled.

0 commit comments

Comments
 (0)