bug #23755 [Config] Fix checking class existence freshness (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Config] Fix checking class existence freshness

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23753
| License       | MIT
| Doc PR        | -

Commits
-------

a63ab77 [Config] Fix checking class existence freshness
This commit is contained in:
Maxime Steinhausser 2017-08-02 16:01:26 +02:00
commit b98a4a39c2
3 changed files with 30 additions and 1 deletions

View File

@ -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) {

View File

@ -0,0 +1,7 @@
<?php
namespace Symfony\Component\Config\Tests\Fixtures;
class BadParent extends MissingParent
{
}

View File

@ -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);