Merge branch '3.1' into 3.2

* 3.1:
  [Config] ConfigCache::isFresh() should return false on __PHP_Incomplete_Class
  mark alias as private during creation
  [Serializer] Remove unused GetSetMethodNormalizer::denormalize
This commit is contained in:
Nicolas Grekas 2016-11-29 12:12:32 +01:00
commit bd5af67f08
4 changed files with 45 additions and 37 deletions

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
use Doctrine\Common\Annotations\Reader;
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
@ -1248,8 +1249,7 @@ class FrameworkExtension extends Extension
}
foreach (array('doctrine', 'psr6', 'redis') as $name) {
if (isset($config[$name = 'default_'.$name.'_provider'])) {
$container->setAlias('cache.'.$name, Compiler\CachePoolPass::getServiceProvider($container, $config[$name]));
$container->getAlias('cache.'.$name)->setPublic(false);
$container->setAlias('cache.'.$name, new Alias(Compiler\CachePoolPass::getServiceProvider($container, $config[$name]), false));
}
}
foreach (array('app', 'system') as $name) {

View File

@ -77,8 +77,37 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
return true;
}
$metadata = $this->getMetaFile();
if (!is_file($metadata)) {
return false;
}
$e = null;
$meta = false;
$time = filemtime($this->file);
$meta = unserialize(file_get_contents($metadata));
$signalingException = new \UnexpectedValueException();
$prevUnserializeHandler = ini_set('unserialize_callback_func', '');
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context) use (&$prevErrorHandler, $signalingException) {
if (E_WARNING === $type && 'Class __PHP_Incomplete_Class has no unserializer' === $msg) {
throw $signalingException;
}
return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false;
});
try {
$meta = unserialize(file_get_contents($metadata));
} catch (\Error $e) {
} catch (\Exception $e) {
}
restore_error_handler();
ini_set('unserialize_callback_func', $prevUnserializeHandler);
if (null !== $e && $e !== $signalingException) {
throw $e;
}
if (false === $meta) {
return false;
}
foreach ($meta as $resource) {
/* @var ResourceInterface $resource */

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Tests;
use Symfony\Component\Config\Tests\Resource\ResourceStub;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\ResourceCheckerConfigCache;
class ResourceCheckerConfigCacheTest extends \PHPUnit_Framework_TestCase
@ -108,6 +109,18 @@ class ResourceCheckerConfigCacheTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($cache->isFresh());
}
public function testCacheIsNotFreshWhenUnserializeFails()
{
$checker = $this->getMock('\Symfony\Component\Config\ResourceCheckerInterface');
$cache = new ResourceCheckerConfigCache($this->cacheFile, array($checker));
$cache->write('foo', array(new FileResource(__FILE__)));
$metaFile = "{$this->cacheFile}.meta";
file_put_contents($metaFile, str_replace('FileResource', 'ClassNotHere', file_get_contents($metaFile)));
$this->assertFalse($cache->isFresh());
}
public function testCacheKeepsContent()
{
$cache = new ResourceCheckerConfigCache($this->cacheFile);

View File

@ -36,40 +36,6 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
{
private static $setterAccessibleCache = array();
/**
* {@inheritdoc}
*
* @throws RuntimeException
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
$allowedAttributes = $this->getAllowedAttributes($class, $context, true);
$normalizedData = $this->prepareForDenormalization($data);
$reflectionClass = new \ReflectionClass($class);
$object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes, $format);
$classMethods = get_class_methods($object);
foreach ($normalizedData as $attribute => $value) {
if ($this->nameConverter) {
$attribute = $this->nameConverter->denormalize($attribute);
}
$allowed = $allowedAttributes === false || in_array($attribute, $allowedAttributes);
$ignored = in_array($attribute, $this->ignoredAttributes);
if ($allowed && !$ignored) {
$setter = 'set'.ucfirst($attribute);
if (in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) {
$object->$setter($value);
}
}
}
return $object;
}
/**
* {@inheritdoc}
*/