Merge branch '3.3' into 3.4
* 3.3: [Security] added more tests [Security] fixed default target path when referer contains a query string [Security] simplified tests [Security] refactored tests [WebProfilerBundle][TwigBundle] Fix infinite js loop on exception pages [FrameworkBundle] fix ValidatorCacheWarmer: use serializing ArrayAdapter Change "this" to "that" to avoid confusion [VarDumper] Move locale sniffing to dump() time [VarDumper] Use "C" locale when using "comma" flags [Config] Make ClassExistenceResource throw on invalid parents
This commit is contained in:
commit
8c028bd956
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
||||||
|
|
||||||
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
|
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||||
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
|
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||||
|
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||||
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface
|
||||||
|
{
|
||||||
|
private $phpArrayFile;
|
||||||
|
private $fallbackPool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $phpArrayFile The PHP file where metadata are cached
|
||||||
|
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
|
||||||
|
*/
|
||||||
|
public function __construct($phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
||||||
|
{
|
||||||
|
$this->phpArrayFile = $phpArrayFile;
|
||||||
|
if (!$fallbackPool instanceof AdapterInterface) {
|
||||||
|
$fallbackPool = new ProxyAdapter($fallbackPool);
|
||||||
|
}
|
||||||
|
$this->fallbackPool = $fallbackPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function isOptional()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function warmUp($cacheDir)
|
||||||
|
{
|
||||||
|
$arrayAdapter = new ArrayAdapter();
|
||||||
|
|
||||||
|
spl_autoload_register(array(PhpArrayAdapter::class, 'throwOnRequiredClass'));
|
||||||
|
try {
|
||||||
|
if (!$this->doWarmUp($cacheDir, $arrayAdapter)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
spl_autoload_unregister(array(PhpArrayAdapter::class, 'throwOnRequiredClass'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// the ArrayAdapter stores the values serialized
|
||||||
|
// to avoid mutation of the data after it was written to the cache
|
||||||
|
// so here we un-serialize the values first
|
||||||
|
$values = array_map(function ($val) { return null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues());
|
||||||
|
|
||||||
|
$this->warmUpPhpArrayAdapter(new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool), $values);
|
||||||
|
|
||||||
|
foreach ($values as $k => $v) {
|
||||||
|
$item = $this->fallbackPool->getItem($k);
|
||||||
|
$this->fallbackPool->saveDeferred($item->set($v));
|
||||||
|
}
|
||||||
|
$this->fallbackPool->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
|
||||||
|
{
|
||||||
|
$phpArrayAdapter->warmUp($values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $cacheDir
|
||||||
|
* @param ArrayAdapter $arrayAdapter
|
||||||
|
*
|
||||||
|
* @return bool false if there is nothing to warm-up
|
||||||
|
*/
|
||||||
|
abstract protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter);
|
||||||
|
}
|
@ -15,12 +15,8 @@ use Doctrine\Common\Annotations\AnnotationException;
|
|||||||
use Doctrine\Common\Annotations\CachedReader;
|
use Doctrine\Common\Annotations\CachedReader;
|
||||||
use Doctrine\Common\Annotations\Reader;
|
use Doctrine\Common\Annotations\Reader;
|
||||||
use Psr\Cache\CacheItemPoolInterface;
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
|
||||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
|
||||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
|
||||||
use Symfony\Component\Cache\DoctrineProvider;
|
use Symfony\Component\Cache\DoctrineProvider;
|
||||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warms up annotation caches for classes found in composer's autoload class map
|
* Warms up annotation caches for classes found in composer's autoload class map
|
||||||
@ -28,11 +24,9 @@ use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
|||||||
*
|
*
|
||||||
* @author Titouan Galopin <galopintitouan@gmail.com>
|
* @author Titouan Galopin <galopintitouan@gmail.com>
|
||||||
*/
|
*/
|
||||||
class AnnotationsCacheWarmer implements CacheWarmerInterface
|
class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
|
||||||
{
|
{
|
||||||
private $annotationReader;
|
private $annotationReader;
|
||||||
private $phpArrayFile;
|
|
||||||
private $fallbackPool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Reader $annotationReader
|
* @param Reader $annotationReader
|
||||||
@ -41,70 +35,41 @@ class AnnotationsCacheWarmer implements CacheWarmerInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
||||||
{
|
{
|
||||||
|
parent::__construct($phpArrayFile, $fallbackPool);
|
||||||
$this->annotationReader = $annotationReader;
|
$this->annotationReader = $annotationReader;
|
||||||
$this->phpArrayFile = $phpArrayFile;
|
|
||||||
if (!$fallbackPool instanceof AdapterInterface) {
|
|
||||||
$fallbackPool = new ProxyAdapter($fallbackPool);
|
|
||||||
}
|
|
||||||
$this->fallbackPool = $fallbackPool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function warmUp($cacheDir)
|
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
|
||||||
{
|
{
|
||||||
$adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
|
|
||||||
$annotatedClassPatterns = $cacheDir.'/annotations.map';
|
$annotatedClassPatterns = $cacheDir.'/annotations.map';
|
||||||
|
|
||||||
if (!is_file($annotatedClassPatterns)) {
|
if (!is_file($annotatedClassPatterns)) {
|
||||||
$adapter->warmUp(array());
|
return true;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$annotatedClasses = include $annotatedClassPatterns;
|
$annotatedClasses = include $annotatedClassPatterns;
|
||||||
|
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayAdapter));
|
||||||
|
|
||||||
$arrayPool = new ArrayAdapter(0, false);
|
foreach ($annotatedClasses as $class) {
|
||||||
$reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayPool));
|
try {
|
||||||
|
$this->readAllComponents($reader, $class);
|
||||||
spl_autoload_register(array($adapter, 'throwOnRequiredClass'));
|
} catch (\ReflectionException $e) {
|
||||||
try {
|
// ignore failing reflection
|
||||||
foreach ($annotatedClasses as $class) {
|
} catch (AnnotationException $e) {
|
||||||
try {
|
/*
|
||||||
$this->readAllComponents($reader, $class);
|
* Ignore any AnnotationException to not break the cache warming process if an Annotation is badly
|
||||||
} catch (\ReflectionException $e) {
|
* configured or could not be found / read / etc.
|
||||||
// ignore failing reflection
|
*
|
||||||
} catch (AnnotationException $e) {
|
* In particular cases, an Annotation in your code can be used and defined only for a specific
|
||||||
/*
|
* environment but is always added to the annotations.map file by some Symfony default behaviors,
|
||||||
* Ignore any AnnotationException to not break the cache warming process if an Annotation is badly
|
* and you always end up with a not found Annotation.
|
||||||
* configured or could not be found / read / etc.
|
*/
|
||||||
*
|
|
||||||
* In particular cases, an Annotation in your code can be used and defined only for a specific
|
|
||||||
* environment but is always added to the annotations.map file by some Symfony default behaviors,
|
|
||||||
* and you always end up with a not found Annotation.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
spl_autoload_unregister(array($adapter, 'throwOnRequiredClass'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = $arrayPool->getValues();
|
|
||||||
$adapter->warmUp($values);
|
|
||||||
|
|
||||||
foreach ($values as $k => $v) {
|
|
||||||
$item = $this->fallbackPool->getItem($k);
|
|
||||||
$this->fallbackPool->saveDeferred($item->set($v));
|
|
||||||
}
|
|
||||||
$this->fallbackPool->commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function isOptional()
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
|||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationException;
|
use Doctrine\Common\Annotations\AnnotationException;
|
||||||
use Psr\Cache\CacheItemPoolInterface;
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
|
||||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
|
||||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
|
||||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
|
||||||
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
|
||||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||||
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
|
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
|
||||||
@ -30,11 +26,9 @@ use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
|||||||
*
|
*
|
||||||
* @author Titouan Galopin <galopintitouan@gmail.com>
|
* @author Titouan Galopin <galopintitouan@gmail.com>
|
||||||
*/
|
*/
|
||||||
class SerializerCacheWarmer implements CacheWarmerInterface
|
class SerializerCacheWarmer extends AbstractPhpFileCacheWarmer
|
||||||
{
|
{
|
||||||
private $loaders;
|
private $loaders;
|
||||||
private $phpArrayFile;
|
|
||||||
private $fallbackPool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param LoaderInterface[] $loaders The serializer metadata loaders
|
* @param LoaderInterface[] $loaders The serializer metadata loaders
|
||||||
@ -43,60 +37,33 @@ class SerializerCacheWarmer implements CacheWarmerInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
||||||
{
|
{
|
||||||
|
parent::__construct($phpArrayFile, $fallbackPool);
|
||||||
$this->loaders = $loaders;
|
$this->loaders = $loaders;
|
||||||
$this->phpArrayFile = $phpArrayFile;
|
|
||||||
if (!$fallbackPool instanceof AdapterInterface) {
|
|
||||||
$fallbackPool = new ProxyAdapter($fallbackPool);
|
|
||||||
}
|
|
||||||
$this->fallbackPool = $fallbackPool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function warmUp($cacheDir)
|
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
|
||||||
{
|
{
|
||||||
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
|
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
|
$metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayAdapter);
|
||||||
$arrayPool = new ArrayAdapter(0, false);
|
|
||||||
|
|
||||||
$metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayPool);
|
foreach ($this->extractSupportedLoaders($this->loaders) as $loader) {
|
||||||
|
foreach ($loader->getMappedClasses() as $mappedClass) {
|
||||||
spl_autoload_register(array($adapter, 'throwOnRequiredClass'));
|
try {
|
||||||
try {
|
$metadataFactory->getMetadataFor($mappedClass);
|
||||||
foreach ($this->extractSupportedLoaders($this->loaders) as $loader) {
|
} catch (\ReflectionException $e) {
|
||||||
foreach ($loader->getMappedClasses() as $mappedClass) {
|
// ignore failing reflection
|
||||||
try {
|
} catch (AnnotationException $e) {
|
||||||
$metadataFactory->getMetadataFor($mappedClass);
|
// ignore failing annotations
|
||||||
} catch (\ReflectionException $e) {
|
|
||||||
// ignore failing reflection
|
|
||||||
} catch (AnnotationException $e) {
|
|
||||||
// ignore failing annotations
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
spl_autoload_unregister(array($adapter, 'throwOnRequiredClass'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = $arrayPool->getValues();
|
|
||||||
$adapter->warmUp($values);
|
|
||||||
|
|
||||||
foreach ($values as $k => $v) {
|
|
||||||
$item = $this->fallbackPool->getItem($k);
|
|
||||||
$this->fallbackPool->saveDeferred($item->set($v));
|
|
||||||
}
|
|
||||||
$this->fallbackPool->commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function isOptional()
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,11 +13,8 @@ namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
|
|||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationException;
|
use Doctrine\Common\Annotations\AnnotationException;
|
||||||
use Psr\Cache\CacheItemPoolInterface;
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
|
||||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
|
||||||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
|
||||||
use Symfony\Component\Validator\Mapping\Cache\Psr6Cache;
|
use Symfony\Component\Validator\Mapping\Cache\Psr6Cache;
|
||||||
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
|
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
|
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
|
||||||
@ -31,11 +28,9 @@ use Symfony\Component\Validator\ValidatorBuilderInterface;
|
|||||||
*
|
*
|
||||||
* @author Titouan Galopin <galopintitouan@gmail.com>
|
* @author Titouan Galopin <galopintitouan@gmail.com>
|
||||||
*/
|
*/
|
||||||
class ValidatorCacheWarmer implements CacheWarmerInterface
|
class ValidatorCacheWarmer extends AbstractPhpFileCacheWarmer
|
||||||
{
|
{
|
||||||
private $validatorBuilder;
|
private $validatorBuilder;
|
||||||
private $phpArrayFile;
|
|
||||||
private $fallbackPool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ValidatorBuilderInterface $validatorBuilder
|
* @param ValidatorBuilderInterface $validatorBuilder
|
||||||
@ -44,64 +39,43 @@ class ValidatorCacheWarmer implements CacheWarmerInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArrayFile, CacheItemPoolInterface $fallbackPool)
|
||||||
{
|
{
|
||||||
|
parent::__construct($phpArrayFile, $fallbackPool);
|
||||||
$this->validatorBuilder = $validatorBuilder;
|
$this->validatorBuilder = $validatorBuilder;
|
||||||
$this->phpArrayFile = $phpArrayFile;
|
|
||||||
if (!$fallbackPool instanceof AdapterInterface) {
|
|
||||||
$fallbackPool = new ProxyAdapter($fallbackPool);
|
|
||||||
}
|
|
||||||
$this->fallbackPool = $fallbackPool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function warmUp($cacheDir)
|
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
|
||||||
{
|
{
|
||||||
if (!method_exists($this->validatorBuilder, 'getLoaders')) {
|
if (!method_exists($this->validatorBuilder, 'getLoaders')) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
|
|
||||||
$arrayPool = new ArrayAdapter(0, false);
|
|
||||||
|
|
||||||
$loaders = $this->validatorBuilder->getLoaders();
|
$loaders = $this->validatorBuilder->getLoaders();
|
||||||
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayPool));
|
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayAdapter));
|
||||||
|
|
||||||
spl_autoload_register(array($adapter, 'throwOnRequiredClass'));
|
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
|
||||||
try {
|
foreach ($loader->getMappedClasses() as $mappedClass) {
|
||||||
foreach ($this->extractSupportedLoaders($loaders) as $loader) {
|
try {
|
||||||
foreach ($loader->getMappedClasses() as $mappedClass) {
|
if ($metadataFactory->hasMetadataFor($mappedClass)) {
|
||||||
try {
|
$metadataFactory->getMetadataFor($mappedClass);
|
||||||
if ($metadataFactory->hasMetadataFor($mappedClass)) {
|
|
||||||
$metadataFactory->getMetadataFor($mappedClass);
|
|
||||||
}
|
|
||||||
} catch (\ReflectionException $e) {
|
|
||||||
// ignore failing reflection
|
|
||||||
} catch (AnnotationException $e) {
|
|
||||||
// ignore failing annotations
|
|
||||||
}
|
}
|
||||||
|
} catch (\ReflectionException $e) {
|
||||||
|
// ignore failing reflection
|
||||||
|
} catch (AnnotationException $e) {
|
||||||
|
// ignore failing annotations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
spl_autoload_unregister(array($adapter, 'throwOnRequiredClass'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = $arrayPool->getValues();
|
return true;
|
||||||
$adapter->warmUp(array_filter($values));
|
|
||||||
|
|
||||||
foreach ($values as $k => $v) {
|
|
||||||
$item = $this->fallbackPool->getItem($k);
|
|
||||||
$this->fallbackPool->saveDeferred($item->set($v));
|
|
||||||
}
|
|
||||||
$this->fallbackPool->commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function isOptional()
|
|
||||||
{
|
{
|
||||||
return true;
|
// make sure we don't cache null values
|
||||||
|
parent::warmUpPhpArrayAdapter($phpArrayAdapter, array_filter($values));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -512,14 +512,14 @@
|
|||||||
var altContent = toggle.getAttribute('data-toggle-alt-content');
|
var altContent = toggle.getAttribute('data-toggle-alt-content');
|
||||||
toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
|
toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* Prevents from disallowing clicks on links inside toggles */
|
/* Prevents from disallowing clicks on links inside toggles */
|
||||||
var toggleLinks = document.querySelectorAll('.sf-toggle a');
|
var toggleLinks = document.querySelectorAll('.sf-toggle a');
|
||||||
for (var i = 0; i < toggleLinks.length; i++) {
|
for (var i = 0; i < toggleLinks.length; i++) {
|
||||||
addEventListener(toggleLinks[i], 'click', function(e) {
|
addEventListener(toggleLinks[i], 'click', function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,6 +25,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
|||||||
private $exists;
|
private $exists;
|
||||||
|
|
||||||
private static $autoloadLevel = 0;
|
private static $autoloadLevel = 0;
|
||||||
|
private static $autoloadedClass;
|
||||||
private static $existsCache = array();
|
private static $existsCache = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,6 +58,8 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @throws \ReflectionException when a parent class/interface/trait is not found
|
||||||
*/
|
*/
|
||||||
public function isFresh($timestamp)
|
public function isFresh($timestamp)
|
||||||
{
|
{
|
||||||
@ -68,12 +71,13 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
|||||||
if (!self::$autoloadLevel++) {
|
if (!self::$autoloadLevel++) {
|
||||||
spl_autoload_register(__CLASS__.'::throwOnRequiredClass');
|
spl_autoload_register(__CLASS__.'::throwOnRequiredClass');
|
||||||
}
|
}
|
||||||
|
$autoloadedClass = self::$autoloadedClass;
|
||||||
|
self::$autoloadedClass = $this->resource;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
|
$exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
|
||||||
} catch (\ReflectionException $e) {
|
|
||||||
$exists = false;
|
|
||||||
} finally {
|
} finally {
|
||||||
|
self::$autoloadedClass = $autoloadedClass;
|
||||||
if (!--self::$autoloadLevel) {
|
if (!--self::$autoloadLevel) {
|
||||||
spl_autoload_unregister(__CLASS__.'::throwOnRequiredClass');
|
spl_autoload_unregister(__CLASS__.'::throwOnRequiredClass');
|
||||||
}
|
}
|
||||||
@ -112,7 +116,10 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
|||||||
*/
|
*/
|
||||||
private static function throwOnRequiredClass($class)
|
private static function throwOnRequiredClass($class)
|
||||||
{
|
{
|
||||||
$e = new \ReflectionException("Class $class does not exist");
|
if (self::$autoloadedClass === $class) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$e = new \ReflectionException("Class $class not found");
|
||||||
$trace = $e->getTrace();
|
$trace = $e->getTrace();
|
||||||
$autoloadFrame = array(
|
$autoloadFrame = array(
|
||||||
'function' => 'spl_autoload_call',
|
'function' => 'spl_autoload_call',
|
||||||
@ -138,6 +145,18 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
|||||||
case 'is_callable':
|
case 'is_callable':
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$props = array(
|
||||||
|
'file' => $trace[$i]['file'],
|
||||||
|
'line' => $trace[$i]['line'],
|
||||||
|
'trace' => array_slice($trace, 0, 1 + $i),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($props as $p => $v) {
|
||||||
|
$r = new \ReflectionProperty('Exception', $p);
|
||||||
|
$r->setAccessible(true);
|
||||||
|
$r->setValue($e, $v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -124,8 +124,8 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
|
if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
if (!$reflectionClass = $this->container->getReflectionClass($value->getClass())) {
|
if (!$reflectionClass = $this->container->getReflectionClass($value->getClass(), false)) {
|
||||||
$this->container->log($this, sprintf('Skipping service "%s": Class or interface "%s" does not exist.', $this->currentId, $value->getClass()));
|
$this->container->log($this, sprintf('Skipping service "%s": Class or interface "%s" cannot be loaded.', $this->currentId, $value->getClass()));
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
@ -388,7 +388,7 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
unset($this->ambiguousServiceTypes[$type]);
|
unset($this->ambiguousServiceTypes[$type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass())) {
|
if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
*/
|
*/
|
||||||
private function createAutowiredDefinition($type)
|
private function createAutowiredDefinition($type)
|
||||||
{
|
{
|
||||||
if (!($typeHint = $this->container->getReflectionClass($type)) || !$typeHint->isInstantiable()) {
|
if (!($typeHint = $this->container->getReflectionClass($type, false)) || !$typeHint->isInstantiable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,8 +478,8 @@ class AutowirePass extends AbstractRecursivePass
|
|||||||
|
|
||||||
private function createTypeNotFoundMessage(TypedReference $reference, $label)
|
private function createTypeNotFoundMessage(TypedReference $reference, $label)
|
||||||
{
|
{
|
||||||
if (!$r = $this->container->getReflectionClass($type = $reference->getType())) {
|
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
|
||||||
$message = sprintf('has type "%s" but this class does not exist.', $type);
|
$message = sprintf('has type "%s" but this class cannot be loaded.', $type);
|
||||||
} else {
|
} else {
|
||||||
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
|
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
|
||||||
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));
|
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));
|
||||||
|
@ -81,7 +81,7 @@ class FactoryReturnTypePass implements CompilerPassInterface
|
|||||||
$class = $factory[0];
|
$class = $factory[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$m = $container->getReflectionClass($class)) {
|
if (!$m = $container->getReflectionClass($class, false)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -26,7 +26,7 @@ trait PriorityTaggedServiceTrait
|
|||||||
*
|
*
|
||||||
* The order of additions must be respected for services having the same priority,
|
* The order of additions must be respected for services having the same priority,
|
||||||
* and knowing that the \SplPriorityQueue class does not respect the FIFO method,
|
* and knowing that the \SplPriorityQueue class does not respect the FIFO method,
|
||||||
* we should not use this class.
|
* we should not use that class.
|
||||||
*
|
*
|
||||||
* @see https://bugs.php.net/bug.php?id=53710
|
* @see https://bugs.php.net/bug.php?id=53710
|
||||||
* @see https://bugs.php.net/bug.php?id=60926
|
* @see https://bugs.php.net/bug.php?id=60926
|
||||||
|
@ -66,7 +66,7 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
|
|||||||
$instanceofTags = array();
|
$instanceofTags = array();
|
||||||
|
|
||||||
foreach ($conditionals as $interface => $instanceofDefs) {
|
foreach ($conditionals as $interface => $instanceofDefs) {
|
||||||
if ($interface !== $class && (!$container->getReflectionClass($class))) {
|
if ($interface !== $class && (!$container->getReflectionClass($class, false))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,12 +337,15 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
* Retrieves the requested reflection class and registers it for resource tracking.
|
* Retrieves the requested reflection class and registers it for resource tracking.
|
||||||
*
|
*
|
||||||
* @param string $class
|
* @param string $class
|
||||||
|
* @param bool $throw
|
||||||
*
|
*
|
||||||
* @return \ReflectionClass|null
|
* @return \ReflectionClass|null
|
||||||
*
|
*
|
||||||
|
* @throws \ReflectionException when a parent class/interface/trait is not found and $throw is true
|
||||||
|
*
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
public function getReflectionClass($class)
|
public function getReflectionClass($class, $throw = true)
|
||||||
{
|
{
|
||||||
if (!$class = $this->getParameterBag()->resolveValue($class)) {
|
if (!$class = $this->getParameterBag()->resolveValue($class)) {
|
||||||
return;
|
return;
|
||||||
@ -357,6 +360,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
$classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class);
|
$classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class);
|
||||||
}
|
}
|
||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
|
if ($throw) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
$classReflector = false;
|
$classReflector = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ class AutowirePassTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class does not exist.
|
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.
|
||||||
*/
|
*/
|
||||||
public function testClassNotFoundThrowsException()
|
public function testClassNotFoundThrowsException()
|
||||||
{
|
{
|
||||||
@ -374,7 +374,7 @@ class AutowirePassTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
|
||||||
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class does not exist.
|
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class cannot be loaded.
|
||||||
*/
|
*/
|
||||||
public function testParentClassNotFoundThrowsException()
|
public function testParentClassNotFoundThrowsException()
|
||||||
{
|
{
|
||||||
@ -744,7 +744,7 @@ class AutowirePassTest extends TestCase
|
|||||||
public function provideNotWireableCalls()
|
public function provideNotWireableCalls()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class does not exist.'),
|
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.'),
|
||||||
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
|
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
|
||||||
array(null, 'Cannot autowire service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
|
array(null, 'Cannot autowire service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
|
||||||
);
|
);
|
||||||
|
@ -122,8 +122,14 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
|
|||||||
return $targetUrl;
|
return $targetUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && parse_url($targetUrl, PHP_URL_PATH) !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
|
if ($this->options['use_referer']) {
|
||||||
return $targetUrl;
|
$targetUrl = $request->headers->get('Referer');
|
||||||
|
if (false !== $pos = strpos($targetUrl, '?')) {
|
||||||
|
$targetUrl = substr($targetUrl, 0, $pos);
|
||||||
|
}
|
||||||
|
if ($targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
|
||||||
|
return $targetUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->options['default_target_path'];
|
return $this->options['default_target_path'];
|
||||||
|
@ -12,193 +12,92 @@
|
|||||||
namespace Symfony\Component\Security\Http\Tests\Authentication;
|
namespace Symfony\Component\Security\Http\Tests\Authentication;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
|
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
|
||||||
|
use Symfony\Component\Security\Http\HttpUtils;
|
||||||
|
|
||||||
class DefaultAuthenticationSuccessHandlerTest extends TestCase
|
class DefaultAuthenticationSuccessHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
private $httpUtils = null;
|
/**
|
||||||
|
* @dataProvider getRequestRedirections
|
||||||
private $request = null;
|
*/
|
||||||
|
public function testRequestRedirections(Request $request, $options, $redirectedUrl)
|
||||||
private $token = null;
|
|
||||||
|
|
||||||
protected function setUp()
|
|
||||||
{
|
{
|
||||||
$this->httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
|
$urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock();
|
||||||
$this->request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
|
$urlGenerator->expects($this->any())->method('generate')->will($this->returnValue('http://localhost/login'));
|
||||||
$this->request->headers = $this->getMockBuilder('Symfony\Component\HttpFoundation\HeaderBag')->getMock();
|
$httpUtils = new HttpUtils($urlGenerator);
|
||||||
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
|
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
|
||||||
|
$handler = new DefaultAuthenticationSuccessHandler($httpUtils, $options);
|
||||||
|
if ($request->hasSession()) {
|
||||||
|
$handler->setProviderKey('admin');
|
||||||
|
}
|
||||||
|
$this->assertSame('http://localhost'.$redirectedUrl, $handler->onAuthenticationSuccess($request, $token)->getTargetUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequestIsRedirected()
|
public function getRequestRedirections()
|
||||||
{
|
|
||||||
$response = $this->expectRedirectResponse('/');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefaultTargetPathCanBeForced()
|
|
||||||
{
|
|
||||||
$options = array(
|
|
||||||
'always_use_default_target_path' => true,
|
|
||||||
'default_target_path' => '/dashboard',
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->expectRedirectResponse('/dashboard');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testTargetPathIsPassedWithRequest()
|
|
||||||
{
|
|
||||||
$this->request->expects($this->once())
|
|
||||||
->method('get')->with('_target_path')
|
|
||||||
->will($this->returnValue('/dashboard'));
|
|
||||||
|
|
||||||
$response = $this->expectRedirectResponse('/dashboard');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testTargetPathIsPassedAsNestedParameterWithRequest()
|
|
||||||
{
|
|
||||||
$this->request->expects($this->once())
|
|
||||||
->method('get')->with('_target_path')
|
|
||||||
->will($this->returnValue(array('value' => '/dashboard')));
|
|
||||||
|
|
||||||
$response = $this->expectRedirectResponse('/dashboard');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array('target_path_parameter' => '_target_path[value]'));
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testTargetPathParameterIsCustomised()
|
|
||||||
{
|
|
||||||
$options = array('target_path_parameter' => '_my_target_path');
|
|
||||||
|
|
||||||
$this->request->expects($this->once())
|
|
||||||
->method('get')->with('_my_target_path')
|
|
||||||
->will($this->returnValue('/dashboard'));
|
|
||||||
|
|
||||||
$response = $this->expectRedirectResponse('/dashboard');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testTargetPathIsTakenFromTheSession()
|
|
||||||
{
|
{
|
||||||
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
|
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
|
||||||
$session->expects($this->once())
|
$session->expects($this->once())->method('get')->with('_security.admin.target_path')->will($this->returnValue('/admin/dashboard'));
|
||||||
->method('get')->with('_security.admin.target_path')
|
$session->expects($this->once())->method('remove')->with('_security.admin.target_path');
|
||||||
->will($this->returnValue('/admin/dashboard'));
|
$requestWithSession = Request::create('/');
|
||||||
$session->expects($this->once())
|
$requestWithSession->setSession($session);
|
||||||
->method('remove')->with('_security.admin.target_path');
|
|
||||||
|
|
||||||
$this->request->expects($this->any())
|
return array(
|
||||||
->method('getSession')
|
'default' => array(
|
||||||
->will($this->returnValue($session));
|
Request::create('/'),
|
||||||
|
array(),
|
||||||
$response = $this->expectRedirectResponse('/admin/dashboard');
|
'/',
|
||||||
|
),
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
|
'forced target path' => array(
|
||||||
$handler->setProviderKey('admin');
|
Request::create('/'),
|
||||||
|
array('always_use_default_target_path' => true, 'default_target_path' => '/dashboard'),
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
'/dashboard',
|
||||||
|
),
|
||||||
$this->assertSame($response, $result);
|
'target path as query string' => array(
|
||||||
}
|
Request::create('/?_target_path=/dashboard'),
|
||||||
|
array(),
|
||||||
public function testTargetPathIsPassedAsReferer()
|
'/dashboard',
|
||||||
{
|
),
|
||||||
$options = array('use_referer' => true);
|
'target path name as query string is customized' => array(
|
||||||
|
Request::create('/?_my_target_path=/dashboard'),
|
||||||
$this->request->headers->expects($this->once())
|
array('target_path_parameter' => '_my_target_path'),
|
||||||
->method('get')->with('Referer')
|
'/dashboard',
|
||||||
->will($this->returnValue('/dashboard'));
|
),
|
||||||
|
'target path name as query string is customized and nested' => array(
|
||||||
$response = $this->expectRedirectResponse('/dashboard');
|
Request::create('/?_target_path[value]=/dashboard'),
|
||||||
|
array('target_path_parameter' => '_target_path[value]'),
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
|
'/dashboard',
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
),
|
||||||
|
'target path in session' => array(
|
||||||
$this->assertSame($response, $result);
|
$requestWithSession,
|
||||||
}
|
array(),
|
||||||
|
'/admin/dashboard',
|
||||||
public function testRefererHasToBeDifferentThanLoginUrl()
|
),
|
||||||
{
|
'target path as referer' => array(
|
||||||
$options = array('use_referer' => true);
|
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')),
|
||||||
|
array('use_referer' => true),
|
||||||
$this->request->headers->expects($this->any())
|
'/dashboard',
|
||||||
->method('get')->with('Referer')
|
),
|
||||||
->will($this->returnValue('/login'));
|
'target path as referer is ignored if not configured' => array(
|
||||||
|
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/dashboard')),
|
||||||
$this->httpUtils->expects($this->once())
|
array(),
|
||||||
->method('generateUri')->with($this->request, '/login')
|
'/',
|
||||||
->will($this->returnValue('/login'));
|
),
|
||||||
|
'target path should be different than login URL' => array(
|
||||||
$response = $this->expectRedirectResponse('/');
|
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')),
|
||||||
|
array('use_referer' => true, 'login_path' => '/login'),
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
|
'/',
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
),
|
||||||
|
'target path should be different than login URL (query string does not matter)' => array(
|
||||||
$this->assertSame($response, $result);
|
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')),
|
||||||
}
|
array('use_referer' => true, 'login_path' => '/login'),
|
||||||
|
'/',
|
||||||
public function testRefererWithoutParametersHasToBeDifferentThanLoginUrl()
|
),
|
||||||
{
|
'target path should be different than login URL (login_path as a route)' => array(
|
||||||
$options = array('use_referer' => true);
|
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login?t=1&p=2')),
|
||||||
|
array('use_referer' => true, 'login_path' => 'login_route'),
|
||||||
$this->request->headers->expects($this->any())
|
'/',
|
||||||
->method('get')->with('Referer')
|
),
|
||||||
->will($this->returnValue('/subfolder/login?t=1&p=2'));
|
);
|
||||||
|
|
||||||
$this->httpUtils->expects($this->once())
|
|
||||||
->method('generateUri')->with($this->request, '/login')
|
|
||||||
->will($this->returnValue('/subfolder/login'));
|
|
||||||
|
|
||||||
$response = $this->expectRedirectResponse('/');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRefererTargetPathIsIgnoredByDefault()
|
|
||||||
{
|
|
||||||
$this->request->headers->expects($this->never())->method('get');
|
|
||||||
|
|
||||||
$response = $this->expectRedirectResponse('/');
|
|
||||||
|
|
||||||
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
|
|
||||||
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
|
|
||||||
|
|
||||||
$this->assertSame($response, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function expectRedirectResponse($path)
|
|
||||||
{
|
|
||||||
$response = new Response();
|
|
||||||
$this->httpUtils->expects($this->once())
|
|
||||||
->method('createRedirectResponse')
|
|
||||||
->with($this->request, $path)
|
|
||||||
->will($this->returnValue($response));
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
|
|||||||
{
|
{
|
||||||
$this->flags = (int) $flags;
|
$this->flags = (int) $flags;
|
||||||
$this->setCharset($charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8');
|
$this->setCharset($charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8');
|
||||||
$this->decimalPoint = (string) 0.5;
|
$this->decimalPoint = localeconv();
|
||||||
$this->decimalPoint = $this->decimalPoint[1];
|
$this->decimalPoint = $this->decimalPoint['decimal_point'];
|
||||||
$this->setOutput($output ?: static::$defaultOutput);
|
$this->setOutput($output ?: static::$defaultOutput);
|
||||||
if (!$output && is_string(static::$defaultOutput)) {
|
if (!$output && is_string(static::$defaultOutput)) {
|
||||||
static::$defaultOutput = $this->outputStream;
|
static::$defaultOutput = $this->outputStream;
|
||||||
@ -123,6 +123,13 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
|
|||||||
*/
|
*/
|
||||||
public function dump(Data $data, $output = null)
|
public function dump(Data $data, $output = null)
|
||||||
{
|
{
|
||||||
|
$this->decimalPoint = localeconv();
|
||||||
|
$this->decimalPoint = $this->decimalPoint['decimal_point'];
|
||||||
|
|
||||||
|
if ($locale = $this->flags & (self::DUMP_COMMA_SEPARATOR | self::DUMP_TRAILING_COMMA) ? setlocale(LC_NUMERIC, 0) : null) {
|
||||||
|
setlocale(LC_NUMERIC, 'C');
|
||||||
|
}
|
||||||
|
|
||||||
if ($returnDump = true === $output) {
|
if ($returnDump = true === $output) {
|
||||||
$output = fopen('php://memory', 'r+b');
|
$output = fopen('php://memory', 'r+b');
|
||||||
}
|
}
|
||||||
@ -143,6 +150,9 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
|
|||||||
if ($output) {
|
if ($output) {
|
||||||
$this->setOutput($prevOutput);
|
$this->setOutput($prevOutput);
|
||||||
}
|
}
|
||||||
|
if ($locale) {
|
||||||
|
setlocale(LC_NUMERIC, $locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user