Merge branch '2.7' into 2.8
* 2.7: [Config] ConfigCache::isFresh() should return false on __PHP_Incomplete_Class
This commit is contained in:
commit
25fa4a0ddf
@ -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 */
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user