AbstractAnnotation.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Di\Annotation;
  12. use Hyperf\Contract\Arrayable;
  13. use Hyperf\Di\ReflectionManager;
  14. use ReflectionProperty;
  15. abstract class AbstractAnnotation implements AnnotationInterface, Arrayable
  16. {
  17. public function toArray(): array
  18. {
  19. $properties = ReflectionManager::reflectClass(static::class)->getProperties(ReflectionProperty::IS_PUBLIC);
  20. $result = [];
  21. foreach ($properties as $property) {
  22. $result[$property->getName()] = $property->getValue($this);
  23. }
  24. return $result;
  25. }
  26. public function collectClass(string $className): void
  27. {
  28. AnnotationCollector::collectClass($className, static::class, $this);
  29. }
  30. public function collectClassConstant(string $className, ?string $target): void
  31. {
  32. AnnotationCollector::collectClassConstant($className, $target, static::class, $this);
  33. }
  34. public function collectMethod(string $className, ?string $target): void
  35. {
  36. AnnotationCollector::collectMethod($className, $target, static::class, $this);
  37. }
  38. public function collectProperty(string $className, ?string $target): void
  39. {
  40. AnnotationCollector::collectProperty($className, $target, static::class, $this);
  41. }
  42. }