Completed
Pull Request — master (#279)
by Marco
28:36 queued 05:21
created

Configuration::setProxyAutoloader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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
    /**
88
     * @param AutoloaderInterface $proxyAutoloader
89
     *
90
     * @return void
91
     */
92 1
    public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader)
93
    {
94 1
        $this->proxyAutoloader = $proxyAutoloader;
95 1
    }
96
97 1
    public function getProxyAutoloader() : AutoloaderInterface
98
    {
99 1
        return $this->proxyAutoloader
100 1
            ?: $this->proxyAutoloader = new Autoloader(
101 1
                new FileLocator($this->getProxiesTargetDir()),
102 1
                $this->getClassNameInflector()
103
            );
104
    }
105
106
    /**
107
     * @param string $proxiesNamespace
108
     *
109
     * @return void
110
     */
111 1
    public function setProxiesNamespace(string $proxiesNamespace)
112
    {
113 1
        $this->proxiesNamespace = $proxiesNamespace;
114 1
    }
115
116 1
    public function getProxiesNamespace() : string
117
    {
118 1
        return $this->proxiesNamespace;
119
    }
120
121
    /**
122
     * @param string $proxiesTargetDir
123
     *
124
     * @return void
125
     */
126 1
    public function setProxiesTargetDir(string $proxiesTargetDir)
127
    {
128 1
        $this->proxiesTargetDir = $proxiesTargetDir;
129 1
    }
130
131 1
    public function getProxiesTargetDir() : string
132
    {
133 1
        return $this->proxiesTargetDir ?: $this->proxiesTargetDir = sys_get_temp_dir();
134
    }
135
136
    /**
137
     * @param GeneratorStrategyInterface $generatorStrategy
138
     *
139
     * @return void
140
     */
141 1
    public function setGeneratorStrategy(GeneratorStrategyInterface $generatorStrategy)
142
    {
143 1
        $this->generatorStrategy = $generatorStrategy;
144 1
    }
145
146 2
    public function getGeneratorStrategy() : GeneratorStrategyInterface
147
    {
148 2
        return $this->generatorStrategy
149 2
            ?: $this->generatorStrategy = new EvaluatingGeneratorStrategy();
150
    }
151
152
    /**
153
     * @param ClassNameInflectorInterface $classNameInflector
154
     *
155
     * @return void
156
     */
157 1
    public function setClassNameInflector(ClassNameInflectorInterface $classNameInflector)
158
    {
159 1
        $this->classNameInflector = $classNameInflector;
160 1
    }
161
162 1
    public function getClassNameInflector() : ClassNameInflectorInterface
163
    {
164 1
        return $this->classNameInflector
165 1
            ?: $this->classNameInflector = new ClassNameInflector($this->getProxiesNamespace());
166
    }
167
168
    /**
169
     * @param SignatureGeneratorInterface $signatureGenerator
170
     *
171
     * @return void
172
     */
173 1
    public function setSignatureGenerator(SignatureGeneratorInterface $signatureGenerator)
174
    {
175 1
        $this->signatureGenerator = $signatureGenerator;
176 1
    }
177
178 1
    public function getSignatureGenerator() : SignatureGeneratorInterface
179
    {
180 1
        return $this->signatureGenerator ?: $this->signatureGenerator = new SignatureGenerator();
181
    }
182
183
    /**
184
     * @param SignatureCheckerInterface $signatureChecker
185
     *
186
     * @return void
187
     */
188 1
    public function setSignatureChecker(SignatureCheckerInterface $signatureChecker)
189
    {
190 1
        $this->signatureChecker = $signatureChecker;
191 1
    }
192
193 1
    public function getSignatureChecker() : SignatureCheckerInterface
194
    {
195 1
        return $this->signatureChecker
196 1
            ?: $this->signatureChecker = new SignatureChecker($this->getSignatureGenerator());
197
    }
198
199
    /**
200
     * @param ClassSignatureGeneratorInterface $classSignatureGenerator
201
     *
202
     * @return void
203
     */
204 1
    public function setClassSignatureGenerator(ClassSignatureGeneratorInterface $classSignatureGenerator)
205
    {
206 1
        $this->classSignatureGenerator = $classSignatureGenerator;
207 1
    }
208
209 1
    public function getClassSignatureGenerator() : ClassSignatureGeneratorInterface
210
    {
211 1
        return $this->classSignatureGenerator
212 1
            ?: new ClassSignatureGenerator($this->getSignatureGenerator());
213
    }
214
}
215