AspectLoader.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\Di\ReflectionManager;
  13. use ReflectionProperty;
  14. class AspectLoader
  15. {
  16. /**
  17. * Load classes annotations and priority from aspect without invoking their constructor.
  18. */
  19. public static function load(string $className): array
  20. {
  21. $reflectionClass = ReflectionManager::reflectClass($className);
  22. $properties = $reflectionClass->getProperties(ReflectionProperty::IS_PUBLIC);
  23. $instanceClasses = $instanceAnnotations = [];
  24. $instancePriority = null;
  25. foreach ($properties as $property) {
  26. if ($property->getName() === 'classes') {
  27. $instanceClasses = ReflectionManager::getPropertyDefaultValue($property);
  28. } elseif ($property->getName() === 'annotations') {
  29. $instanceAnnotations = ReflectionManager::getPropertyDefaultValue($property);
  30. } elseif ($property->getName() === 'priority') {
  31. $instancePriority = ReflectionManager::getPropertyDefaultValue($property);
  32. }
  33. }
  34. return [$instanceClasses, $instanceAnnotations, $instancePriority];
  35. }
  36. }