Constants.php 856 B

12345678910111213141516171819202122232425262728293031323334
  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\Constants\Annotation;
  12. use Attribute;
  13. use Hyperf\Constants\AnnotationReader;
  14. use Hyperf\Constants\ConstantsCollector;
  15. use Hyperf\Di\Annotation\AbstractAnnotation;
  16. use ReflectionClass;
  17. #[Attribute(Attribute::TARGET_CLASS)]
  18. class Constants extends AbstractAnnotation
  19. {
  20. public function collectClass(string $className): void
  21. {
  22. $reader = new AnnotationReader();
  23. $ref = new ReflectionClass($className);
  24. $classConstants = $ref->getReflectionConstants();
  25. $data = $reader->getAnnotations($classConstants);
  26. ConstantsCollector::set($className, $data);
  27. }
  28. }