From a63ab776247cb76ee0c0fec9c37f6a09d2ee0b61 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 2 Aug 2017 07:57:29 +0200 Subject: [PATCH] [Config] Fix checking class existence freshness --- .../Config/Resource/ClassExistenceResource.php | 7 ++++++- .../Config/Tests/Fixtures/BadParent.php | 7 +++++++ .../Resource/ClassExistenceResourceTest.php | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Config/Tests/Fixtures/BadParent.php diff --git a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php index 623124ab8d98..e3fd095b6008 100644 --- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php @@ -65,7 +65,7 @@ public function isFresh($timestamp) { $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 @@ public function isFresh($timestamp) 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) { diff --git a/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php b/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php new file mode 100644 index 000000000000..68d7296ed869 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php @@ -0,0 +1,7 @@ +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);