|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
declare(strict_types=1); |
|
20
|
|
|
|
|
21
|
|
|
namespace ProxyManager; |
|
22
|
|
|
|
|
23
|
|
|
use ProxyManager\Autoloader\Autoloader; |
|
24
|
|
|
use ProxyManager\Autoloader\AutoloaderInterface; |
|
25
|
|
|
use ProxyManager\FileLocator\FileLocator; |
|
26
|
|
|
use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; |
|
27
|
|
|
use ProxyManager\GeneratorStrategy\GeneratorStrategyInterface; |
|
28
|
|
|
use ProxyManager\Inflector\ClassNameInflector; |
|
29
|
|
|
use ProxyManager\Inflector\ClassNameInflectorInterface; |
|
30
|
|
|
use ProxyManager\Signature\ClassSignatureGenerator; |
|
31
|
|
|
use ProxyManager\Signature\ClassSignatureGeneratorInterface; |
|
32
|
|
|
use ProxyManager\Signature\SignatureChecker; |
|
33
|
|
|
use ProxyManager\Signature\SignatureCheckerInterface; |
|
34
|
|
|
use ProxyManager\Signature\SignatureGenerator; |
|
35
|
|
|
use ProxyManager\Signature\SignatureGeneratorInterface; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Base configuration class for the proxy manager - serves as micro disposable DIC/facade |
|
39
|
|
|
* |
|
40
|
|
|
* @author Marco Pivetta <[email protected]> |
|
41
|
|
|
* @license MIT |
|
42
|
|
|
*/ |
|
43
|
|
|
class Configuration |
|
44
|
|
|
{ |
|
45
|
|
|
const DEFAULT_PROXY_NAMESPACE = 'ProxyManagerGeneratedProxy'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string|null |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $proxiesTargetDir; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $proxiesNamespace = self::DEFAULT_PROXY_NAMESPACE; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var GeneratorStrategyInterface|null |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $generatorStrategy; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var callable|null |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $proxyAutoloader; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var ClassNameInflectorInterface|null |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $classNameInflector; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var SignatureGeneratorInterface|null |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $signatureGenerator; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var SignatureCheckerInterface|null |
|
79
|
|
|
*/ |
|
80
|
|
|
protected $signatureChecker; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var ClassSignatureGeneratorInterface|null |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $classSignatureGenerator; |
|
86
|
|
|
|
|
87
|
1 |
|
public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader) : void |
|
88
|
|
|
{ |
|
89
|
1 |
|
$this->proxyAutoloader = $proxyAutoloader; |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
1 |
|
public function getProxyAutoloader() : AutoloaderInterface |
|
93
|
|
|
{ |
|
94
|
1 |
|
return $this->proxyAutoloader |
|
95
|
1 |
|
?: $this->proxyAutoloader = new Autoloader( |
|
96
|
1 |
|
new FileLocator($this->getProxiesTargetDir()), |
|
97
|
1 |
|
$this->getClassNameInflector() |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
public function setProxiesNamespace(string $proxiesNamespace) : void |
|
102
|
|
|
{ |
|
103
|
1 |
|
$this->proxiesNamespace = $proxiesNamespace; |
|
104
|
1 |
|
} |
|
105
|
|
|
|
|
106
|
1 |
|
public function getProxiesNamespace() : string |
|
107
|
|
|
{ |
|
108
|
1 |
|
return $this->proxiesNamespace; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
public function setProxiesTargetDir(string $proxiesTargetDir) : void |
|
112
|
|
|
{ |
|
113
|
1 |
|
$this->proxiesTargetDir = $proxiesTargetDir; |
|
114
|
1 |
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
public function getProxiesTargetDir() : string |
|
117
|
|
|
{ |
|
118
|
1 |
|
return $this->proxiesTargetDir ?: $this->proxiesTargetDir = sys_get_temp_dir(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
public function setGeneratorStrategy(GeneratorStrategyInterface $generatorStrategy) : void |
|
122
|
|
|
{ |
|
123
|
1 |
|
$this->generatorStrategy = $generatorStrategy; |
|
124
|
1 |
|
} |
|
125
|
|
|
|
|
126
|
2 |
|
public function getGeneratorStrategy() : GeneratorStrategyInterface |
|
127
|
|
|
{ |
|
128
|
2 |
|
return $this->generatorStrategy |
|
129
|
2 |
|
?: $this->generatorStrategy = new EvaluatingGeneratorStrategy(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
1 |
|
public function setClassNameInflector(ClassNameInflectorInterface $classNameInflector) : void |
|
133
|
|
|
{ |
|
134
|
1 |
|
$this->classNameInflector = $classNameInflector; |
|
135
|
1 |
|
} |
|
136
|
|
|
|
|
137
|
1 |
|
public function getClassNameInflector() : ClassNameInflectorInterface |
|
138
|
|
|
{ |
|
139
|
1 |
|
return $this->classNameInflector |
|
140
|
1 |
|
?: $this->classNameInflector = new ClassNameInflector($this->getProxiesNamespace()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
1 |
|
public function setSignatureGenerator(SignatureGeneratorInterface $signatureGenerator) : void |
|
144
|
|
|
{ |
|
145
|
1 |
|
$this->signatureGenerator = $signatureGenerator; |
|
146
|
1 |
|
} |
|
147
|
|
|
|
|
148
|
1 |
|
public function getSignatureGenerator() : SignatureGeneratorInterface |
|
149
|
|
|
{ |
|
150
|
1 |
|
return $this->signatureGenerator ?: $this->signatureGenerator = new SignatureGenerator(); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
1 |
|
public function setSignatureChecker(SignatureCheckerInterface $signatureChecker) : void |
|
154
|
|
|
{ |
|
155
|
1 |
|
$this->signatureChecker = $signatureChecker; |
|
156
|
1 |
|
} |
|
157
|
|
|
|
|
158
|
1 |
|
public function getSignatureChecker() : SignatureCheckerInterface |
|
159
|
|
|
{ |
|
160
|
1 |
|
return $this->signatureChecker |
|
161
|
1 |
|
?: $this->signatureChecker = new SignatureChecker($this->getSignatureGenerator()); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
1 |
|
public function setClassSignatureGenerator(ClassSignatureGeneratorInterface $classSignatureGenerator) : void |
|
165
|
|
|
{ |
|
166
|
1 |
|
$this->classSignatureGenerator = $classSignatureGenerator; |
|
167
|
1 |
|
} |
|
168
|
|
|
|
|
169
|
1 |
|
public function getClassSignatureGenerator() : ClassSignatureGeneratorInterface |
|
170
|
|
|
{ |
|
171
|
1 |
|
return $this->classSignatureGenerator |
|
172
|
1 |
|
?: new ClassSignatureGenerator($this->getSignatureGenerator()); |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|