1 | <?php |
||
24 | class AopComposerLoader |
||
25 | { |
||
26 | /** |
||
27 | * Instance of original autoloader |
||
28 | */ |
||
29 | protected $original; |
||
30 | |||
31 | /** |
||
32 | * AOP kernel options |
||
33 | */ |
||
34 | protected $options = []; |
||
35 | |||
36 | /** |
||
37 | * File enumerator |
||
38 | */ |
||
39 | protected $fileEnumerator; |
||
40 | |||
41 | /** |
||
42 | * Cache state |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | private $cacheState; |
||
47 | |||
48 | /** |
||
49 | * Was initialization successful or not |
||
50 | */ |
||
51 | private static $wasInitialized = false; |
||
52 | |||
53 | /** |
||
54 | * Constructs an wrapper for the composer loader |
||
55 | * |
||
56 | * @param array $options Configuration options |
||
57 | */ |
||
58 | 1 | public function __construct(ClassLoader $original, AspectContainer $container, array $options = []) |
|
80 | |||
81 | /** |
||
82 | * Initialize aspect autoloader and returns status whether initialization was successful or not |
||
83 | * |
||
84 | * Replaces original composer autoloader with wrapper |
||
85 | * |
||
86 | * @param array $options Aspect kernel options |
||
87 | */ |
||
88 | 1 | public static function init(array $options, AspectContainer $container): bool |
|
89 | { |
||
90 | 1 | $loaders = spl_autoload_functions(); |
|
91 | |||
92 | 1 | foreach ($loaders as &$loader) { |
|
93 | 1 | $loaderToUnregister = $loader; |
|
94 | 1 | if (is_array($loader) && ($loader[0] instanceof ClassLoader)) { |
|
|
|||
95 | 1 | $originalLoader = $loader[0]; |
|
96 | // Configure library loader for doctrine annotation loader |
||
97 | AnnotationRegistry::registerLoader(function($class) use ($originalLoader) { |
||
98 | 1 | $originalLoader->loadClass($class); |
|
99 | |||
100 | 1 | return class_exists($class, false); |
|
101 | 1 | }); |
|
102 | 1 | $loader[0] = new AopComposerLoader($loader[0], $container, $options); |
|
103 | 1 | self::$wasInitialized = true; |
|
104 | } |
||
105 | 1 | spl_autoload_unregister($loaderToUnregister); |
|
106 | } |
||
107 | 1 | unset($loader); |
|
108 | |||
109 | 1 | foreach ($loaders as $loader) { |
|
110 | 1 | spl_autoload_register($loader); |
|
111 | } |
||
112 | |||
113 | 1 | return self::$wasInitialized; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * Autoload a class by it's name |
||
118 | */ |
||
119 | 18 | public function loadClass(string $class): void |
|
127 | |||
128 | /** |
||
129 | * Finds either the path to the file where the class is defined, |
||
130 | * or gets the appropriate php://filter stream for the given class. |
||
131 | * |
||
132 | * @return string|false The path/resource if found, false otherwise. |
||
133 | */ |
||
134 | 18 | public function findFile(string $class) |
|
157 | |||
158 | /** |
||
159 | * Whether or not loader was initialized |
||
160 | */ |
||
161 | public static function wasInitialized(): bool |
||
165 | } |
||
166 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.