@@ -25,6 +25,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
25
25
private $ exists ;
26
26
27
27
private static $ autoloadLevel = 0 ;
28
+ private static $ autoloadedClass ;
28
29
private static $ existsCache = array ();
29
30
30
31
/**
@@ -57,6 +58,8 @@ public function getResource()
57
58
58
59
/**
59
60
* {@inheritdoc}
61
+ *
62
+ * @throws \ReflectionException when a parent class/interface/trait is not found
60
63
*/
61
64
public function isFresh ($ timestamp )
62
65
{
@@ -68,12 +71,13 @@ public function isFresh($timestamp)
68
71
if (!self ::$ autoloadLevel ++) {
69
72
spl_autoload_register (__CLASS__ .'::throwOnRequiredClass ' );
70
73
}
74
+ $ autoloadedClass = self ::$ autoloadedClass ;
75
+ self ::$ autoloadedClass = $ this ->resource ;
71
76
72
77
try {
73
78
$ exists = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
74
- } catch (\ReflectionException $ e ) {
75
- $ exists = false ;
76
79
} finally {
80
+ self ::$ autoloadedClass = $ autoloadedClass ;
77
81
if (!--self ::$ autoloadLevel ) {
78
82
spl_autoload_unregister (__CLASS__ .'::throwOnRequiredClass ' );
79
83
}
@@ -112,7 +116,10 @@ public function unserialize($serialized)
112
116
*/
113
117
private static function throwOnRequiredClass ($ class )
114
118
{
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 " );
116
123
$ trace = $ e ->getTrace ();
117
124
$ autoloadFrame = array (
118
125
'function ' => 'spl_autoload_call ' ,
@@ -138,6 +145,18 @@ private static function throwOnRequiredClass($class)
138
145
case 'is_callable ' :
139
146
return ;
140
147
}
148
+
149
+ $ props = array (
150
+ 'file ' => $ trace [$ i ]['file ' ],
151
+ 'line ' => $ trace [$ i ]['line ' ],
152
+ 'trace ' => array_slice ($ trace , 0 , 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
+ }
141
160
}
142
161
143
162
throw $ e ;
0 commit comments