This commit is contained in:
2020-09-01 03:11:34 +08:00
parent ae753bc267
commit 689c2556e6
8 changed files with 194 additions and 191 deletions
@@ -3,6 +3,7 @@
namespace HttpServer\Route\Annotation;
use ReflectionClass;
use ReflectionException;
use Snowflake\Abstracts\BaseAnnotation;
use Snowflake\Snowflake;
@@ -30,6 +31,47 @@ class Annotation extends \Snowflake\Annotation\Annotation
protected $_annotations = [];
/**
* @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]);
}
/**
* @param $events
* @return bool
@@ -0,0 +1,64 @@
<?php
namespace HttpServer\Route\Annotation;
use Snowflake\Annotation\Annotation;
/**
* Class Websocket
* @package Snowflake\Annotation
*/
class Websocket extends Annotation
{
const MESSAGE = 'Message:';
const HANDSHAKE = 'Handshake:';
const CLOSE = 'Close:';
private $Message = 'required|not empty';
private $Handshake;
private $Close;
/**
* @param $controller
* @param $methodName
* @param $events
* @return array
*/
public function createHandler($controller, $methodName, $events)
{
return [$controller, $methodName];
}
/**
* @param $events
* @return bool|void
*/
public function isLegitimate($events)
{
return true;
}
/**
* @param $events
* @param $comment
* @return false|string
*/
public function getName($events, $comment)
{
$prefix = 'WEBSOCKET:ANNOTATION:' . $events;
if (isset($comment[2])) {
return $prefix . ':' . $comment[2];
}
return $prefix;
}
}