Files
kiri-router/src/Annotate/AutoController.php
T

32 lines
607 B
PHP
Raw Normal View History

2023-04-15 23:29:27 +08:00
<?php
2023-04-16 01:24:30 +08:00
declare(strict_types=1);
2023-04-15 23:29:27 +08:00
2023-04-16 20:36:47 +08:00
namespace Kiri\Router\Annotate;
2023-04-15 23:29:27 +08:00
2023-07-25 10:09:06 +08:00
use ReflectionException;
2023-04-15 23:29:27 +08:00
#[\Attribute(\Attribute::TARGET_CLASS)]
2023-04-16 17:15:34 +08:00
class AutoController
2023-04-15 23:29:27 +08:00
{
2023-04-16 16:51:24 +08:00
/**
2023-07-25 10:09:06 +08:00
* @throws ReflectionException
2023-04-16 16:51:24 +08:00
*/
public function dispatch(object $object): void
{
$reflection = \Kiri::getDi()->getReflectionClass($object::class);
foreach ($reflection->getMethods() as $method) {
$attributes = $method->getAttributes();
foreach ($attributes as $attribute) {
2023-04-16 23:38:32 +08:00
if (!class_exists($attribute->getName())) {
continue;
}
2023-04-16 16:51:24 +08:00
$attribute->newInstance()->dispatch($object, $method->getName());
}
}
}
2023-04-15 23:29:27 +08:00
}