|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Spiral\Boot\BootloadManager\AttributeResolver; |
|
6
|
|
|
|
|
7
|
|
|
use Spiral\Boot\Attribute\AbstractMethod; |
|
8
|
|
|
use Spiral\Boot\Attribute\BindAlias; |
|
9
|
|
|
use Spiral\Boot\Attribute\BindScope; |
|
10
|
|
|
use Spiral\Boot\Bootloader\BootloaderInterface; |
|
11
|
|
|
use Spiral\Boot\BootloadManager\AttributeResolverInterface; |
|
12
|
|
|
use Spiral\Core\BinderInterface; |
|
13
|
|
|
use Spiral\Core\Config\Binding; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @internal |
|
17
|
|
|
* @template T of AbstractMethod |
|
18
|
|
|
* @template TBootloader of BootloaderInterface |
|
19
|
|
|
* @implements AttributeResolverInterface<T, TBootloader> |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AbstractResolver implements AttributeResolverInterface |
|
22
|
|
|
{ |
|
23
|
19 |
|
public function __construct( |
|
24
|
|
|
protected readonly BinderInterface $binder, |
|
25
|
19 |
|
) {} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @psalm-param T $attribute |
|
29
|
|
|
* @return list<non-empty-string> |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
11 |
|
protected function getAliases(object $attribute, \ReflectionMethod $method): array |
|
32
|
|
|
{ |
|
33
|
11 |
|
$alias = $attribute->alias ?? null; |
|
34
|
|
|
|
|
35
|
11 |
|
$aliases = []; |
|
36
|
11 |
|
if ($alias !== null) { |
|
37
|
5 |
|
$aliases[] = $alias; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
11 |
|
$attrs = $method->getAttributes(name: BindAlias::class); |
|
41
|
11 |
|
foreach ($attrs as $attr) { |
|
42
|
1 |
|
$aliases = [...$aliases, ...$attr->newInstance()->aliases]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// If no aliases are provided, we will use the return type as the alias. |
|
46
|
11 |
|
if (\count($aliases) > 0 && !$attribute->aliasesFromReturnType) { |
|
47
|
5 |
|
return \array_unique(\array_filter($aliases)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
11 |
|
$type = $method->getReturnType(); |
|
51
|
|
|
|
|
52
|
11 |
|
if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { |
|
53
|
8 |
|
foreach ($type->getTypes() as $type) { |
|
54
|
8 |
|
if ($type->isBuiltin()) { |
|
55
|
6 |
|
continue; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
6 |
|
$aliases[] = $type->getName(); |
|
59
|
|
|
} |
|
60
|
7 |
|
} elseif ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) { |
|
61
|
5 |
|
$aliases[] = $type->getName(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
11 |
|
if ($aliases === []) { |
|
65
|
4 |
|
throw new \LogicException( |
|
66
|
4 |
|
"No alias provided for binding {$method->getDeclaringClass()->getName()}::{$method->getName()}", |
|
67
|
4 |
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
7 |
|
return \array_unique(\array_filter($aliases)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
7 |
|
protected function getScopes(\ReflectionMethod $method): array |
|
74
|
|
|
{ |
|
75
|
7 |
|
$attrs = $method->getAttributes(name: BindScope::class); |
|
76
|
|
|
|
|
77
|
7 |
|
if ($attrs === []) { |
|
78
|
7 |
|
return []; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return \array_map( |
|
82
|
|
|
static fn(\ReflectionAttribute $attr): string => $attrs[0]->newInstance()->scope, |
|
|
|
|
|
|
83
|
|
|
$attrs, |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
7 |
|
protected function bind(array $aliases, Binding $binding, array $scopes): void |
|
88
|
|
|
{ |
|
89
|
7 |
|
$binders = []; |
|
90
|
7 |
|
foreach ($scopes as $scope) { |
|
91
|
|
|
$binders[] = $this->binder->getBinder($scope); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
7 |
|
if ($binders === []) { |
|
95
|
7 |
|
$binders[] = $this->binder; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
7 |
|
foreach ($binders as $binder) { |
|
99
|
7 |
|
$alias = \array_shift($aliases); |
|
100
|
7 |
|
foreach ($aliases as $a) { |
|
101
|
7 |
|
$binder->bind($alias, $a); |
|
102
|
7 |
|
$alias = \array_shift($aliases); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
7 |
|
$binder->bind($alias, $binding); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths