This commit is contained in:
2021-02-23 14:16:08 +08:00
parent 8de7e6cfbc
commit 9e6ac6d92d
8 changed files with 275 additions and 279 deletions
+29 -6
View File
@@ -212,24 +212,47 @@ class Annotation extends Component
return [];
}
$name = get_class($object) . '_' . $method->getName();
if (!isset($this->_annotations[$alias])) {
$this->_annotations[$alias] = [];
}
if (!isset($this->_annotations[$alias][$name])) {
$this->_annotations[$alias][$name] = [];
}
$array = [];
foreach ($attributes as $attribute) {
/** @var IAnnotation $class */
$class = $this->instance($attribute);
if ($class === null) {
continue;
}
$class->execute([$object, $method->getName()]);
$array[] = $class->execute([$object, $method->getName()]);
}
// $tmp['handler'] = [$object, $method->getName()];
// $tmp['attributes'] = $names;
//
// $this->_annotations[$alias][] = $tmp;
$this->_annotations[$alias][$name][] = $array;
return [];
}
/**
* @param $class
* @param $method
* @param string $alias
* @return array|mixed
*/
public function getAnnotationByMethod($class, $method, $alias = '')
{
if (!isset($this->_annotations[$alias])) {
return [];
}
if (is_object($class)) {
$class = get_class($class);
}
return $this->_annotations[$alias][$class . '_' . $method] ?? [];
}
/**
* @param $className
* @param string $method
+1 -7
View File
@@ -34,16 +34,10 @@ use Snowflake\Snowflake;
/**
* @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;
return $this;
}
+1 -7
View File
@@ -34,16 +34,10 @@ use Snowflake\Snowflake;
/**
* @param array $handler
* @return array|string
* @throws ReflectionException
* @throws NotFindClassException
*/
public function execute(array $handler): array|string
{
// TODO: Implement execute() method.
foreach ($this->interceptor as $key => $item) {
$this->interceptor[$key] = [Snowflake::createObject($item), 'Interceptor'];
}
return $this->interceptor;
return $this;
}
}
+1 -7
View File
@@ -34,16 +34,10 @@ use Snowflake\Snowflake;
/**
* @param array $handler
* @return array|string
* @throws ReflectionException
* @throws NotFindClassException
*/
public function execute(array $handler): array|string
{
// TODO: Implement execute() method.
foreach ($this->limits as $key => $item) {
$this->limits[$key] = [Snowflake::createObject($item), 'next'];
}
return $this->limits;
return $this;
}
+1 -7
View File
@@ -35,16 +35,10 @@ use Snowflake\Snowflake;
/**
* @param array $handler
* @return array|string
* @throws ReflectionException
* @throws NotFindClassException
*/
public function execute(array $handler): array|string
{
// TODO: Implement execute() method.
foreach ($this->middleware as $key => $item) {
$this->middleware[$key] = [Snowflake::createObject($item), 'onHandler'];
}
return $this->middleware;
return $this;
}
-1
View File
@@ -40,7 +40,6 @@ use Annotation\IAnnotation;
// TODO: Implement setHandler() method.
$router = Snowflake::app()->getRouter();
var_dump($this->uri, $handler, $this->method);
$router->addRoute($this->uri, $handler, $this->method);
return $router;
+2 -7
View File
@@ -72,15 +72,11 @@ class Middleware
}
[$controller, $action] = $node->handler;
$attributes = Snowflake::app()->getAttributes();
$annotation = $attributes->getByClass(get_class($controller), $action);
$annotation = $attributes->getAnnotationByMethod($controller, $action, 'controllers');
if (count($annotation) < 1) {
return;
}
foreach ($annotation as $item) {
if (empty($item) || !isset($item['attributes'])) {
continue;
}
foreach ($item['attributes'] as $attribute) {
foreach ($annotation as $attribute) {
if ($attribute instanceof Interceptor) {
$node->addInterceptor($attribute->interceptor);
}
@@ -95,7 +91,6 @@ class Middleware
}
}
}
}
/**
+3
View File
@@ -447,6 +447,9 @@ class Node extends HttpService
if (empty($this->handler)) {
return $this;
}
if (!is_array($this->handler)) {
return $this;
}
/** @var Middleware $made */
$made = Snowflake::createObject(Middleware::class);
$made->getGenerate($this);