[PropertyAccess] Use ArrayAdapter in debug mode
This commit is contained in:
parent
2fad5affe6
commit
dca3f365d7
@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
|
|||||||
use Doctrine\Common\Annotations\Reader;
|
use Doctrine\Common\Annotations\Reader;
|
||||||
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
|
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
|
||||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||||
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
use Symfony\Component\DependencyInjection\Alias;
|
use Symfony\Component\DependencyInjection\Alias;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
@ -1256,10 +1257,16 @@ class FrameworkExtension extends Extension
|
|||||||
if (method_exists(PropertyAccessor::class, 'createCache')) {
|
if (method_exists(PropertyAccessor::class, 'createCache')) {
|
||||||
$propertyAccessDefinition = $container->register('cache.property_access', AdapterInterface::class);
|
$propertyAccessDefinition = $container->register('cache.property_access', AdapterInterface::class);
|
||||||
$propertyAccessDefinition->setPublic(false);
|
$propertyAccessDefinition->setPublic(false);
|
||||||
|
|
||||||
|
if (!$container->getParameter('kernel.debug')) {
|
||||||
$propertyAccessDefinition->setFactory(array(PropertyAccessor::class, 'createCache'));
|
$propertyAccessDefinition->setFactory(array(PropertyAccessor::class, 'createCache'));
|
||||||
$propertyAccessDefinition->setArguments(array(null, null, $version, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
$propertyAccessDefinition->setArguments(array(null, null, $version, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
||||||
$propertyAccessDefinition->addTag('cache.pool', array('clearer' => 'cache.default_clearer'));
|
$propertyAccessDefinition->addTag('cache.pool', array('clearer' => 'cache.default_clearer'));
|
||||||
$propertyAccessDefinition->addTag('monolog.logger', array('channel' => 'cache'));
|
$propertyAccessDefinition->addTag('monolog.logger', array('channel' => 'cache'));
|
||||||
|
} else {
|
||||||
|
$propertyAccessDefinition->setClass(ArrayAdapter::class);
|
||||||
|
$propertyAccessDefinition->setArguments(array(0, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addClassesToCompile(array(
|
$this->addClassesToCompile(array(
|
||||||
|
@ -14,7 +14,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
||||||
|
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||||
use Symfony\Component\Cache\Adapter\ApcuAdapter;
|
use Symfony\Component\Cache\Adapter\ApcuAdapter;
|
||||||
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\ChainAdapter;
|
use Symfony\Component\Cache\Adapter\ChainAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
|
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
@ -25,6 +27,7 @@ use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
|||||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||||
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
||||||
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
|
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
||||||
@ -67,6 +70,32 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
$this->assertTrue($def->getArgument(1));
|
$this->assertTrue($def->getArgument(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPropertyAccessCache()
|
||||||
|
{
|
||||||
|
$container = $this->createContainerFromFile('property_accessor');
|
||||||
|
|
||||||
|
if (!method_exists(PropertyAccessor::class, 'createCache')) {
|
||||||
|
return $this->assertFalse($container->hasDefinition('cache.property_access'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache = $container->getDefinition('cache.property_access');
|
||||||
|
$this->assertSame(array(PropertyAccessor::class, 'createCache'), $cache->getFactory(), 'PropertyAccessor::createCache() should be used in non-debug mode');
|
||||||
|
$this->assertSame(AdapterInterface::class, $cache->getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPropertyAccessCacheWithDebug()
|
||||||
|
{
|
||||||
|
$container = $this->createContainerFromFile('property_accessor', array('kernel.debug' => true));
|
||||||
|
|
||||||
|
if (!method_exists(PropertyAccessor::class, 'createCache')) {
|
||||||
|
return $this->assertFalse($container->hasDefinition('cache.property_access'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache = $container->getDefinition('cache.property_access');
|
||||||
|
$this->assertNull($cache->getFactory());
|
||||||
|
$this->assertSame(ArrayAdapter::class, $cache->getClass(), 'ArrayAdapter should be used in debug mode');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \LogicException
|
* @expectedException \LogicException
|
||||||
* @expectedExceptionMessage CSRF protection needs sessions to be enabled.
|
* @expectedExceptionMessage CSRF protection needs sessions to be enabled.
|
||||||
|
Reference in New Issue
Block a user