mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 16:15:34 +08:00
add alias
This commit is contained in:
@@ -11,10 +11,15 @@ use Traversable;
|
||||
|
||||
abstract class AnnotationBase implements IteratorAggregate
|
||||
{
|
||||
public $method = '';
|
||||
public string $method = '';
|
||||
|
||||
/**
|
||||
* @var Closure|string
|
||||
*/
|
||||
public $class = '';
|
||||
|
||||
public array $group = [];
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$str = __CLASS__ . ': ';
|
||||
@@ -44,7 +49,7 @@ abstract class AnnotationBase implements IteratorAggregate
|
||||
*
|
||||
* @param Closure|string $method
|
||||
*/
|
||||
public function withMethod($method): AnnotationBase
|
||||
public function on($method): AnnotationBase
|
||||
{
|
||||
$this->method = $method;
|
||||
return $this;
|
||||
@@ -54,4 +59,19 @@ abstract class AnnotationBase implements IteratorAggregate
|
||||
{
|
||||
return new ArrayIterator($this);
|
||||
}
|
||||
|
||||
public function isInGroup(string $name): bool
|
||||
{
|
||||
return in_array($name, $this->group);
|
||||
}
|
||||
|
||||
public function addGroup(string $name)
|
||||
{
|
||||
$this->group[] = $name;
|
||||
}
|
||||
|
||||
public function getGroups(): array
|
||||
{
|
||||
return $this->group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Middleware;
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Middleware;
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Middleware;
|
||||
|
||||
use Attribute;
|
||||
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
|
||||
use Doctrine\Common\Annotations\Annotation\Target;
|
||||
use Exception;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Annotation\Middleware;
|
||||
|
||||
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 MiddlewareClass
|
||||
* @Annotation
|
||||
* @NamedArgumentConstructor()
|
||||
* @Target("CLASS")
|
||||
*/
|
||||
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
|
||||
class MiddlewareClass extends AnnotationBase
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @Required()
|
||||
*/
|
||||
public $name = '';
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user