mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Removed $formattedValue from AbstractAnnotation.
This commit is contained in:
parent
70cd22cb17
commit
ee156ab50d
@ -40,6 +40,7 @@
|
||||
- [#3635](https://github.com/hyperf/hyperf/pull/3635) Added `Hyperf\Utils\CodeGen\PhpParser` which used to generate AST for reflection.
|
||||
- [#3648](https://github.com/hyperf/hyperf/pull/3648) Added `Hyperf\Utils\CodeGen\PhpDocReaderManager` to manage `PhpDocReader`.
|
||||
- [#3679](https://github.com/hyperf/hyperf/pull/3679) Added Nacos SDK component.
|
||||
- [#3698](https://github.com/hyperf/hyperf/pull/3698) Support PHP8 Attribute which can replace doctrine annotations.
|
||||
|
||||
## Optimized
|
||||
|
||||
|
@ -60,6 +60,6 @@ class CircuitBreaker extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('value');
|
||||
$this->bindMainProperty('value', $value);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ class Value extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('key');
|
||||
$this->bindMainProperty('key', $value);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class Crontab extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('rule');
|
||||
$this->bindMainProperty('rule', $value);
|
||||
if (! empty($this->rule)) {
|
||||
$this->rule = str_replace('\\', '', $this->rule);
|
||||
}
|
||||
|
@ -17,33 +17,21 @@ use ReflectionProperty;
|
||||
|
||||
abstract class AbstractAnnotation implements AnnotationInterface, Arrayable
|
||||
{
|
||||
|
||||
/**
|
||||
* @var null|array
|
||||
*/
|
||||
protected $formattedValue = null;
|
||||
protected $formattedValue;
|
||||
|
||||
public function __construct(...$value)
|
||||
{
|
||||
$this->formattedValue = $this->formatParams($value);
|
||||
foreach ($this->formattedValue as $key => $val) {
|
||||
$formattedValue = $this->formatParams($value);
|
||||
foreach ($formattedValue as $key => $val) {
|
||||
if (property_exists($this, $key)) {
|
||||
$this->{$key} = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatParams($value): array
|
||||
{
|
||||
if (isset($value[0])) {
|
||||
$value = $value[0];
|
||||
}
|
||||
if (! is_array($value)) {
|
||||
$value = ['value' => $value];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$properties = ReflectionManager::reflectClass(static::class)->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
@ -69,10 +57,22 @@ abstract class AbstractAnnotation implements AnnotationInterface, Arrayable
|
||||
AnnotationCollector::collectProperty($className, $target, static::class, $this);
|
||||
}
|
||||
|
||||
protected function bindMainProperty(string $key)
|
||||
protected function formatParams($value): array
|
||||
{
|
||||
if (isset($this->formattedValue['value'])) {
|
||||
$this->{$key} = $this->formattedValue['value'];
|
||||
if (isset($value[0])) {
|
||||
$value = $value[0];
|
||||
}
|
||||
if (! is_array($value)) {
|
||||
$value = ['value' => $value];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
protected function bindMainProperty(string $key, array $value)
|
||||
{
|
||||
$formattedValue = $this->formatParams($value);
|
||||
if (isset($formattedValue['value'])) {
|
||||
$this->{$key} = $formattedValue['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,6 @@ abstract class Mapping extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('path');
|
||||
$this->bindMainProperty('path', $value);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ class Middleware extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('middleware');
|
||||
$this->bindMainProperty('middleware', $value);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ class Middlewares extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
$this->formatParams($value);
|
||||
$this->bindMainProperty('middlewares');
|
||||
$this->bindMainProperty('middlewares', $value);
|
||||
}
|
||||
}
|
||||
|
@ -43,13 +43,14 @@ class RequestMapping extends Mapping
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
if (isset($this->formattedValue['methods'])) {
|
||||
if (is_string($this->formattedValue['methods'])) {
|
||||
$formattedValue = $this->formatParams($value);
|
||||
if (isset($formattedValue['methods'])) {
|
||||
if (is_string($formattedValue['methods'])) {
|
||||
// Explode a string to a array
|
||||
$this->methods = explode(',', Str::upper(str_replace(' ', '', $this->formattedValue['methods'])));
|
||||
$this->methods = explode(',', Str::upper(str_replace(' ', '', $formattedValue['methods'])));
|
||||
} else {
|
||||
$methods = [];
|
||||
foreach ($this->formattedValue['methods'] as $method) {
|
||||
foreach ($formattedValue['methods'] as $method) {
|
||||
$methods[] = Str::upper(str_replace(' ', '', $method));
|
||||
}
|
||||
$this->methods = $methods;
|
||||
|
@ -32,7 +32,7 @@ class ModelListener extends AbstractAnnotation
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
|
||||
if ($formattedValue = $this->formattedValue['value'] ?? null) {
|
||||
if ($formattedValue = $this->formatParams($value)['value'] ?? null) {
|
||||
if (is_string($formattedValue)) {
|
||||
$this->models = [$formattedValue];
|
||||
} elseif (is_array($formattedValue) && ! Arr::isAssoc($formattedValue)) {
|
||||
|
@ -28,7 +28,7 @@ class Event extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('event');
|
||||
$this->bindMainProperty('event', $value);
|
||||
}
|
||||
|
||||
public function collectMethod(string $className, ?string $target): void
|
||||
|
@ -27,7 +27,7 @@ class SocketIONamespace extends AbstractAnnotation
|
||||
public function __construct(...$value)
|
||||
{
|
||||
parent::__construct(...$value);
|
||||
$this->bindMainProperty('namespace');
|
||||
$this->bindMainProperty('namespace', $value);
|
||||
}
|
||||
|
||||
public function collectClass(string $className): void
|
||||
|
Loading…
Reference in New Issue
Block a user