This commit is contained in:
2021-04-19 15:33:44 +08:00
parent 0771848114
commit a6046bb74e
2 changed files with 34 additions and 32 deletions
+3 -3
View File
@@ -86,9 +86,9 @@ class Annotation extends Component
*/ */
public function runtime(string $dir, string|array $outPath = []) public function runtime(string $dir, string|array $outPath = [])
{ {
if (!empty($outPath) && !is_array($outPath)) { // if (!empty($outPath) && !is_array($outPath)) {
$outPath = [$outPath]; // $outPath = [$outPath];
} // }
$this->_loader->loadByDirectory($dir, $outPath); $this->_loader->loadByDirectory($dir, $outPath);
} }
+31 -29
View File
@@ -227,21 +227,23 @@ class Loader extends BaseObject
* @param string|array $outPath * @param string|array $outPath
* @throws Exception * @throws Exception
*/ */
public function loadByDirectory(string $path, string|array $outPath = []) public function loadByDirectory(string $path, string|array $outPath = '')
{ {
try { try {
$path = '/' . trim($path, '/'); // $path = '/' . trim($path, '/');
if (!isset($this->_directory[$path])) { // if (!isset($this->_directory[$path])) {
return; // return;
} // }
foreach ($this->_directory as $key => $_path) { // foreach ($this->_directory as $key => $_path) {
$key = '/' . trim($path, '/'); // $key = '/' . trim($path, '/');
if (!str_starts_with($key, $path)) { // if (!str_starts_with($key, $path)) {
continue; // continue;
} // }
// if (!empty($outPath) && in_array($key, $outPath)) continue; //// if (!empty($outPath) && in_array($key, $outPath)) continue;
$this->execute($_path); // $this->execute($_path);
} // }
$this->each($path, $outPath);
} catch (Throwable $exception) { } catch (Throwable $exception) {
$this->addError($exception, 'throwable'); $this->addError($exception, 'throwable');
} }
@@ -272,24 +274,24 @@ class Loader extends BaseObject
*/ */
public function appendFileToDirectory(string $filePath, string $className) public function appendFileToDirectory(string $filePath, string $className)
{ {
$array = explode('/', $filePath); // $array = explode('/', $filePath);
array_pop($array); // array_pop($array);
$directory = '/' . implode('/', $array);
$this->_directory[$directory][] = $className;
// $directory = $this->splitDirectory($filePath);
// array_pop($directory);
// //
// $tree = null; // $directory = '/' . implode('/', $array);
// foreach ($directory as $value) {
// $tree = $this->getTree($tree, $value);
// }
// //
// if ($tree instanceof FileTree) { // $this->_directory[$directory][] = $className;
// $tree->addFile($className, $filePath);
// } $directory = $this->splitDirectory($filePath);
array_pop($directory);
$tree = null;
foreach ($directory as $value) {
$tree = $this->getTree($tree, $value);
}
if ($tree instanceof FileTree) {
$tree->addFile($className, $filePath);
}
} }