@@ -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 , 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+ }
141160 }
142161
143162 throw $ e ;
0 commit comments