This commit is contained in:
2021-02-22 17:44:24 +08:00
parent 3b09b9a308
commit 2d1f83cf09
34 changed files with 732 additions and 222 deletions
+21 -15
View File
@@ -4,13 +4,16 @@
namespace Annotation\Route;
use Annotation\IAnnotation;
use ReflectionException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
/**
* Class Interceptor
* @package Annotation\Route
*/
#[\Attribute(\Attribute::TARGET_METHOD)] class After
#[\Attribute(\Attribute::TARGET_METHOD)] class After implements IAnnotation
{
@@ -18,27 +21,30 @@ use Snowflake\Snowflake;
* Interceptor constructor.
* @param \HttpServer\IInterface\After|\HttpServer\IInterface\After[] $after
* @throws
* if ($object instanceof Interceptor) {
$classes[$key] = [$object, 'Interceptor'];
}
if ($object instanceof Limits) {
$classes[$key] = [$object, 'next'];
}
if ($object instanceof After) {
$classes[$key] = [$object, 'onHandler'];
}
if ($object instanceof Middleware) {
$classes[$key] = [$object, 'onHandler'];
}
*/
public function __construct(public string|array $after)
{
if (is_string($this->after)) {
$this->after = [$this->after];
if (!is_string($this->after)) {
return;
}
$this->after = [$this->after];
}
/**
* @param array $handler
* @return array|string
* @throws ReflectionException
* @throws NotFindClassException
*/
public function execute(array $handler): array|string
{
// TODO: Implement execute() method.
foreach ($this->after as $key => $item) {
$this->after[$key] = [Snowflake::createObject($item), 'onHandler'];
}
return $this->after;
}
}