Skip to content

Commit c57fbfe

Browse files
Merge branch '3.4'
* 3.4: (22 commits) use Precise on Travis to keep PHP LDAP support Fix case sensitive sameSite cookie [PropertyInfo] Use rawurlencode to escape PSR-6 keys fix(security): ensure the 'route' index is set before attempting to use it Fix registering lazy command services with autoconfigure enabled Fix the design of the profiler exceptions when there is no message [Config] Minor fix document the TwigRenderer class deprecation [Security] added more tests [Security] fixed default target path when referer contains a query string [Security] simplified tests [Security] refactored tests [WebProfilerBundle][TwigBundle] Fix infinite js loop on exception pages [FrameworkBundle] fix ValidatorCacheWarmer: use serializing ArrayAdapter Change "this" to "that" to avoid confusion [VarDumper] Move locale sniffing to dump() time [VarDumper] Use "C" locale when using "comma" flags [Config] Make ClassExistenceResource throw on invalid parents [DebugBundle] Added min_depth to Configuration [Console] Add a factory command loader for standalone application with lazy-loading needs ...
2 parents 4cc7994 + 11c2b64 commit c57fbfe

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Resource/ClassExistenceResource.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
2525
private $exists;
2626

2727
private static $autoloadLevel = 0;
28+
private static $autoloadedClass;
2829
private static $existsCache = array();
2930

3031
/**
@@ -57,6 +58,8 @@ public function getResource()
5758

5859
/**
5960
* {@inheritdoc}
61+
*
62+
* @throws \ReflectionException when a parent class/interface/trait is not found
6063
*/
6164
public function isFresh($timestamp)
6265
{
@@ -68,12 +71,13 @@ public function isFresh($timestamp)
6871
if (!self::$autoloadLevel++) {
6972
spl_autoload_register(__CLASS__.'::throwOnRequiredClass');
7073
}
74+
$autoloadedClass = self::$autoloadedClass;
75+
self::$autoloadedClass = $this->resource;
7176

7277
try {
7378
$exists = class_exists($this->resource) || interface_exists($this->resource, false) || trait_exists($this->resource, false);
74-
} catch (\ReflectionException $e) {
75-
$exists = false;
7679
} finally {
80+
self::$autoloadedClass = $autoloadedClass;
7781
if (!--self::$autoloadLevel) {
7882
spl_autoload_unregister(__CLASS__.'::throwOnRequiredClass');
7983
}
@@ -112,7 +116,10 @@ public function unserialize($serialized)
112116
*/
113117
private static function throwOnRequiredClass($class)
114118
{
115-
$e = new \ReflectionException("Class $class does not exist");
119+
if (self::$autoloadedClass === $class) {
120+
return;
121+
}
122+
$e = new \ReflectionException("Class $class not found");
116123
$trace = $e->getTrace();
117124
$autoloadFrame = array(
118125
'function' => 'spl_autoload_call',
@@ -138,6 +145,18 @@ private static function throwOnRequiredClass($class)
138145
case 'is_callable':
139146
return;
140147
}
148+
149+
$props = array(
150+
'file' => $trace[$i]['file'],
151+
'line' => $trace[$i]['line'],
152+
'trace' => array_slice($trace, 1 + $i),
153+
);
154+
155+
foreach ($props as $p => $v) {
156+
$r = new \ReflectionProperty('Exception', $p);
157+
$r->setAccessible(true);
158+
$r->setValue($e, $v);
159+
}
141160
}
142161

143162
throw $e;

0 commit comments

Comments
 (0)