2020-12-15 12:24:38 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Annotation\Route;
|
|
|
|
|
|
2020-12-15 18:52:50 +08:00
|
|
|
use HttpServer\IInterface\After;
|
|
|
|
|
use HttpServer\IInterface\Interceptor;
|
|
|
|
|
use HttpServer\IInterface\Limits;
|
|
|
|
|
use HttpServer\IInterface\Middleware;
|
2020-12-15 18:42:54 +08:00
|
|
|
use ReflectionException;
|
|
|
|
|
use Snowflake\Exception\NotFindClassException;
|
|
|
|
|
use Snowflake\Snowflake;
|
2020-12-15 12:24:38 +08:00
|
|
|
|
|
|
|
|
trait Node
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2020-12-15 18:42:54 +08:00
|
|
|
/**
|
|
|
|
|
* @param array $classes
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws ReflectionException
|
|
|
|
|
* @throws NotFindClassException
|
|
|
|
|
*/
|
2021-02-23 14:45:50 +08:00
|
|
|
public function reflectClass(array $classes): array
|
2020-12-15 18:42:54 +08:00
|
|
|
{
|
2021-02-23 14:50:24 +08:00
|
|
|
$array = [];
|
|
|
|
|
foreach ($classes as $class) {
|
|
|
|
|
$object = Snowflake::getDi()->get($class);
|
2020-12-15 18:52:50 +08:00
|
|
|
if ($object instanceof Interceptor) {
|
2021-02-23 14:50:24 +08:00
|
|
|
$array[] = [$object, 'Interceptor'];
|
2020-12-15 18:52:50 +08:00
|
|
|
}
|
|
|
|
|
if ($object instanceof Limits) {
|
2021-02-23 14:50:24 +08:00
|
|
|
$array[] = [$object, 'next'];
|
2020-12-15 18:52:50 +08:00
|
|
|
}
|
|
|
|
|
if ($object instanceof After) {
|
2021-02-23 14:50:24 +08:00
|
|
|
$array[] = [$object, 'onHandler'];
|
2020-12-15 18:52:50 +08:00
|
|
|
}
|
|
|
|
|
if ($object instanceof Middleware) {
|
2021-02-23 14:50:24 +08:00
|
|
|
$array[] = [$object, 'onHandler'];
|
2020-12-15 18:52:50 +08:00
|
|
|
}
|
2020-12-15 18:42:54 +08:00
|
|
|
}
|
2021-02-23 14:50:24 +08:00
|
|
|
return $array;
|
2020-12-15 18:42:54 +08:00
|
|
|
}
|
|
|
|
|
|
2020-12-15 12:24:38 +08:00
|
|
|
}
|