add PHP8 Attribute compatibility (build 439, 2.7.0-beta4)

This commit is contained in:
crazywhalecc 2022-03-20 01:53:36 +08:00
parent 12363aebf0
commit c897da29c6
42 changed files with 355 additions and 40 deletions

View File

@ -36,18 +36,20 @@
"ext-json": "*",
"ext-posix": "*",
"doctrine/annotations": "~1.12 || ~1.4.0",
"symfony/polyfill-ctype": "^1.19",
"symfony/polyfill-mbstring": "^1.19",
"symfony/console": "~5.0 || ~4.0 || ~3.0",
"symfony/routing": "~5.0 || ~4.0 || ~3.0",
"zhamao/console": "^1.0",
"zhamao/config": "^1.0",
"zhamao/request": "^1.1",
"zhamao/connection-manager": "^1.0",
"doctrine/dbal": "^2.13.1",
"jelix/version": "^2.0",
"koriym/attributes": "^1.0",
"league/climate": "^3.6",
"psy/psysh": "@stable",
"doctrine/dbal": "^2.13.1"
"symfony/console": "~5.0 || ~4.0 || ~3.0",
"symfony/polyfill-ctype": "^1.19",
"symfony/polyfill-mbstring": "^1.19",
"symfony/polyfill-php80": "^1.16",
"symfony/routing": "~5.0 || ~4.0 || ~3.0",
"zhamao/config": "^1.0",
"zhamao/connection-manager": "^1.0",
"zhamao/console": "^1.0",
"zhamao/request": "^1.1"
},
"suggest": {
"ext-ctype": "Use C/C++ extension instead of polyfill will be more efficient",

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Custom\Annotation;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
use ZM\Annotation\Interfaces\CustomAnnotation;
@ -11,10 +13,17 @@ use ZM\Annotation\Interfaces\CustomAnnotation;
/**
* Class CustomAnnotation
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class Example extends AnnotationBase implements CustomAnnotation
{
/** @var string */
public $str = '';
public function __construct($str = '')
{
$this->str = $str;
}
}

View File

