Repository navigation
Expand file tree
/
Copy pathAspect.php
More file actions
51 lines (44 loc) · 1.68 KB
/
Copy pathAspect.php
File metadata and controls
51 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Di\Annotation;
use Attribute;
use InvalidArgumentException;
#[Attribute(Attribute::TARGET_CLASS)]
class Aspect extends AbstractAnnotation
{
public function __construct(public array $classes = [], public array $annotations = [], public ?int $priority = null)
{
}
public function collectClass(string $className): void
{
parent::collectClass($className);
$this->collect($className);
}
protected function collect(string $className)
{
[$instanceClasses, $instanceAnnotations, $instancePriority] = AspectLoader::load($className);
// Classes
$classes = $this->classes;
$classes = $instanceClasses ? array_merge($classes, $instanceClasses) : $classes;
// Annotations
$annotations = $this->annotations;
$annotations = $instanceAnnotations ? array_merge($annotations, $instanceAnnotations) : $annotations;
// Priority
$annotationPriority = $this->priority;
$propertyPriority = $instancePriority ?: null;
if (! is_null($annotationPriority) && ! is_null($propertyPriority) && $annotationPriority !== $propertyPriority) {
throw new InvalidArgumentException('Cannot define two difference priority of Aspect.');
}
$priority = $annotationPriority ?? $propertyPriority;
// Save the metadata to AspectCollector
AspectCollector::setAround($className, $classes, $annotations, $priority);
}
}