@@ -28,8 +28,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
28
28
private $ resource ;
29
29
private $ existsStatus ;
30
30
31
- private static $ checkingLevel = 0 ;
32
- private static $ throwingAutoloader ;
31
+ private static $ autoloadLevel = 0 ;
33
32
private static $ existsCache = array ();
34
33
35
34
/**
@@ -68,21 +67,17 @@ public function isFresh($timestamp)
68
67
if (null !== $ exists = &self ::$ existsCache [$ this ->resource ]) {
69
68
$ exists = $ exists || class_exists ($ this ->resource , false ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
70
69
} elseif (self ::EXISTS_KO_WITH_THROWING_AUTOLOADER === $ this ->existsStatus ) {
71
- if (null === self ::$ throwingAutoloader ) {
72
- $ signalingException = new \ReflectionException ();
73
- self ::$ throwingAutoloader = function () use ($ signalingException ) { throw $ signalingException ; };
74
- }
75
- if (!self ::$ checkingLevel ++) {
76
- spl_autoload_register (self ::$ throwingAutoloader );
70
+ if (!self ::$ autoloadLevel ++) {
71
+ spl_autoload_register ('Symfony\Component\Config\Resource\ClassExistenceResource::throwOnRequiredClass ' );
77
72
}
78
73
79
74
try {
80
75
$ exists = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
81
76
} catch (\ReflectionException $ e ) {
82
77
$ exists = false ;
83
78
} finally {
84
- if (!--self ::$ checkingLevel ) {
85
- spl_autoload_unregister (self :: $ throwingAutoloader );
79
+ if (!--self ::$ autoloadLevel ) {
80
+ spl_autoload_unregister (' Symfony\Component\Config\Resource\ClassExistenceResource::throwOnRequiredClass ' );
86
81
}
87
82
}
88
83
} else {
@@ -115,4 +110,40 @@ public function unserialize($serialized)
115
110
{
116
111
list ($ this ->resource , $ this ->existsStatus ) = unserialize ($ serialized );
117
112
}
113
+
114
+ /**
115
+ * @throws \ReflectionException When $class is not found and is required
116
+ */
117
+ private static function throwOnRequiredClass ($ class )
118
+ {
119
+ $ e = new \ReflectionException ("Class $ class does not exist " );
120
+ $ trace = $ e ->getTrace ();
121
+ $ autoloadFrame = array (
122
+ 'function ' => 'spl_autoload_call ' ,
123
+ 'args ' => array ($ class ),
124
+ );
125
+ $ i = 1 + array_search ($ autoloadFrame , $ trace , true );
126
+
127
+ if (isset ($ trace [$ i ]['function ' ]) && !isset ($ trace [$ i ]['class ' ])) {
128
+ switch ($ trace [$ i ]['function ' ]) {
129
+ case 'get_class_methods ' :
130
+ case 'get_class_vars ' :
131
+ case 'get_parent_class ' :
132
+ case 'is_a ' :
133
+ case 'is_subclass_of ' :
134
+ case 'class_exists ' :
135
+ case 'class_implements ' :
136
+ case 'class_parents ' :
137
+ case 'trait_exists ' :
138
+ case 'defined ' :
139
+ case 'interface_exists ' :
140
+ case 'method_exists ' :
141
+ case 'property_exists ' :
142
+ case 'is_callable ' :
143
+ return ;
144
+ }
145
+ }
146
+
147
+ throw $ e ;
148
+ }
118
149
}
0 commit comments