AbstractMultipleAnnotation.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. abstract class AbstractMultipleAnnotation extends AbstractAnnotation
  13. {
  14. public function collectClass(string $className): void
  15. {
  16. $annotation = AnnotationCollector::getClassAnnotation($className, static::class);
  17. AnnotationCollector::collectClass($className, static::class, $this->formatAnnotation($annotation));
  18. }
  19. public function collectClassConstant(string $className, ?string $target): void
  20. {
  21. $annotation = AnnotationCollector::getClassConstantAnnotation($className, $target)[static::class] ?? null;
  22. AnnotationCollector::collectClassConstant($className, $target, static::class, $this->formatAnnotation($annotation));
  23. }
  24. public function collectMethod(string $className, ?string $target): void
  25. {
  26. $annotation = AnnotationCollector::getClassMethodAnnotation($className, $target)[static::class] ?? null;
  27. AnnotationCollector::collectMethod($className, $target, static::class, $this->formatAnnotation($annotation));
  28. }
  29. public function collectProperty(string $className, ?string $target): void
  30. {
  31. $annotation = AnnotationCollector::getClassPropertyAnnotation($className, $target)[static::class] ?? null;
  32. AnnotationCollector::collectProperty($className, $target, static::class, $this->formatAnnotation($annotation));
  33. }
  34. protected function formatAnnotation(?MultipleAnnotation $annotation): MultipleAnnotation
  35. {
  36. if ($annotation instanceof MultipleAnnotation) {
  37. return $annotation->insert($this);
  38. }
  39. return new MultipleAnnotation($this);
  40. }
  41. }