@@ -36,7 +36,7 @@ public function __construct($resource, $exists = null)
36
36
{
37
37
$ this ->resource = $ resource ;
38
38
if (null !== $ exists ) {
39
- $ this ->exists = (bool ) $ exists ;
39
+ $ this ->exists = [ (bool ) $ exists, null ] ;
40
40
}
41
41
}
42
42
@@ -65,26 +65,33 @@ public function isFresh($timestamp)
65
65
{
66
66
$ loaded = class_exists ($ this ->resource , false ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
67
67
68
- if (null !== $ exists = &self ::$ existsCache [(int ) (0 >= $ timestamp )][$ this ->resource ]) {
69
- $ exists = $ exists || $ loaded ;
70
- } elseif (!$ exists = $ loaded ) {
68
+ if (null !== $ exists = &self ::$ existsCache [$ this ->resource ]) {
69
+ if ($ loaded ) {
70
+ $ exists = [true , null ];
71
+ } elseif (0 >= $ timestamp && !$ exists [0 ] && null !== $ exists [1 ]) {
72
+ throw new \ReflectionException ($ exists [1 ]);
73
+ }
74
+ } elseif ([false , null ] === $ exists = [$ loaded , null ]) {
71
75
if (!self ::$ autoloadLevel ++) {
72
76
spl_autoload_register (__CLASS__ .'::throwOnRequiredClass ' );
73
77
}
74
78
$ autoloadedClass = self ::$ autoloadedClass ;
75
79
self ::$ autoloadedClass = ltrim ($ this ->resource , '\\' );
76
80
77
81
try {
78
- $ exists = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
82
+ $ exists[ 0 ] = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
79
83
} catch (\Exception $ e ) {
84
+ $ exists [1 ] = $ e ->getMessage ();
85
+
80
86
try {
81
87
self ::throwOnRequiredClass ($ this ->resource , $ e );
82
88
} catch (\ReflectionException $ e ) {
83
89
if (0 >= $ timestamp ) {
84
- unset(self ::$ existsCache [1 ][$ this ->resource ]);
85
<
10000
code>90 throw $ e ;
86
91
}
87
92
}
93
+ } catch (\Throwable $ e ) {
94
+ $ exists [1 ] = $ e ->getMessage ();
88
95
} finally {
89
96
self ::$ autoloadedClass = $ autoloadedClass ;
90
97
if (!--self ::$ autoloadLevel ) {
@@ -97,7 +104,7 @@ public function isFresh($timestamp)
97
104
$ this ->exists = $ exists ;
98
105
}
99
106
100
- return $ this ->exists xor !$ exists ;
107
+ return $ this ->exists [ 0 ] xor !$ exists[ 0 ] ;
101
108
}
102
109
103
110
/**
@@ -118,6 +125,10 @@ public function serialize()
118
125
public function unserialize ($ serialized )
119
126
{
120
127
list ($ this ->resource , $ this ->exists ) = unserialize ($ serialized );
128
+
129
+ if (\is_bool ($ this ->exists )) {
130
+ $ this ->exists = [$ this ->exists , null ];
131
+ }
121
132
}
122
133
123
134
/**
@@ -155,7 +166,17 @@ public static function throwOnRequiredClass($class, \Exception $previous = null)
155
166
throw $ previous ;
156
167
}
157
168
158
- $ e = new \ReflectionException (sprintf ('Class "%s" not found while loading "%s". ' , $ class , self ::$ autoloadedClass ), 0 , $ previous );
169
+ $ message = sprintf ('Class "%s" not found. ' , $ class );
170
+
171
+ if (self ::$ autoloadedClass !== $ class ) {
172
+ $ message = substr_replace ($ message , sprintf (' while loading "%s" ' , self ::$ autoloadedClass ), -1 , 0 );
173
+ }
174
+
175
+ if (null !== $ previous ) {
176
+ $ message = $ previous ->getMessage ();
177
+ }
178
+
179
+ $ e = new \ReflectionException ($ message , 0 , $ previous );
159
180
160
181
if (null !== $ previous ) {
161
182
throw $ e ;
0 commit comments