optimization code

This commit is contained in:
assert 2021-06-15 10:53:11 +08:00 committed by 李铭昕
parent a3f4d0c0e6
commit 934058c479
10 changed files with 14 additions and 19 deletions

View File

@ -59,8 +59,6 @@ class CircuitBreaker extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $this->value = parent::__construct(...$value);
$this->value = $this->formatParams($value);
} }
} }

View File

@ -28,8 +28,7 @@ class Value extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
$this->bindMainProperty('key', $value); $this->bindMainProperty('key', $value);
} }
} }

View File

@ -76,8 +76,7 @@ class Crontab extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
$this->bindMainProperty('rule', $value); $this->bindMainProperty('rule', $value);
if (! empty($this->rule)) { if (! empty($this->rule)) {
$this->rule = str_replace('\\', '', $this->rule); $this->rule = str_replace('\\', '', $this->rule);

View File

@ -25,6 +25,7 @@ abstract class AbstractAnnotation implements AnnotationInterface, Arrayable
$this->{$key} = $val; $this->{$key} = $val;
} }
} }
return $value;
} }
protected function formatParams($value): array protected function formatParams($value): array

View File

@ -71,7 +71,8 @@ class AnnotationReader implements Reader
'example' => true, 'example' => true,
'filesource' => true, 'filesource' => true,
'global' => true, 'global' => true,
'ignore' => true, /* Can we enable this? 'index' => true, */ 'internal' => true, 'ignore' => true, /* Can we enable this? 'index' => true, */
'internal' => true,
'license' => true, 'link' => true, 'license' => true, 'link' => true,
'method' => true, 'method' => true,
'package' => true, 'param' => true, 'property' => true, 'property-read' => true, 'property-write' => true, 'package' => true, 'param' => true, 'property' => true, 'property-read' => true, 'property-write' => true,
@ -232,7 +233,9 @@ class AnnotationReader implements Reader
public function getAttributes(\Reflector $reflection): ?array public function getAttributes(\Reflector $reflection): ?array
{ {
if (method_exists($reflection, 'getAttributes') && $attributes = $reflection->getAttributes()) { if (method_exists($reflection, 'getAttributes') && $attributes = $reflection->getAttributes()) {
return array_map(fn(\ReflectionAttribute $attribute) => $attribute->newInstance(), $attributes); return array_map(function (\ReflectionAttribute $attribute) {
return $attribute->newInstance();
}, $attributes);
} }
return null; return null;
} }

View File

@ -28,8 +28,7 @@ class Middleware extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
$this->bindMainProperty('middleware', $value); $this->bindMainProperty('middleware', $value);
} }
} }

View File

@ -42,8 +42,7 @@ class RequestMapping extends Mapping
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
if (isset($value['methods'])) { if (isset($value['methods'])) {
if (is_string($value['methods'])) { if (is_string($value['methods'])) {
// Explode a string to a array // Explode a string to a array

View File

@ -30,8 +30,7 @@ class ModelListener extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
if ($value = $value['value'] ?? null) { if ($value = $value['value'] ?? null) {
if (is_string($value)) { if (is_string($value)) {

View File

@ -27,8 +27,7 @@ class Event extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
$this->bindMainProperty('event', $value); $this->bindMainProperty('event', $value);
} }

View File

@ -26,8 +26,7 @@ class SocketIONamespace extends AbstractAnnotation
public function __construct(...$value) public function __construct(...$value)
{ {
parent::__construct(...$value); $value = parent::__construct(...$value);
$value = $this->formatParams($value);
$this->bindMainProperty('namespace', $value); $this->bindMainProperty('namespace', $value);
} }