File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ protected static function evaluateCondition($condition)
161
161
{
162
162
if (is_string ($ condition )) {
163
163
// Should be extended for functions, extensions???
164
- return class_exists ($ condition );
164
+ return self :: safeClassExists ($ condition );
165
165
} elseif (is_callable ($ condition )) {
166
166
return $ condition ();
167
167
} elseif (is_bool ($ condition )) {
@@ -205,4 +205,25 @@ protected static function instantiateClass($class)
205
205
206
206
throw new ClassInstantiationFailedException ('Could not instantiate class because parameter is neither a callable nor a string ' );
207
207
}
208
+
209
+ /**
210
+ * We want to do a "safe" version of PHP's "class_exists" because Magento has a bug
211
+ * (or they call it a "feature"). Magento is throwing an exception if you do class_exists()
212
+ * on a class that ends with "Factory" and if that file does not exits.
213
+ *
214
+ * This function will catch all potential exceptions and make sure it returns a boolean.
215
+ *
216
+ * @param string $class
217
+ * @param bool $autoload
218
+ *
219
+ * @return bool
220
+ */
221
+ public static function safeClassExists ($ class )
222
+ {
223
+ try {
224
+ return class_exists ($ class );
225
+ } catch (\Exception $ e ) {
226
+ return false ;
227
+ }
228
+ }
208
229
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Http \Discovery \Strategy ;
4
4
5
+ use Http \Discovery \ClassDiscovery ;
5
6
use Http \Discovery \Exception \PuliUnavailableException ;
6
7
use Puli \Discovery \Api \Discovery ;
7
8
use Puli \GeneratedPuliFactory ;
@@ -41,7 +42,7 @@ private static function getPuliFactory()
41
42
42
43
$ puliFactoryClass = PULI_FACTORY_CLASS ;
43
44
44
- if (!class_exists ($ puliFactoryClass )) {
45
+ if (!ClassDiscovery:: safeClassExists ($ puliFactoryClass )) {
45
46
throw new PuliUnavailableException ('Puli Factory class does not exist ' );
46
47
}
47
48
You can’t perform that action at this time.
0 commit comments