1 | <?php |
||
14 | class ClassLoader |
||
15 | { |
||
16 | use Injector; |
||
17 | |||
18 | /** |
||
19 | * @var Psr\Log\LoggerInterface |
||
20 | */ |
||
21 | private $logger; |
||
22 | |||
23 | /** |
||
24 | * @var string アプリケーションルートパス |
||
25 | */ |
||
26 | private $applicationRoot; |
||
27 | |||
28 | /** |
||
29 | * constructor |
||
30 | * @param string アプリケーションルートパス |
||
31 | */ |
||
32 | public function __construct(string $applicationRoot) |
||
33 | { |
||
34 | $this->logger = new class() { function __call($name, $args) {} }; |
||
37 | |||
38 | /** |
||
39 | * クラスをロードする |
||
40 | * @param mixed クラスまたはクラスリスト |
||
41 | * @return array<string> ロード済みクラスリスト |
||
42 | */ |
||
43 | 7 | public function load($target): array |
|
47 | |||
48 | /** |
||
49 | * ファイルをインポートする |
||
50 | * @param string ファイルパス |
||
51 | * @param callable フィルタリング無名関数 trueを返すとインポート |
||
52 | * @return bool インポート結果 |
||
53 | */ |
||
54 | 3 | public function import($filepath, callable $filter = null): bool |
|
70 | |||
71 | /** |
||
72 | * 指定ディレクトリのファイルをインポートする |
||
73 | * @param string ディレクトリパス |
||
74 | * @param callable フィルタリング無名関数 trueを返すとインポート |
||
75 | * @return bool インポート結果 |
||
76 | */ |
||
77 | 3 | public function importAll($dirPath, callable $filter = null): bool |
|
104 | |||
105 | /** |
||
106 | * 名前空間リストを返却する |
||
107 | * @param string ファイル名 |
||
108 | * @return array<string> 名前空間リスト |
||
109 | */ |
||
110 | 3 | public function getNamespaces($fileName) |
|
139 | |||
140 | /** |
||
141 | * ロード可能なクラスを返却する |
||
142 | * @param string クラス名(フルパス指定の場合はクラスパス) |
||
143 | * @return array<string> ロード可能クラス |
||
144 | */ |
||
145 | 7 | private function loadClass(string $className): array |
|
146 | { |
||
147 | 7 | $rootDir = $this->applicationRoot; |
|
148 | 7 | $logger = $this->logger; |
|
149 | |||
150 | // 名前空間セパレータをパスセパレータに置換 |
||
151 | 7 | if (DIRECTORY_SEPARATOR === '/') { |
|
152 | 7 | $className = str_replace("\\", DIRECTORY_SEPARATOR, $className); |
|
153 | } |
||
154 | |||
155 | 7 | $search = function ($dirPath, $searchFilePath) use ($logger) { |
|
156 | 7 | $includeList = []; |
|
157 | 7 | $dir = new File($dirPath); |
|
158 | 7 | if (!$dir->isDirectory()) { |
|
159 | 1 | $logger->error("Invalid search directory path: " . $dir->getFilePath()); |
|
160 | 1 | return $includeList; |
|
161 | } |
||
162 | 6 | $iterator = $this->getFileSearchIterator($dir->getFilePath()); |
|
163 | 6 | foreach ($iterator as $filepath => $fileObject) { |
|
164 | 6 | if (!$fileObject->isFile()) { |
|
165 | 6 | continue; |
|
166 | } |
||
167 | 6 | if (strpos($filepath, $searchFilePath) !== false) { |
|
168 | 5 | $file = new File($filepath); |
|
169 | 5 | $absoluteFilePath = $file->getAbsoluteFilePath(); |
|
170 | 5 | include_once $absoluteFilePath; |
|
171 | 5 | $includeList[] = $absoluteFilePath; |
|
172 | 6 | $logger->debug($absoluteFilePath . " load success. (search from " . $dir->getFilePath()); |
|
173 | } |
||
174 | } |
||
175 | |||
176 | 6 | return $includeList; |
|
177 | 7 | }; |
|
178 | |||
179 | return $search("${rootDir}", DIRECTORY_SEPARATOR . "${className}.php"); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * ロード可能なクラスを複数返却する |
||
184 | * @param array クラス名 |
||
185 | * @return array<string> ロード済みクラスリスト |
||
186 | */ |
||
187 | private function loadClassList(array $classList): array |
||
199 | |||
200 | /** |
||
201 | * ファイル検索イテレータを返却する |
||
202 | * @param string ディレクトリパス |
||
203 | * @return RecursiveIteratorIterator イテレータ |
||
204 | */ |
||
205 | private function getFileSearchIterator(string $path): \RecursiveIteratorIterator |
||
218 | } |
||
219 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..