1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Broker; |
4: | |
5: | use PhpParser\Node; |
6: | use PHPStan\Analyser\Scope; |
7: | use PHPStan\Reflection\ClassReflection; |
8: | use PHPStan\Reflection\FunctionReflection; |
9: | use PHPStan\Reflection\GlobalConstantReflection; |
10: | use PHPStan\Reflection\NamespaceAnswerer; |
11: | use PHPStan\Reflection\ReflectionProvider; |
12: | use PHPStan\ShouldNotHappenException; |
13: | |
14: | |
15: | |
16: | |
17: | final class Broker implements ReflectionProvider |
18: | { |
19: | |
20: | private static ?Broker $instance = null; |
21: | |
22: | |
23: | |
24: | |
25: | public function __construct( |
26: | private ReflectionProvider $reflectionProvider, |
27: | private array $universalObjectCratesClasses, |
28: | ) |
29: | { |
30: | } |
31: | |
32: | public static function registerInstance(Broker $broker): void |
33: | { |
34: | self::$instance = $broker; |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | public static function getInstance(): Broker |
41: | { |
42: | if (self::$instance === null) { |
43: | throw new ShouldNotHappenException(); |
44: | } |
45: | return self::$instance; |
46: | } |
47: | |
48: | |
49: | |
50: | |
51: | public function hasClass(string $className): bool |
52: | { |
53: | return $this->reflectionProvider->hasClass($className); |
54: | } |
55: | |
56: | |
57: | |
58: | |
59: | public function getClass(string $className): ClassReflection |
60: | { |
61: | return $this->reflectionProvider->getClass($className); |
62: | } |
63: | |
64: | |
65: | |
66: | |
67: | public function getClassName(string $className): string |
68: | { |
69: | return $this->reflectionProvider->getClassName($className); |
70: | } |
71: | |
72: | |
73: | |
74: | |
75: | public function supportsAnonymousClasses(): bool |
76: | { |
77: | return $this->reflectionProvider->supportsAnonymousClasses(); |
78: | } |
79: | |
80: | |
81: | |
82: | |
83: | public function getAnonymousClassReflection(Node\Stmt\Class_ $classNode, Scope $scope): ClassReflection |
84: | { |
85: | return $this->reflectionProvider->getAnonymousClassReflection($classNode, $scope); |
86: | } |
87: | |
88: | |
89: | |
90: | |
91: | public function hasFunction(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): bool |
92: | { |
93: | return $this->reflectionProvider->hasFunction($nameNode, $namespaceAnswerer); |
94: | } |
95: | |
96: | |
97: | |
98: | |
99: | public function getFunction(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): FunctionReflection |
100: | { |
101: | return $this->reflectionProvider->getFunction($nameNode, $namespaceAnswerer); |
102: | } |
103: | |
104: | |
105: | |
106: | |
107: | public function resolveFunctionName(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): ?string |
108: | { |
109: | return $this->reflectionProvider->resolveFunctionName($nameNode, $namespaceAnswerer); |
110: | } |
111: | |
112: | |
113: | |
114: | |
115: | public function hasConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): bool |
116: | { |
117: | return $this->reflectionProvider->hasConstant($nameNode, $namespaceAnswerer); |
118: | } |
119: | |
120: | |
121: | |
122: | |
123: | public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): GlobalConstantReflection |
124: | { |
125: | return $this->reflectionProvider->getConstant($nameNode, $namespaceAnswerer); |
126: | } |
127: | |
128: | |
129: | |
130: | |
131: | public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): ?string |
132: | { |
133: | return $this->reflectionProvider->resolveConstantName($nameNode, $namespaceAnswerer); |
134: | } |
135: | |
136: | |
137: | |
138: | |
139: | |
140: | |
141: | public function getUniversalObjectCratesClasses(): array |
142: | { |
143: | return $this->universalObjectCratesClasses; |
144: | } |
145: | |
146: | } |
147: | |