This commit is contained in:
2023-08-03 14:08:16 +08:00
parent 3611b87817
commit 0a171da047
2 changed files with 17 additions and 15 deletions
+4 -14
View File
@@ -100,25 +100,15 @@ class Container implements ContainerInterface
/** /**
* @param string $id * @param string $id
* @return void * @return object
* @throws ReflectionException * @throws ReflectionException
*/ */
public function parse(string $id): void public function parse(string $id): object
{ {
if (isset($this->_singletons[$id])) { if (isset($this->_singletons[$id])) {
return; return $this->_singletons[$id];
}
$object = $this->make($id);
$methods = $this->getReflectionClass($id);
foreach ($methods->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if ($method->isStatic() || $method->getDeclaringClass()->getName() != $id) {
continue;
}
$attributes = $method->getAttributes();
foreach ($attributes as $attribute) {
$attribute->newInstance()->dispatch($object, $method->getName());
}
} }
return $this->make($id);
} }
+13 -1
View File
@@ -9,6 +9,7 @@ use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Di\Inject\Skip; use Kiri\Di\Inject\Skip;
use ReflectionException; use ReflectionException;
use ReflectionMethod;
class Scanner extends Component class Scanner extends Component
{ {
@@ -51,7 +52,18 @@ class Scanner extends Component
if (count($data) > 0) { if (count($data) > 0) {
continue; continue;
} }
$container->parse($class); $object = $container->parse($class);
$methods = $container->getReflectionClass($class);
foreach ($methods->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if ($method->isStatic() || $method->getDeclaringClass()->getName() != $class) {
continue;
}
$attributes = $method->getAttributes();
foreach ($attributes as $attribute) {
$attribute->newInstance()->dispatch($object, $method->getName());
}
}
} }
} }
} }