This commit is contained in:
2021-03-04 10:19:56 +08:00
parent 51c34d1488
commit 6180cc3125
3 changed files with 38 additions and 2 deletions
+25
View File
@@ -10,6 +10,7 @@ use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
use Snowflake\Abstracts\BaseObject;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
use Throwable;
@@ -119,6 +120,7 @@ class Loader extends BaseObject
/**
* @param DirectoryIterator $paths
* @param $namespace
* @throws ComponentException
*/
public function _scanDir(DirectoryIterator $paths, $namespace)
{
@@ -199,6 +201,29 @@ class Loader extends BaseObject
}
/**
* @param string $path
*/
public function loadByDirectory(string $path)
{
foreach ($this->_fileMap as $value) {
if (!str_starts_with($value, $path)) {
continue;
}
$annotations = $this->getClassByFilepath($path);
foreach ($annotations['methods'] as $name => $attribute) {
foreach ($attribute as $value) {
if (!($value instanceof \Annotation\Attribute)) {
continue;
}
$value->execute([$annotations['handler'], $name]);
}
}
}
}
/**
* @param DirectoryIterator $path
* @param string $namespace