1 | <?php |
||
13 | class ClassLoader |
||
14 | { |
||
15 | use Injector; |
||
16 | |||
17 | /** |
||
18 | * @var Psr\Log\LoggerInterface |
||
19 | */ |
||
20 | private $logger; |
||
21 | |||
22 | /** |
||
23 | * @var string アプリケーションルートパス |
||
24 | */ |
||
25 | private $applicationRoot; |
||
26 | |||
27 | /** |
||
28 | * @var array<string> サブディレクトリパスリスト |
||
29 | */ |
||
30 | private $subDirectoryPathList; |
||
31 | |||
32 | /** |
||
33 | * constructor |
||
34 | * @param string アプリケーションルートパス |
||
35 | * @param array<string> サブディレクトリパスリスト |
||
36 | */ |
||
37 | public function __construct(string $applicationRoot, $subDirectoryPathList = []) |
||
38 | { |
||
39 | $this->logger = new class() { function __call($name, $args) {} }; |
||
43 | |||
44 | /** |
||
45 | * クラスをロードする |
||
46 | * @param mixed クラスまたはクラスリスト |
||
47 | * @return array<string> ロード済みクラスリスト |
||
48 | */ |
||
49 | 8 | public function load($target): array |
|
53 | |||
54 | /** |
||
55 | * ファイルをインポートする |
||
56 | * @param string ファイルパス |
||
57 | * @param callable フィルタリング無名関数 trueを返すとインポート |
||
58 | * @return bool インポート結果 |
||
59 | */ |
||
60 | 4 | public function import($filepath, callable $filter = null): bool |
|
61 | { |
||
62 | 4 | $file = new File($this->applicationRoot . "/" . $filepath); |
|
63 | 4 | if ($file->isFile()) { |
|
64 | 3 | if ($file->getFileExtension() === 'php') { |
|
65 | 3 | if ($filter === null || (is_callable($filter) && $filter($file->getFilePath()) === true)) { |
|
66 | 2 | include_once $file->getFilePath(); |
|
67 | 2 | $this->logger->debug($file->getFilePath() . " import success."); |
|
68 | } |
||
69 | } |
||
70 | |||
71 | 3 | return true; |
|
72 | } |
||
73 | |||
74 | 1 | return false; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * 指定ディレクトリのファイルをインポートする |
||
79 | * @param string ディレクトリパス |
||
80 | * @param callable フィルタリング無名関数 trueを返すとインポート |
||
81 | * @return bool インポート結果 |
||
82 | */ |
||
83 | 3 | public function importAll($dirPath, callable $filter = null): bool |
|
110 | |||
111 | /** |
||
112 | * ロード可能なクラスを返却する |
||
113 | * @param string クラス名(フルパス指定の場合はクラスパス) |
||
114 | * @return array<string> ロード可能クラス |
||
115 | */ |
||
116 | 8 | private function loadClass(string $className): array |
|
167 | |||
168 | /** |
||
169 | * ロード可能なクラスを複数返却する |
||
170 | * @param array クラス名 |
||
171 | * @return array<string> ロード済みクラスリスト |
||
172 | */ |
||
173 | private function loadClassList(array $classList): array |
||
174 | { |
||
175 | 1 | $includedlist = []; |
|
176 | 1 | foreach ($classList as $className) { |
|
177 | 1 | $result = $this->loadClass($className); |
|
178 | 1 | if (is_array($result)) { |
|
179 | 1 | $includedlist = array_merge($includedlist, $result); |
|
180 | } |
||
181 | } |
||
182 | |||
183 | 1 | return $includedlist; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * ファイル検索イテレータを返却する |
||
188 | * @param string ディレクトリパス |
||
189 | * @return RecursiveIteratorIterator イテレータ |
||
190 | */ |
||
191 | private function getFileSearchIterator(string $path): \RecursiveIteratorIterator |
||
204 | } |
||
205 |
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..