Files
kiri-core/http-server/Route/Annotation/Annotation.php
T

97 lines
1.6 KiB
PHP
Raw Normal View History

2020-08-31 22:33:50 +08:00
<?php
namespace HttpServer\Route\Annotation;
2020-09-01 03:11:34 +08:00
use ReflectionClass;
2020-08-31 22:33:50 +08:00
use ReflectionException;
use Snowflake\Abstracts\BaseAnnotation;
use Snowflake\Snowflake;
/**
* Class Annotation
*/
class Annotation extends \Snowflake\Annotation\Annotation
{
const HTTP_EVENT = 'http:event:';
2020-09-02 11:38:47 +08:00
const CLOSE = 'Close';
2020-08-31 22:33:50 +08:00
/**
* @var string
* @Interceptor(LoginInterceptor)
*/
private $Interceptor = 'required|not empty';
/**
* @var string
*/
private $Limits = 'required|not empty';
protected $_annotations = [];
2020-09-01 03:11:34 +08:00
/**
* @param ReflectionClass $reflect
* @param $method
* @param $annotations
* @return mixed|null
* @throws ReflectionException
*/
public function read($reflect, $method, $annotations)
{
$method = $reflect->getMethod($method);
$_annotations = $this->getDocCommentAnnotation($annotations, $method->getDocComment());
$array = [];
foreach ($_annotations as $keyName => $annotation) {
if (!in_array($keyName, $annotations)) {
continue;
}
$array[$keyName] = $this->pop($this->getName(...$annotation));
}
return $array;
}
/**
* @param $controller
* @param $methodName
* @param $events
* @return array|void
* @throws
*/
public function createHandler($controller, $methodName, $events)
{
return Snowflake::createObject($events[2]);
}
2020-08-31 22:33:50 +08:00
/**
* @param $events
* @return bool
*/
public function isLegitimate($events)
{
return isset($events[2]) && !empty($events[2]);
}
/**
* @param $name
* @param $events
* @return false|string
*/
public function getName($name, $events)
{
return self::HTTP_EVENT . $name . ':' . $events[2];
}
}