@@ -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,23 +65,32 @@ 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 );
79
- } catch (\Exception $ e ) {
82
+ $ exists [0 ] = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
83
+ } catch (\Throwable $ e ) {
84
+ $ exists [1 ] = $ e ->getMessage ();
85
+
86
+ if (!$ e instanceof \Exception) {
87
+ throw $ e ;
88
+ }
89
+
80
90
try {
81
91
self ::throwOnRequiredClass ($ this ->resource , $ e );
82
92
} catch (\ReflectionException $ e ) {
83
93
if (0 >= $ timestamp ) {
84
- unset(self ::$ existsCache [1 ][$ this ->resource ]);
85
94
throw $ e ;
86
95
}
87
96
}
@@ -97,7 +106,7 @@ public function isFresh($timestamp)
97
106
$ this ->exists = $ exists ;
98
107
}
99
108
100
- return $ this ->exists xor !$ exists ;
109
+ return $ this ->exists [ 0 ] xor !$ exists[ 0 ] ;
101
110
}
102
111
103
112
/**
@@ -118,6 +127,10 @@ public function serialize()
118
127
public function unserialize ($ serialized )
119
128
{
120
129
list ($ this ->resource , $ this ->exists ) = unserialize ($ serialized );
130
+
131
+ if (\is_bool ($ this ->exists )) {
132
+ $ this ->exists = [$ this ->exists , null ];
133
+ }
121
134
}
122
135
123
136
/**
@@ -155,7 +168,17 @@ public static function throwOnRequiredClass($class, \Exception $previous = null)
155
168
throw $ previous ;
156
169
}
157
170
158
- $ e = new \ReflectionException (sprintf ('Class "%s" not found while loading "%s". ' , $ class , self ::$ autoloadedClass ), 0 , $ previous );
171
+ $ message = sprintf ('Class "%s" not found. ' , $ class );
172
+
173
+ if (self ::$ autoloadedClass !== $ class ) {
174
+ $ message = substr_replace ($ message , sprintf (' while loading "%s" ' , self ::$ autoloadedClass ), -1 , 0 );
175
+ }
176
+
177
+ if (null !== $ previous ) {
178
+ $ message = $ previous ->getMessage ();
179
+ }
180
+
181
+ $ e = new \ReflectionException ($ message , 0 , $ previous );
159
182
160
183
if (null !== $ previous ) {
161
184
throw $ e ;
0 commit comments