[Config] Fix checking class existence freshness
This commit is contained in:
parent
468b44a031
commit
a63ab77624
@ -65,7 +65,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
||||
{
|
||||
$loaded = class_exists($this->resource, false) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
|
||||
|
||||
if (null !== $exists = &self::$existsCache[$this->resource]) {
|
||||
if (null !== $exists = &self::$existsCache[(int) (0 >= $timestamp)][$this->resource]) {
|
||||
$exists = $exists || $loaded;
|
||||
} elseif (!$exists = $loaded) {
|
||||
if (!self::$autoloadLevel++) {
|
||||
@ -76,6 +76,11 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
||||
|
||||
try {
|
||||
$exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
|
||||
} catch (\ReflectionException $e) {
|
||||
if (0 >= $timestamp) {
|
||||
unset(self::$existsCache[1][$this->resource]);
|
||||
throw $e;
|
||||
}
|
||||
} finally {
|
||||
self::$autoloadedClass = $autoloadedClass;
|
||||
if (!--self::$autoloadLevel) {
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Fixtures;
|
||||
|
||||
class BadParent extends MissingParent
|
||||
{
|
||||
}
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Config\Tests\Resource;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Resource\ClassExistenceResource;
|
||||
use Symfony\Component\Config\Tests\Fixtures\Resource\ConditionalClass;
|
||||
use Symfony\Component\Config\Tests\Fixtures\BadParent;
|
||||
|
||||
class ClassExistenceResourceTest extends TestCase
|
||||
{
|
||||
@ -74,6 +75,22 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
public function testBadParentWithTimestamp()
|
||||
{
|
||||
$res = new ClassExistenceResource(BadParent::class, false);
|
||||
$this->assertTrue($res->isFresh(time()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \ReflectionException
|
||||
* @expectedExceptionMessage Class Symfony\Component\Config\Tests\Fixtures\MissingParent not found
|
||||
*/
|
||||
public function testBadParentWithNoTimestamp()
|
||||
{
|
||||
$res = new ClassExistenceResource(BadParent::class, false);
|
||||
$res->isFresh(0);
|
||||
}
|
||||
|
||||
public function testConditionalClass()
|
||||
{
|
||||
$res = new ClassExistenceResource(ConditionalClass::class, false);
|
||||
|
Reference in New Issue
Block a user