mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-20 15:15:35 +08:00
add cs fixer and PHPStan and activate it (build 436)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation;
|
||||
|
||||
|
||||
use Closure;
|
||||
|
||||
abstract class AnnotationBase
|
||||
@@ -12,18 +12,27 @@ abstract class AnnotationBase
|
||||
|
||||
public $class;
|
||||
|
||||
public function __toString() {
|
||||
$str = __CLASS__ . ": ";
|
||||
public function __toString()
|
||||
{
|
||||
$str = __CLASS__ . ': ';
|
||||
foreach ($this as $k => $v) {
|
||||
$str .= "\n\t" . $k . " => ";
|
||||
if (is_string($v)) $str .= "\"$v\"";
|
||||
elseif (is_numeric($v)) $str .= $v;
|
||||
elseif (is_bool($v)) $str .= ($v ? "TRUE" : "FALSE");
|
||||
elseif (is_array($v)) $str .= json_encode($v, JSON_UNESCAPED_UNICODE);
|
||||
elseif ($v instanceof Closure) $str .= "@AnonymousFunction";
|
||||
elseif (is_null($v)) $str .= "NULL";
|
||||
else $str .= "@Unknown";
|
||||
$str .= "\n\t" . $k . ' => ';
|
||||
if (is_string($v)) {
|
||||
$str .= "\"{$v}\"";
|
||||
} elseif (is_numeric($v)) {
|
||||
$str .= $v;
|
||||
} elseif (is_bool($v)) {
|
||||
$str .= ($v ? 'TRUE' : 'FALSE');
|
||||
} elseif (is_array($v)) {
|
||||
$str .= json_encode($v, JSON_UNESCAPED_UNICODE);
|
||||
} elseif ($v instanceof Closure) {
|
||||
$str .= '@AnonymousFunction';
|
||||
} elseif (is_null($v)) {
|
||||
$str .= 'NULL';
|
||||
} else {
|
||||
$str .= '@Unknown';
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use ZM\Annotation\CQ\CQCommand;
|
||||
use ZM\Annotation\Interfaces\ErgodicAnnotation;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionMethod;
|
||||
@@ -17,8 +14,11 @@ use ZM\Annotation\Http\HandleException;
|
||||
use ZM\Annotation\Http\Middleware;
|
||||
use ZM\Annotation\Http\MiddlewareClass;
|
||||
use ZM\Annotation\Http\RequestMapping;
|
||||
use ZM\Annotation\Interfaces\ErgodicAnnotation;
|
||||
use ZM\Annotation\Interfaces\Level;
|
||||
use ZM\Annotation\Module\Closed;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\AnnotationException;
|
||||
use ZM\Utils\Manager\RouteManager;
|
||||
use ZM\Utils\ZMUtil;
|
||||
@@ -30,23 +30,27 @@ class AnnotationParser
|
||||
private $start_time;
|
||||
|
||||
private $annotation_map = [];
|
||||
|
||||
private $middleware_map = [];
|
||||
|
||||
private $middlewares = [];
|
||||
|
||||
/** @var null|AnnotationReader */
|
||||
private $reader = null;
|
||||
private $reader;
|
||||
|
||||
private $req_mapping = [];
|
||||
|
||||
/**
|
||||
* AnnotationParser constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->start_time = microtime(true);
|
||||
//$this->loadAnnotationClasses();
|
||||
$this->req_mapping[0] = [
|
||||
'id' => 0,
|
||||
'pid' => -1,
|
||||
'name' => '/'
|
||||
'name' => '/',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -54,13 +58,14 @@ class AnnotationParser
|
||||
* 注册各个模块类的注解和模块level的排序
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function registerMods() {
|
||||
public function registerMods()
|
||||
{
|
||||
foreach ($this->path_list as $path) {
|
||||
Console::debug("parsing annotation in " . $path[0].":".$path[1]);
|
||||
Console::debug('parsing annotation in ' . $path[0] . ':' . $path[1]);
|
||||
$all_class = ZMUtil::getClassesPsr4($path[0], $path[1]);
|
||||
$this->reader = new AnnotationReader();
|
||||
foreach ($all_class as $v) {
|
||||
Console::debug("正在检索 " . $v);
|
||||
Console::debug('正在检索 ' . $v);
|
||||
$reflection_class = new ReflectionClass($v);
|
||||
$methods = $reflection_class->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
$class_annotations = $this->reader->getClassAnnotations($reflection_class);
|
||||
@@ -85,22 +90,21 @@ class AnnotationParser
|
||||
*/
|
||||
|
||||
// 生成主树
|
||||
$this->annotation_map[$v]["class_annotations"] = $class_annotations;
|
||||
$this->annotation_map[$v]["methods"] = $methods;
|
||||
$this->annotation_map[$v]['class_annotations'] = $class_annotations;
|
||||
$this->annotation_map[$v]['methods'] = $methods;
|
||||
foreach ($methods as $method) {
|
||||
$this->annotation_map[$v]["methods_annotations"][$method->getName()] = $this->reader->getMethodAnnotations($method);
|
||||
$this->annotation_map[$v]['methods_annotations'][$method->getName()] = $this->reader->getMethodAnnotations($method);
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->annotation_map[$v]["class_annotations"] as $vs) {
|
||||
foreach ($this->annotation_map[$v]['class_annotations'] as $vs) {
|
||||
$vs->class = $v;
|
||||
|
||||
//预处理1:将适用于每一个函数的注解到类注解重新注解到每个函数下面
|
||||
if ($vs instanceof ErgodicAnnotation) {
|
||||
foreach (($this->annotation_map[$v]["methods"] ?? []) as $method) {
|
||||
foreach (($this->annotation_map[$v]['methods'] ?? []) as $method) {
|
||||
$copy = clone $vs;
|
||||
$copy->method = $method->getName();
|
||||
$this->annotation_map[$v]["methods_annotations"][$method->getName()][] = $copy;
|
||||
$this->annotation_map[$v]['methods_annotations'][$method->getName()][] = $copy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,23 +112,24 @@ class AnnotationParser
|
||||
if ($vs instanceof Closed) {
|
||||
unset($this->annotation_map[$v]);
|
||||
continue 2;
|
||||
} elseif ($vs instanceof MiddlewareClass) {
|
||||
}
|
||||
if ($vs instanceof MiddlewareClass) {
|
||||
//注册中间件本身的类,标记到 middlewares 属性中
|
||||
Console::debug("正在注册中间件 " . $reflection_class->getName());
|
||||
Console::debug('正在注册中间件 ' . $reflection_class->getName());
|
||||
$rs = $this->registerMiddleware($vs, $reflection_class);
|
||||
$this->middlewares[$rs["name"]] = $rs;
|
||||
$this->middlewares[$rs['name']] = $rs;
|
||||
}
|
||||
}
|
||||
|
||||
$inserted = [];
|
||||
|
||||
//预处理3:处理每个函数上面的特殊注解,就是需要操作一些东西的
|
||||
foreach (($this->annotation_map[$v]["methods_annotations"] ?? []) as $method_name => $methods_annotations) {
|
||||
foreach (($this->annotation_map[$v]['methods_annotations'] ?? []) as $method_name => $methods_annotations) {
|
||||
foreach ($methods_annotations as $method_anno) {
|
||||
/** @var AnnotationBase $method_anno */
|
||||
/* @var AnnotationBase $method_anno */
|
||||
$method_anno->class = $v;
|
||||
$method_anno->method = $method_name;
|
||||
if (!($method_anno instanceof Middleware) && ($middlewares = ZMConfig::get("global", "runtime")["global_middleware_binding"][get_class($method_anno)] ?? []) !== []) {
|
||||
if (!($method_anno instanceof Middleware) && ($middlewares = ZMConfig::get('global', 'runtime')['global_middleware_binding'][get_class($method_anno)] ?? []) !== []) {
|
||||
if (!isset($inserted[$v][$method_name])) {
|
||||
// 在这里在其他中间件前插入插入全局的中间件
|
||||
foreach ($middlewares as $middleware) {
|
||||
@@ -146,23 +151,25 @@ class AnnotationParser
|
||||
}
|
||||
}
|
||||
}
|
||||
Console::debug("解析注解完毕!");
|
||||
Console::debug('解析注解完毕!');
|
||||
}
|
||||
|
||||
public function generateAnnotationEvents(): array {
|
||||
public function generateAnnotationEvents(): array
|
||||
{
|
||||
$o = [];
|
||||
foreach ($this->annotation_map as $obj) {
|
||||
// 这里的ErgodicAnnotation是为了解决类上的注解可穿透到方法上的问题
|
||||
foreach (($obj["class_annotations"] ?? []) as $class_annotation) {
|
||||
if ($class_annotation instanceof ErgodicAnnotation) continue;
|
||||
else $o[get_class($class_annotation)][] = $class_annotation;
|
||||
foreach (($obj['class_annotations'] ?? []) as $class_annotation) {
|
||||
if ($class_annotation instanceof ErgodicAnnotation) {
|
||||
continue;
|
||||
}
|
||||
$o[get_class($class_annotation)][] = $class_annotation;
|
||||
}
|
||||
foreach (($obj["methods_annotations"] ?? []) as $methods_annotations) {
|
||||
foreach (($obj['methods_annotations'] ?? []) as $methods_annotations) {
|
||||
foreach ($methods_annotations as $annotation) {
|
||||
$o[get_class($annotation)][] = $annotation;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($o as $k => $v) {
|
||||
$this->sortByLevel($o, $k);
|
||||
@@ -170,55 +177,36 @@ class AnnotationParser
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMiddlewares(): array { return $this->middlewares; }
|
||||
public function getMiddlewares(): array
|
||||
{
|
||||
return $this->middlewares;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMiddlewareMap(): array { return $this->middleware_map; }
|
||||
public function getMiddlewareMap(): array
|
||||
{
|
||||
return $this->middleware_map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getReqMapping(): array { return $this->req_mapping; }
|
||||
public function getReqMapping(): array
|
||||
{
|
||||
return $this->req_mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $indoor_name
|
||||
*/
|
||||
public function addRegisterPath($path, $indoor_name) { $this->path_list[] = [$path, $indoor_name]; }
|
||||
|
||||
//private function below
|
||||
|
||||
private function registerMiddleware(MiddlewareClass $vs, ReflectionClass $reflection_class): array {
|
||||
$result = [
|
||||
"class" => "\\" . $reflection_class->getName(),
|
||||
"name" => $vs->name
|
||||
];
|
||||
|
||||
foreach ($reflection_class->getMethods() as $vss) {
|
||||
$method_annotations = $this->reader->getMethodAnnotations($vss);
|
||||
foreach ($method_annotations as $vsss) {
|
||||
if ($vsss instanceof HandleBefore) $result["before"] = $vss->getName();
|
||||
if ($vsss instanceof HandleAfter) $result["after"] = $vss->getName();
|
||||
if ($vsss instanceof HandleException) {
|
||||
$result["exceptions"][$vsss->class_name] = $vss->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
public function addRegisterPath($path, $indoor_name)
|
||||
{
|
||||
$this->path_list[] = [$path, $indoor_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal 用于 level 排序
|
||||
* @param $events
|
||||
* @param string $class_name
|
||||
* @param string $prefix
|
||||
* @internal 用于 level 排序
|
||||
*/
|
||||
public function sortByLevel(&$events, string $class_name, $prefix = "") {
|
||||
public function sortByLevel(&$events, string $class_name, string $prefix = '')
|
||||
{
|
||||
if (is_a($class_name, Level::class, true)) {
|
||||
$class_name .= $prefix;
|
||||
usort($events[$class_name], function ($a, $b) {
|
||||
@@ -232,12 +220,13 @@ class AnnotationParser
|
||||
/**
|
||||
* @throws AnnotationException
|
||||
*/
|
||||
public function verifyMiddlewares() {
|
||||
if ((ZMConfig::get("global", "runtime")["middleware_error_policy"] ?? 1) === 2) {
|
||||
public function verifyMiddlewares()
|
||||
{
|
||||
if ((ZMConfig::get('global', 'runtime')['middleware_error_policy'] ?? 1) === 2) {
|
||||
//我承认套三层foreach很不优雅,但是这个会很快的。
|
||||
foreach($this->middleware_map as $class => $v) {
|
||||
foreach ($v as $method => $vs) {
|
||||
foreach($vs as $mid) {
|
||||
foreach ($this->middleware_map as $v) {
|
||||
foreach ($v as $vs) {
|
||||
foreach ($vs as $mid) {
|
||||
if (!isset($this->middlewares[$mid->middleware])) {
|
||||
throw new AnnotationException("Annotation parse error: Unknown MiddlewareClass named \"{$mid->middleware}\"!");
|
||||
}
|
||||
@@ -246,4 +235,35 @@ class AnnotationParser
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getRunTime()
|
||||
{
|
||||
return microtime(true) - $this->start_time;
|
||||
}
|
||||
|
||||
//private function below
|
||||
|
||||
private function registerMiddleware(MiddlewareClass $vs, ReflectionClass $reflection_class): array
|
||||
{
|
||||
$result = [
|
||||
'class' => '\\' . $reflection_class->getName(),
|
||||
'name' => $vs->name,
|
||||
];
|
||||
|
||||
foreach ($reflection_class->getMethods() as $vss) {
|
||||
$method_annotations = $this->reader->getMethodAnnotations($vss);
|
||||
foreach ($method_annotations as $vsss) {
|
||||
if ($vsss instanceof HandleBefore) {
|
||||
$result['before'] = $vss->getName();
|
||||
}
|
||||
if ($vsss instanceof HandleAfter) {
|
||||
$result['after'] = $vss->getName();
|
||||
}
|
||||
if ($vsss instanceof HandleException) {
|
||||
$result['exceptions'][$vsss->class_name] = $vss->getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class CQAPIResponse
|
||||
* @package ZM\Annotation\CQ
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
@@ -11,7 +12,6 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQAfter
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQAfter extends AnnotationBase implements Level
|
||||
{
|
||||
@@ -26,14 +26,16 @@ class CQAfter extends AnnotationBase implements Level
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLevel() {
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $level
|
||||
*/
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
@@ -13,7 +13,6 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQBefore
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQBefore extends AnnotationBase implements Level
|
||||
{
|
||||
@@ -28,15 +27,16 @@ class CQBefore extends AnnotationBase implements Level
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLevel(): int {
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $level
|
||||
*/
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
@@ -11,43 +12,55 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQCommand
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQCommand extends AnnotationBase implements Level
|
||||
{
|
||||
/** @var string */
|
||||
public $match = "";
|
||||
public $match = '';
|
||||
|
||||
/** @var string */
|
||||
public $pattern = "";
|
||||
public $pattern = '';
|
||||
|
||||
/** @var string */
|
||||
public $regex = "";
|
||||
public $regex = '';
|
||||
|
||||
/** @var string */
|
||||
public $start_with = "";
|
||||
public $start_with = '';
|
||||
|
||||
/** @var string */
|
||||
public $end_with = "";
|
||||
public $end_with = '';
|
||||
|
||||
/** @var string */
|
||||
public $keyword = "";
|
||||
public $keyword = '';
|
||||
|
||||
/** @var string[] */
|
||||
public $alias = [];
|
||||
|
||||
/** @var string */
|
||||
public $message_type = "";
|
||||
public $message_type = '';
|
||||
|
||||
/** @var int */
|
||||
public $user_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $group_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $discuss_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $level = 20;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel(): int { return $this->level; }
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level) { $this->level = $level; }
|
||||
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
@@ -11,30 +12,39 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQMessage
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQMessage extends AnnotationBase implements Level
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $message_type = "";
|
||||
public $message_type = '';
|
||||
|
||||
/** @var int */
|
||||
public $user_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $group_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $discuss_id = 0;
|
||||
|
||||
/** @var string */
|
||||
public $message = "";
|
||||
public $message = '';
|
||||
|
||||
/** @var string */
|
||||
public $raw_message = "";
|
||||
public $raw_message = '';
|
||||
|
||||
/** @var int */
|
||||
public $level = 20;
|
||||
|
||||
public function getLevel(): int { return $this->level; }
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
@@ -12,7 +13,6 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQMetaEvent
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQMetaEvent extends AnnotationBase implements Level
|
||||
{
|
||||
@@ -21,18 +21,23 @@ class CQMetaEvent extends AnnotationBase implements Level
|
||||
* @Required()
|
||||
*/
|
||||
public $meta_event_type = '';
|
||||
|
||||
/** @var int */
|
||||
public $level;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLevel(): int { return $this->level; }
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
@@ -11,32 +12,34 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQNotice
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQNotice extends AnnotationBase implements Level
|
||||
{
|
||||
/** @var string */
|
||||
public $notice_type = "";
|
||||
public $notice_type = '';
|
||||
|
||||
/** @var string */
|
||||
public $sub_type = "";
|
||||
public $sub_type = '';
|
||||
|
||||
/** @var int */
|
||||
public $group_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $operator_id = 0;
|
||||
|
||||
/** @var int */
|
||||
public $level = 20;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel(): int {
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\CQ;
|
||||
|
||||
@@ -11,32 +12,34 @@ use ZM\Annotation\Interfaces\Level;
|
||||
* Class CQRequest
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
* @package ZM\Annotation\CQ
|
||||
*/
|
||||
class CQRequest extends AnnotationBase implements Level
|
||||
{
|
||||
/** @var string */
|
||||
public $request_type = "";
|
||||
public $request_type = '';
|
||||
|
||||
/** @var string */
|
||||
public $sub_type = "";
|
||||
public $sub_type = '';
|
||||
|
||||
/** @var int */
|
||||
public $user_id = 0;
|
||||
|
||||
/** @var string */
|
||||
public $comment = "";
|
||||
public $comment = '';
|
||||
|
||||
/** @var int */
|
||||
public $level = 20;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel(): int {
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Command;
|
||||
|
||||
@@ -9,7 +10,6 @@ use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class TerminalCommand
|
||||
* @package ZM\Annotation\Command
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
@@ -26,5 +26,5 @@ class TerminalCommand extends AnnotationBase
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $description = "";
|
||||
}
|
||||
public $description = '';
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
@@ -12,7 +13,6 @@ use ZM\Annotation\Interfaces\ErgodicAnnotation;
|
||||
* Class Controller
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
* @package ZM\Annotation\Http
|
||||
*/
|
||||
class Controller extends AnnotationBase implements ErgodicAnnotation
|
||||
{
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class HandleAfter
|
||||
* @package ZM\Annotation\Http
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class HandleBefore
|
||||
* @package ZM\Annotation\Http
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use Exception;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class HandleException
|
||||
* @package ZM\Annotation\Http
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
@@ -20,4 +19,4 @@ class HandleException extends AnnotationBase
|
||||
* @var string
|
||||
*/
|
||||
public $class_name = Exception::class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
@@ -11,7 +11,6 @@ use ZM\Annotation\Interfaces\ErgodicAnnotation;
|
||||
|
||||
/**
|
||||
* Class Middleware
|
||||
* @package ZM\Annotation\Http
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class MiddlewareClass
|
||||
* @package ZM\Annotation\Http
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
@@ -11,7 +12,6 @@ use ZM\Annotation\AnnotationBase;
|
||||
* Class RequestMapping
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @package ZM\Annotation\Http
|
||||
*/
|
||||
class RequestMapping extends AnnotationBase
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Http;
|
||||
|
||||
@@ -9,21 +10,26 @@ use ZM\Annotation\AnnotationBase;
|
||||
/**
|
||||
* Class RequestMethod
|
||||
* @Annotation
|
||||
* @package ZM\Annotation\Http
|
||||
*/
|
||||
class RequestMethod extends AnnotationBase
|
||||
{
|
||||
public const GET = 'GET';
|
||||
|
||||
public const POST = 'POST';
|
||||
|
||||
public const PUT = 'PUT';
|
||||
|
||||
public const PATCH = 'PATCH';
|
||||
|
||||
public const DELETE = 'DELETE';
|
||||
|
||||
public const OPTIONS = 'OPTIONS';
|
||||
|
||||
public const HEAD = 'HEAD';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @Required()
|
||||
*/
|
||||
public $method = self::GET;
|
||||
|
||||
public const GET = 'GET';
|
||||
public const POST = 'POST';
|
||||
public const PUT = 'PUT';
|
||||
public const PATCH = 'PATCH';
|
||||
public const DELETE = 'DELETE';
|
||||
public const OPTIONS = 'OPTIONS';
|
||||
public const HEAD = 'HEAD';
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Interfaces;
|
||||
|
||||
|
||||
interface CustomAnnotation
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Interfaces;
|
||||
|
||||
|
||||
interface ErgodicAnnotation
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Interfaces;
|
||||
|
||||
|
||||
interface Level
|
||||
{
|
||||
public function getLevel();
|
||||
|
||||
public function setLevel($level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Interfaces;
|
||||
|
||||
|
||||
interface Rule
|
||||
{
|
||||
public function getRule();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Module;
|
||||
|
||||
@@ -10,9 +11,7 @@ use ZM\Annotation\AnnotationBase;
|
||||
* Class Closed
|
||||
* @Annotation
|
||||
* @Target("CLASS")
|
||||
* @package ZM\Annotation\Module
|
||||
*/
|
||||
class Closed extends AnnotationBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* Class OnCloseEvent
|
||||
* @package ZM\Annotation\Swoole
|
||||
*/
|
||||
class OnCloseEvent extends OnSwooleEventBase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $connect_type = "default";
|
||||
}
|
||||
public $connect_type = 'default';
|
||||
}
|
||||
|
||||
16
src/ZM/Annotation/Swoole/OnManagerStartEvent.php
Normal file
16
src/ZM/Annotation/Swoole/OnManagerStartEvent.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @since 2.7.0
|
||||
*/
|
||||
class OnManagerStartEvent extends OnSwooleEventBase
|
||||
{
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* Class OnMessageEvent
|
||||
* @package ZM\Annotation\Swoole
|
||||
*/
|
||||
class OnMessageEvent extends OnSwooleEventBase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $connect_type = "default";
|
||||
}
|
||||
public $connect_type = 'default';
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* Class OnOpenEvent
|
||||
* @package ZM\Annotation\Swoole
|
||||
*/
|
||||
class OnOpenEvent extends OnSwooleEventBase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $connect_type = "default";
|
||||
}
|
||||
public $connect_type = 'default';
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class OnPipeMessageEvent
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
@@ -21,4 +20,4 @@ class OnPipeMessageEvent extends AnnotationBase
|
||||
* @Required()
|
||||
*/
|
||||
public $action;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* Class OnRequestEvent
|
||||
* @package ZM\Annotation\Swoole
|
||||
*/
|
||||
class OnRequestEvent extends OnSwooleEventBase
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
@@ -8,11 +9,9 @@ use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class OnSave
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
class OnSave extends AnnotationBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class ZMSetup
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
@@ -8,7 +9,6 @@ use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class OnWorkerStart
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
@@ -10,7 +11,6 @@ use Doctrine\Common\Annotations\Annotation\Target;
|
||||
* Class OnSwooleEvent
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @package ZM\Annotation\Swoole
|
||||
*/
|
||||
class OnSwooleEvent extends OnSwooleEventBase
|
||||
{
|
||||
@@ -20,17 +20,13 @@ class OnSwooleEvent extends OnSwooleEventBase
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string {
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType(string $type) {
|
||||
public function setType(string $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
use ZM\Annotation\Interfaces\Level;
|
||||
use ZM\Annotation\Interfaces\Rule;
|
||||
@@ -13,37 +13,33 @@ abstract class OnSwooleEventBase extends AnnotationBase implements Level, Rule
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $rule = "";
|
||||
public $rule = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $level = 20;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRule(): string {
|
||||
return $this->rule !== "" ? $this->rule : true;
|
||||
public function getRule()
|
||||
{
|
||||
return $this->rule !== '' ? $this->rule : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rule
|
||||
*/
|
||||
public function setRule(string $rule) {
|
||||
public function setRule(string $rule)
|
||||
{
|
||||
$this->rule = $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel(): int {
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level) {
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
@@ -10,7 +11,6 @@ use ZM\Annotation\Interfaces\Rule;
|
||||
|
||||
/**
|
||||
* Class OnTask
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
@@ -25,12 +25,13 @@ class OnTask extends AnnotationBase implements Rule
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $rule = "";
|
||||
public $rule = '';
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRule(): string {
|
||||
public function getRule(): string
|
||||
{
|
||||
return $this->rule;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
@@ -7,10 +8,9 @@ use Doctrine\Common\Annotations\Annotation\Target;
|
||||
|
||||
/**
|
||||
* Class OnTaskEvent
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
*/
|
||||
class OnTaskEvent extends OnSwooleEventBase
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class OnTick
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("METHOD")
|
||||
* @since 1.2
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Swoole;
|
||||
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation\Required;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use ZM\Annotation\AnnotationBase;
|
||||
|
||||
/**
|
||||
* Class SwooleHandler
|
||||
* @package ZM\Annotation\Swoole
|
||||
* @Annotation
|
||||
* @Target("ALL")
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user