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