add alias

This commit is contained in:
crazywhalecc
2022-08-21 20:15:55 +08:00
parent 8f761c31e3
commit ac69640253
8 changed files with 59 additions and 112 deletions

View File

@@ -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;
}
}

View File

@@ -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
{
}

View File

@@ -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
{
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}