1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Humbug\PhpScoper\Symbol; |
6
|
|
|
|
7
|
|
|
use Humbug\PhpScoper\Reflector; |
8
|
|
|
use Humbug\PhpScoper\Whitelist; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Combines the API or the "traditional" reflector which is about to tell |
12
|
|
|
* if a symbol is internal or not with the more PHP-Scoper specific exposed |
13
|
|
|
* API. |
14
|
|
|
*/ |
15
|
|
|
final class EnrichedReflector |
16
|
|
|
{ |
17
|
|
|
private Reflector $reflector; |
18
|
|
|
private Whitelist $whitelist; |
19
|
|
|
|
20
|
|
|
public function __construct(Reflector $reflector, Whitelist $whitelist) |
21
|
|
|
{ |
22
|
|
|
$this->reflector = $reflector; |
23
|
|
|
$this->whitelist = $whitelist; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function belongsToExcludedNamespace(string $name): bool |
27
|
|
|
{ |
28
|
|
|
return $this->whitelist->belongsToExcludedNamespace($name); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function isFunctionInternal(string $name): bool |
32
|
|
|
{ |
33
|
|
|
return $this->reflector->isFunctionInternal($name); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function isClassInternal(string $name): bool |
37
|
|
|
{ |
38
|
|
|
return $this->reflector->isClassInternal($name); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function isConstantInternal(string $name): bool |
42
|
|
|
{ |
43
|
|
|
return $this->reflector->isConstantInternal($name); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function isExposedClass(string $resolvedName): bool |
47
|
|
|
{ |
48
|
|
|
return !$this->whitelist->belongsToExcludedNamespace($resolvedName) |
49
|
|
|
&& ( |
50
|
|
|
$this->whitelist->isExposedClassFromGlobalNamespace($resolvedName) |
51
|
|
|
|| $this->whitelist->isSymbolExposed($resolvedName) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function isExposedConstant(string $name): bool |
56
|
|
|
{ |
57
|
|
|
// Special case: internal constants must be treated as exposed symbols. |
58
|
|
|
// |
59
|
|
|
// Example: when declaring a new internal constant for compatibility |
60
|
|
|
// reasons, it must remain un-prefixed. |
61
|
|
|
return $this->reflector->isConstantInternal($name) |
62
|
|
|
|| $this->whitelist->isExposedConstantFromGlobalNamespace($name) |
63
|
|
|
|| $this->whitelist->isSymbolExposed($name, true); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|