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 isFunctionExcluded(string $name): bool |
37
|
|
|
{ |
38
|
|
|
return $this->reflector->isFunctionInternal($name) |
39
|
|
|
|| $this->whitelist->belongsToExcludedNamespace($name); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function isClassInternal(string $name): bool |
43
|
|
|
{ |
44
|
|
|
return $this->reflector->isClassInternal($name); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function isClassExcluded(string $name): bool |
48
|
|
|
{ |
49
|
|
|
return $this->reflector->isClassInternal($name) |
50
|
|
|
|| $this->whitelist->belongsToExcludedNamespace($name); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function isConstantInternal(string $name): bool |
54
|
|
|
{ |
55
|
|
|
return $this->reflector->isConstantInternal($name); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function isExposedFunction(string $resolvedName): bool |
59
|
|
|
{ |
60
|
|
|
return !$this->whitelist->belongsToExcludedNamespace($resolvedName) |
61
|
|
|
&& !$this->reflector->isFunctionInternal($resolvedName) |
62
|
|
|
&& ( |
63
|
|
|
$this->whitelist->isExposedFunctionFromGlobalNamespace($resolvedName) |
64
|
|
|
|| $this->whitelist->isSymbolExposed($resolvedName) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function isExposedClass(string $resolvedName): bool |
69
|
|
|
{ |
70
|
|
|
return !$this->whitelist->belongsToExcludedNamespace($resolvedName) |
71
|
|
|
&& ( |
72
|
|
|
$this->whitelist->isExposedClassFromGlobalNamespace($resolvedName) |
73
|
|
|
|| $this->whitelist->isSymbolExposed($resolvedName) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function isExposedConstant(string $name): bool |
78
|
|
|
{ |
79
|
|
|
// Special case: internal constants must be treated as exposed symbols. |
80
|
|
|
// |
81
|
|
|
// Example: when declaring a new internal constant for compatibility |
82
|
|
|
// reasons, it must remain un-prefixed. |
83
|
|
|
return !$this->whitelist->belongsToExcludedNamespace($name) |
84
|
|
|
&& ( |
85
|
|
|
$this->reflector->isConstantInternal($name) |
86
|
|
|
|| $this->whitelist->isExposedConstantFromGlobalNamespace($name) |
87
|
|
|
|| $this->whitelist->isSymbolExposed($name, true) |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|