add proxy server command and update lowest version of PHP >= 8.0

This commit is contained in:
crazywhalecc
2022-11-03 10:18:17 +08:00
parent 6b34427855
commit 35dec947df
49 changed files with 826 additions and 301 deletions

View File

@@ -4,17 +4,12 @@ declare(strict_types=1);
namespace ZM\Annotation;
use ArrayIterator;
use Closure;
use IteratorAggregate;
use Traversable;
abstract class AnnotationBase implements IteratorAggregate
abstract class AnnotationBase implements \IteratorAggregate
{
public string $method = '';
/**
* @var Closure|string
* @var \Closure|string
*/
public $class = '';
@@ -33,7 +28,7 @@ abstract class AnnotationBase implements IteratorAggregate
$str .= ($v ? 'TRUE' : 'FALSE');
} elseif (is_array($v)) {
$str .= json_encode($v, JSON_UNESCAPED_UNICODE);
} elseif ($v instanceof Closure) {
} elseif ($v instanceof \Closure) {
$str .= '@AnonymousFunction';
} elseif (is_null($v)) {
$str .= 'NULL';
@@ -47,7 +42,7 @@ abstract class AnnotationBase implements IteratorAggregate
/**
* 在 InstantPlugin 下调用,设置回调或匿名函数
*
* @param Closure|string $method
* @param \Closure|string $method
*/
public function on($method): AnnotationBase
{
@@ -55,9 +50,9 @@ abstract class AnnotationBase implements IteratorAggregate
return $this;
}
public function getIterator(): Traversable
public function getIterator(): \Traversable
{
return new ArrayIterator($this);
return new \ArrayIterator($this);
}
public function isInGroup(string $name): bool

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation;
use Throwable;
use ZM\Exception\InterruptException;
/**
@@ -89,8 +88,8 @@ class AnnotationHandler
* 调用注册了该注解的所有函数们
* 此处会遍历所有注册了当前注解的函数,并支持中间件插入
*
* @param mixed ...$params 传入的参数们
* @throws Throwable
* @param mixed ...$params 传入的参数们
* @throws \Throwable
*/
public function handleAll(...$params)
{
@@ -113,7 +112,7 @@ class AnnotationHandler
// InterruptException 用于中断,这里必须 catch并标记状态
$this->return_val = $e->return_var;
$this->status = self::STATUS_INTERRUPTED;
} catch (Throwable $e) {
} catch (\Throwable $e) {
// 其他类型的异常就顺势再抛出到外层,此层不做处理
$this->status = self::STATUS_EXCEPTION;
throw $e;
@@ -124,7 +123,7 @@ class AnnotationHandler
* 调用单个注解
*
* @throws InterruptException
* @throws Throwable
* @throws \Throwable
*/
public function handle(AnnotationBase $v, ?callable $rule_callback = null, ...$args): bool
{
@@ -144,7 +143,7 @@ class AnnotationHandler
} catch (InterruptException $e) {
// 这里直接抛出这个异常的目的就是给上层handleAll()捕获
throw $e;
} catch (Throwable $e) {
} catch (\Throwable $e) {
// 其余的异常就交给中间件的异常捕获器过一遍,没捕获的则继续抛出
$this->status = self::STATUS_EXCEPTION;
throw $e;

View File

@@ -7,8 +7,6 @@ namespace ZM\Annotation;
use Doctrine\Common\Annotations\AnnotationReader;
use Koriym\Attributes\AttributeReader;
use Koriym\Attributes\DualReader;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
use ZM\Annotation\Http\Controller;
use ZM\Annotation\Http\Route;
@@ -78,7 +76,7 @@ class AnnotationParser
/**
* 注册各个模块类的注解和模块level的排序
*
* @throws ReflectionException
* @throws \ReflectionException
* @throws ConfigException
*/
public function parseAll()
@@ -112,8 +110,8 @@ class AnnotationParser
logger()->debug('正在检索 ' . $v);
// 通过反射实现注解读取
$reflection_class = new ReflectionClass($v);
$methods = $reflection_class->getMethods(ReflectionMethod::IS_PUBLIC);
$reflection_class = new \ReflectionClass($v);
$methods = $reflection_class->getMethods(\ReflectionMethod::IS_PUBLIC);
$class_annotations = $reader->getClassAnnotations($reflection_class);
// 这段为新加的:start
// 这里将每个类里面所有的类注解、方法注解通通加到一颗大树上,后期解析

View File

@@ -14,7 +14,7 @@ use Doctrine\Common\Annotations\Annotation\Target;
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
class Closed extends AnnotationBase
{
}

View File

@@ -20,7 +20,7 @@ use ZM\Annotation\Interfaces\Level;
* @Target("METHOD")
* @since 3.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class BindEvent extends AnnotationBase implements Level
{
/**

View File

@@ -16,7 +16,7 @@ use ZM\Annotation\AnnotationBase;
* @Target("METHOD")
* @since 3.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Init extends AnnotationBase
{
/** @var int */

View File

@@ -16,7 +16,7 @@ use ZM\Annotation\AnnotationBase;
* @Target("METHOD")
* @since 3.0.0
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Setup extends AnnotationBase
{
}

View File

@@ -17,7 +17,7 @@ use ZM\Annotation\Interfaces\ErgodicAnnotation;
* @NamedArgumentConstructor()
* @Target("CLASS")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS)]
class Controller extends AnnotationBase implements ErgodicAnnotation
{
/**

View File

@@ -16,7 +16,7 @@ use ZM\Annotation\AnnotationBase;
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Route extends AnnotationBase
{
/**

View File

@@ -17,7 +17,7 @@ use ZM\Annotation\Interfaces\ErgodicAnnotation;
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
class Middleware extends AnnotationBase implements ErgodicAnnotation
{
/**

View File

@@ -20,7 +20,7 @@ use ZM\Exception\ZMKnownException;
* @NamedArgumentConstructor()
* @Target("METHOD")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class BotCommand extends AnnotationBase implements Level
{
/** @var string */

View File

@@ -16,7 +16,7 @@ use ZM\Annotation\AnnotationBase;
* @Target("METHOD")
* @NamedArgumentConstructor()
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class BotEvent extends AnnotationBase
{
public ?string $type;

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Annotation\OneBot;
use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use ZM\Annotation\AnnotationBase;
@@ -18,7 +17,7 @@ use ZM\Exception\ZMKnownException;
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_ALL)]
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
class CommandArgument extends AnnotationBase implements ErgodicAnnotation
{
/**