@ -8,9 +8,9 @@ use Closure;
abstract class AnnotationBase
{
public $method;
public $method = '';
public $class;
public $class = '';
public function __toString()
{

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace ZM\Annotation;
use Doctrine\Common\Annotations\AnnotationReader;
use Koriym\Attributes\AttributeReader;
use Koriym\Attributes\DualReader;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
@ -63,13 +65,12 @@ class AnnotationParser
foreach ($this->path_list as $path) {
Console::debug('parsing annotation in ' . $path[0] . ':' . $path[1]);
$all_class = ZMUtil::getClassesPsr4($path[0], $path[1]);
$this->reader = new AnnotationReader();
$this->reader = new DualReader(new AnnotationReader(), new AttributeReader());
foreach ($all_class as $v) {
Console::debug('正在检索 ' . $v);
$reflection_class = new ReflectionClass($v);
$methods = $reflection_class->getMethods(ReflectionMethod::IS_PUBLIC);
$class_annotations = $this->reader->getClassAnnotations($reflection_class);
// 这段为新加的:start
//这里将每个类里面所有的类注解、方法注解通通加到一颗大树上,后期解析
/*
@ -133,8 +134,7 @@ class AnnotationParser
if (!isset($inserted[$v][$method_name])) {
// 在这里在其他中间件前插入插入全局的中间件
foreach ($middlewares as $middleware) {
$mid_class = new Middleware();
$mid_class->middleware = $middleware;
$mid_class = new Middleware($middleware);
$mid_class->class = $v;
$mid_class->method = $method_name;
$this->middleware_map[$v][$method_name][] = $mid_class;

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,8 +13,10 @@ use ZM\Annotation\AnnotationBase;
/**
* Class CQAPIResponse
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class CQAPIResponse extends AnnotationBase
{
/**
@ -20,4 +24,9 @@ class CQAPIResponse extends AnnotationBase
* @Required()
*/
public $retcode;
public function __construct($retcode)
{
$this->retcode = $retcode;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
use ZM\Annotation\Interfaces\Level;
@ -11,8 +13,10 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQAfter
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class CQAfter extends AnnotationBase implements Level
{
/**
@ -23,6 +27,12 @@ class CQAfter extends AnnotationBase implements Level
public $level = 20;
public function __construct($cq_event, $level = 20)
{
$this->cq_event = $cq_event;
$this->level = $level;
}
/**
* @return mixed
*/

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -12,8 +14,10 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQBefore
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class CQBefore extends AnnotationBase implements Level
{
/**
@ -24,6 +28,12 @@ class CQBefore extends AnnotationBase implements Level
public $level = 20;
public function __construct($cq_event, $level = 20)
{
$this->cq_event = $cq_event;
$this->level = $level;
}
/**
* @return mixed
*/

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
use ZM\Annotation\Interfaces\Level;
@ -11,8 +13,10 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQCommand
* @Annotation
* @NamedArgumentConstructor
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class CQCommand extends AnnotationBase implements Level
{
/** @var string */
@ -51,6 +55,22 @@ class CQCommand extends AnnotationBase implements Level
/** @var int */
public $level = 20;
public function __construct($match = '', $pattern = '', $regex = '', $start_with = '', $end_with = '', $keyword = '', $alias = [], $message_type = '', $user_id = 0, $group_id = 0, $discuss_id = 0, $level = 20)
{
$this->match = $match;
$this->pattern = $pattern;
$this->regex = $regex;
$this->start_with = $start_with;
$this->end_with = $end_with;
$this->keyword = $keyword;
$this->alias = $alias;
$this->message_type = $message_type;
$this->user_id = $user_id;
$this->group_id = $group_id;
$this->discuss_id = $discuss_id;
$this->level = $level;
}
public function getLevel(): int
{
return $this->level;

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
use ZM\Annotation\Interfaces\Level;
@ -11,8 +13,10 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQMessage
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class CQMessage extends AnnotationBase implements Level
{
/**
@ -38,6 +42,17 @@ class CQMessage extends AnnotationBase implements Level
/** @var int */
public $level = 20;
public function __construct($message_type = '', $user_id = 0, $group_id = 0, $discuss_id = 0, $message = '', $raw_message = '', $level = 20)
{
$this->message_type = $message_type;
$this->user_id = $user_id;
$this->group_id = $group_id;
$this->discuss_id = $discuss_id;
$this->message = $message;
$this->raw_message = $raw_message;
$this->level = $level;
}
public function getLevel(): int
{
return $this->level;

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -12,18 +14,26 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQMetaEvent
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class CQMetaEvent extends AnnotationBase implements Level
{
/**
* @var string
* @Required()
*/
public $meta_event_type = '';
public $meta_event_type;
/** @var int */
public $level;
public $level = 20;
public function __construct($meta_event_type, $level = 20)
{
$this->meta_event_type = $meta_event_type;
$this->level = $level;
}
/**
* @return mixed

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
use ZM\Annotation\Interfaces\Level;
@ -11,8 +13,10 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQNotice
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class CQNotice extends AnnotationBase implements Level
{
/** @var string */
@ -30,6 +34,15 @@ class CQNotice extends AnnotationBase implements Level
/** @var int */
public $level = 20;
public function __construct($notice_type = '', $sub_type = '', $group_id = 0, $operator_id = 0, $level = 20)
{
$this->notice_type = $notice_type;
$this->sub_type = $sub_type;
$this->group_id = $group_id;
$this->operator_id = $operator_id;
$this->level = $level;
}
public function getLevel(): int
{
return $this->level;

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\CQ;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
use ZM\Annotation\Interfaces\Level;
@ -11,8 +13,10 @@ use ZM\Annotation\Interfaces\Level;
/**
* Class CQRequest
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class CQRequest extends AnnotationBase implements Level
{
/** @var string */
@ -30,6 +34,15 @@ class CQRequest extends AnnotationBase implements Level
/** @var int */
public $level = 20;
public function __construct($request_type = '', $sub_type = '', $user_id = 0, $comment = '', $level = 20)
{
$this->request_type = $request_type;
$this->sub_type = $sub_type;
$this->user_id = $user_id;
$this->comment = $comment;
$this->level = $level;
}
public function getLevel(): int
{
return $this->level;

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Command;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,8 +13,10 @@ use ZM\Annotation\AnnotationBase;
/**
* Class TerminalCommand
* @Annotation
* @NamedArgumentConstructor
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class TerminalCommand extends AnnotationBase
{
/**
@ -27,4 +31,11 @@ class TerminalCommand extends AnnotationBase
* @var string
*/
public $description = '';
public function __construct($command, $alias = '', $description = '')
{
$this->command = $command;
$this->alias = $alias;
$this->description = $description;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -12,8 +14,10 @@ use ZM\Annotation\Interfaces\ErgodicAnnotation;
/**
* Class Controller
* @Annotation
* @NamedArgumentConstructor()
* @Target("CLASS")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class Controller extends AnnotationBase implements ErgodicAnnotation
{
/**
@ -21,4 +25,9 @@ class Controller extends AnnotationBase implements ErgodicAnnotation
* @Required()
*/
public $prefix = '';
public function __construct(string $prefix)
{
$this->prefix = $prefix;
}
}

View File

@ -4,14 +4,18 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class HandleAfter
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class HandleAfter extends AnnotationBase
{
}

View File

@ -4,14 +4,18 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class HandleBefore
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class HandleBefore extends AnnotationBase
{
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use Exception;
use ZM\Annotation\AnnotationBase;
@ -11,12 +13,19 @@ use ZM\Annotation\AnnotationBase;
/**
* Class HandleException
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class HandleException extends AnnotationBase
{
/**
* @var string
*/
public $class_name = Exception::class;
public function __construct($class_name = Exception::class)
{
$this->class_name = $class_name;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -12,8 +14,10 @@ use ZM\Annotation\Interfaces\ErgodicAnnotation;
/**
* Class Middleware
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
class Middleware extends AnnotationBase implements ErgodicAnnotation
{
/**
@ -26,4 +30,10 @@ class Middleware extends AnnotationBase implements ErgodicAnnotation
* @var string[]
*/
public $params = [];
public function __construct($middleware, $params = [])
{
$this->middleware = $middleware;
$this->params = $params;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,8 +13,10 @@ use ZM\Annotation\AnnotationBase;
/**
* Class MiddlewareClass
* @Annotation
* @NamedArgumentConstructor()
* @Target("CLASS")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class MiddlewareClass extends AnnotationBase
{
/**
@ -20,4 +24,9 @@ class MiddlewareClass extends AnnotationBase
* @Required()
*/
public $name = '';
public function __construct($name)
{
$this->name = $name;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,8 +13,10 @@ use ZM\Annotation\AnnotationBase;
/**
* Class RequestMapping
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class RequestMapping extends AnnotationBase
{
/**
@ -36,4 +40,12 @@ class RequestMapping extends AnnotationBase
* @var array
*/
public $params = [];
public function __construct($route, $name = '', $request_method = [RequestMethod::GET, RequestMethod::POST], $params = [])
{
$this->route = $route;
$this->name = $name;
$this->request_method = $request_method;
$this->params = $params;
}
}

View File

@ -4,13 +4,19 @@ declare(strict_types=1);
namespace ZM\Annotation\Http;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class RequestMethod
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class RequestMethod extends AnnotationBase
{
public const GET = 'GET';
@ -32,4 +38,9 @@ class RequestMethod extends AnnotationBase
* @Required()
*/
public $method = self::GET;
public function __construct($method)
{
$this->method = $method;
}
}

View File

@ -4,14 +4,18 @@ declare(strict_types=1);
namespace ZM\Annotation\Module;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class Closed
* @Annotation
* @NamedArgumentConstructor()
* @Target("CLASS")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class Closed extends AnnotationBase
{
}

View File

@ -4,17 +4,28 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
* Class OnCloseEvent
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnCloseEvent extends OnSwooleEventBase
{
/**
* @var string
*/
public $connect_type = 'default';
public function __construct($connect_type = 'default', $rule = '', $level = 20)
{
$this->connect_type = $connect_type;
$this->rule = $rule;
$this->level = $level;
}
}

View File

@ -4,13 +4,22 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
* @since 2.7.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnManagerStartEvent extends OnSwooleEventBase
{
public function __construct($rule = '', $level = 20)
{
$this->rule = $rule;
$this->level = $level;
}
}

View File

@ -4,17 +4,28 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target("METHOD")
* @NamedArgumentConstructor()
* Class OnMessageEvent
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnMessageEvent extends OnSwooleEventBase
{
/**
* @var string
*/
public $connect_type = 'default';
public function __construct($connect_type = 'default', $rule = '', $level = 20)
{
$this->connect_type = $connect_type;
$this->rule = $rule;
$this->level = $level;
}
}

View File

@ -4,17 +4,28 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
* Class OnOpenEvent
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnOpenEvent extends OnSwooleEventBase
{
/**
* @var string
*/
public $connect_type = 'default';
public function __construct($connect_type = 'default', $rule = '', $level = 20)
{
$this->connect_type = $connect_type;
$this->rule = $rule;
$this->level = $level;
}
}

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,8 +13,10 @@ use ZM\Annotation\AnnotationBase;
/**
* Class OnPipeMessageEvent
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnPipeMessageEvent extends AnnotationBase
{
/**
@ -20,4 +24,9 @@ class OnPipeMessageEvent extends AnnotationBase
* @Required()
*/
public $action;
public function __construct($action)
{
$this->action = $action;
}
}

View File

@ -4,13 +4,22 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
* Class OnRequestEvent
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnRequestEvent extends OnSwooleEventBase
{
public function __construct($rule = '', $level = 20)
{
$this->rule = $rule;
$this->level = $level;
}
}

View File

@ -4,14 +4,18 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class OnSave
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnSave extends AnnotationBase
{
}

View File

@ -4,14 +4,18 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class ZMSetup
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnSetup extends AnnotationBase
{
}

View File

@ -4,18 +4,27 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
/**
* Class OnWorkerStart
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnStart extends AnnotationBase
{
/**
* @var int
*/
public $worker_id = 0;
public function __construct($worker_id = 0)
{
$this->worker_id = $worker_id;
}
}

View File

@ -4,14 +4,18 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* Class OnSwooleEvent
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnSwooleEvent extends OnSwooleEventBase
{
/**
@ -20,6 +24,13 @@ class OnSwooleEvent extends OnSwooleEventBase
*/
public $type;
public function __construct($type, $rule = '', $level = 20)
{
$this->type = $type;
$this->rule = $rule;
$this->level = $level;
}
public function getType(): string
{
return $this->type;

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -12,8 +14,10 @@ use ZM\Annotation\Interfaces\Rule;
/**
* Class OnTask
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnTask extends AnnotationBase implements Rule
{
/**
@ -27,6 +31,12 @@ class OnTask extends AnnotationBase implements Rule
*/
public $rule = '';
public function __construct($task_name, $rule = '')
{
$this->task_name = $task_name;
$this->rule = $rule;
}
/**
* @return mixed
*/

View File

@ -4,13 +4,22 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* Class OnTaskEvent
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
class OnTaskEvent extends OnSwooleEventBase
{
public function __construct($rule = '', $level = 20)
{
$this->rule = $rule;
$this->level = $level;
}
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,6 +12,7 @@ use ZM\Annotation\AnnotationBase;
/**
* Class OnTick
* @Annotation
* @NamedArgumentConstructor()
* @Target("METHOD")
* @since 1.2
*/
@ -26,4 +28,10 @@ class OnTick extends AnnotationBase
* @var int
*/
public $worker_id = 0;
public function __construct($tick_ms, $worker_id = 0)
{
$this->tick_ms = $tick_ms;
$this->worker_id = $worker_id;
}
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace ZM\Annotation\Swoole;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
use ZM\Annotation\AnnotationBase;
@ -11,6 +12,7 @@ use ZM\Annotation\AnnotationBase;
/**
* Class SwooleHandler
* @Annotation
* @NamedArgumentConstructor()
* @Target("ALL")
*/
class SwooleHandler extends AnnotationBase
@ -20,4 +22,13 @@ class SwooleHandler extends AnnotationBase
* @Required()
*/
public $event;
/** @var string */
public $params = '';
public function __construct($event, $params = '')
{
$this->event = $event;
$this->params = $params;
}
}

View File

@ -28,9 +28,9 @@ use ZM\Exception\InitException;
class ConsoleApplication extends Application
{
public const VERSION_ID = 438;
public const VERSION_ID = 439;
public const VERSION = '2.7.0-beta3';
public const VERSION = '2.7.0-beta4';
private static $obj;

View File

@ -30,7 +30,10 @@ class EventTracer
public static function getCurrentEventMiddlewares()
{
$current_event = self::getCurrentEvent();
if (!isset($current_event->class, $current_event->method)) {
if (empty($current_event->class)) {
return null;
}
if (empty($current_event->method)) {
return null;
}
return EventManager::$middleware_map[$current_event->class][$current_event->method] ?? [];

View File

@ -39,7 +39,7 @@ class OnRequest implements SwooleEvent
$dis1 = new EventDispatcher(OnRequestEvent::class);
$dis1->setRuleFunction(function ($v) {
return eval('return ' . $v->getRule() . ';') ? true : false;
return (bool) eval('return ' . $v->getRule() . ';');
});
$dis = new EventDispatcher(OnSwooleEvent::class);
@ -61,8 +61,7 @@ class OnRequest implements SwooleEvent
if ($result === true) {
ctx()->setCache('params', $params);
$dispatcher = new EventDispatcher(RequestMapping::class);
$div = new RequestMapping();
$div->route = $node['route'];
$div = new RequestMapping($node['route']);
$div->params = $params;
$div->method = $node['method'];
$div->request_method = $node['request_method'];

View File

@ -4,6 +4,12 @@ declare(strict_types=1);
namespace ZM\Exception;
use Throwable;
class InvalidArgumentException extends ZMException
{
public function __construct($message = '', $code = 0, Throwable $previous = null)
{
parent::__construct(zm_internal_errcode('E00074') . $message, $code, $previous);
}
}

View File

@ -76,6 +76,7 @@ class Response
/**
* @param mixed ...$params
* @param mixed $name
* @return mixed
*/
public function rawcookie($name, ...$params)

View File

@ -35,6 +35,7 @@ class AnnotationParserRegisterTest extends TestCase
public function testAnnotation() {
ob_start();
$gen = $this->parser->generateAnnotationEvents();
//zm_dump($gen);
$m = $gen[OnStart::class][0]->method;
$class = $gen[OnStart::class][0]->class;
$c = new $class();
@ -43,12 +44,10 @@ class AnnotationParserRegisterTest extends TestCase
} catch (Exception $e) {
}
$result = ob_get_clean();
echo $result;
$this->assertStringContainsString("我开始了!", $result);
}
public function testAnnotation2() {
foreach ($this->parser->generateAnnotationEvents() as $k => $v) {
foreach ($v as $vs) {
$this->assertTrue($vs->method === null || $vs->method != '');
@ -57,22 +56,9 @@ class AnnotationParserRegisterTest extends TestCase
}
}
public function testAnnotationMap() {
$map = $this->parser->getMiddlewareMap();
$this->assertContainsEquals("timer", $map[Hello::class]["timer"]);
}
public function testMiddlewares() {
$wares = $this->parser->getMiddlewares();
zm_dump($wares);
$this->assertArrayHasKey("timer", $wares);
}
public function testReqMapping() {
$mapping = $this->parser->getReqMapping();
$this->assertEquals("index", $mapping["method"]);
}
public function testTracer() {
}
}