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 | * constructor |
||
29 | * @param string アプリケーションルートパス |
||
30 | */ |
||
31 | public function __construct(string $applicationRoot) |
||
32 | { |
||
33 | $this->logger = new class() { function __call($name, $args) {} }; |
||
36 | |||
37 | /** |
||
38 | * クラスをロードする |
||
39 | * @param mixed クラスまたはクラスリスト |
||
40 | * @return array<string> ロード済みクラスリスト |
||
41 | */ |
||
42 | 7 | public function load($target): array |
|
46 | |||
47 | /** |
||
48 | * ファイルをインポートする |
||
49 | * @param string ファイルパス |
||
50 | * @param callable フィルタリング無名関数 trueを返すとインポート |
||
51 | * @return bool インポート結果 |
||
52 | */ |
||
53 | 3 | public function import($filepath, callable $filter = null): bool |
|
69 | |||
70 | /** |
||
71 | * 指定ディレクトリのファイルをインポートする |
||
72 | * @param string ディレクトリパス |
||
73 | * @param callable フィルタリング無名関数 trueを返すとインポート |
||
74 | * @return bool インポート結果 |
||
75 | */ |
||
76 | 3 | public function importAll($dirPath, callable $filter = null): bool |
|
77 | { |
||
78 | 3 | $dir = new File($this->applicationRoot . "/" . $dirPath); |
|
79 | 3 | $isSuccess = true; |
|
80 | 3 | if ($dir->isDirectory()) { |
|
81 | 3 | $iterator = $this->getFileSearchIterator($dir->getFilePath()); |
|
82 | 3 | foreach ($iterator as $filepath => $fileObject) { |
|
83 | 3 | if (preg_match("/(?:\/\.|\/\.\.|\.DS_Store)$/", $filepath)) { |
|
84 | 3 | continue; |
|
85 | } |
||
86 | 3 | $file = new File($filepath); |
|
87 | 3 | if ($file->isFile()) { |
|
88 | 3 | if ($file->getFileExtension() === 'php') { |
|
89 | 3 | if ($filter === null || (is_callable($filter) && $filter($file->getFilePath()) === true)) { |
|
90 | 2 | include_once $file->getFilePath(); |
|
91 | 3 | $this->logger->debug($file->getFilePath() . " import success."); |
|
92 | } |
||
93 | } |
||
94 | } else { |
||
95 | $this->logger->warn($filepath . " import failure."); |
||
96 | 3 | $isSuccess = false; |
|
97 | } |
||
98 | } |
||
99 | } |
||
100 | |||
101 | 3 | return $isSuccess; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * ロード可能なクラスを返却する |
||
106 | * @param string クラス名(フルパス指定の場合はクラスパス) |
||
107 | * @return array<string> ロード可能クラス |
||
108 | */ |
||
109 | 7 | private function loadClass(string $className): array |
|
145 | |||
146 | /** |
||
147 | * ロード可能なクラスを複数返却する |
||
148 | * @param array クラス名 |
||
149 | * @return array<string> ロード済みクラスリスト |
||
150 | */ |
||
151 | private function loadClassList(array $classList): array |
||
152 | { |
||
153 | $includedlist = []; |
||
154 | foreach ($classList as $className) { |
||
155 | $result = $this->loadClass($className); |
||
156 | if (is_array($result)) { |
||
157 | $includedlist = array_merge($includedlist, $result); |
||
158 | } |
||
159 | } |
||
160 | |||
161 | return $includedlist; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * ファイル検索イテレータを返却する |
||
166 | * @param string ディレクトリパス |
||
167 | * @return RecursiveIteratorIterator イテレータ |
||
168 | */ |
||
169 | private function getFileSearchIterator(string $path): \RecursiveIteratorIterator |
||
182 | } |
||
183 |
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..