Completed
Pull Request — master (#359)
by Jefersson
06:36
created

Configuration::getProxiesNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
    public function setProxyAutoloader(AutoloaderInterface $proxyAutoloader) : void
88
    {
89
        $this->proxyAutoloader = $proxyAutoloader;
90
    }
91
92 1
    public function getProxyAutoloader() : AutoloaderInterface
93
    {
94 1
        return $this->proxyAutoloader
95 1
            ?: $this->proxyAutoloader = new Autoloader(
96
                new FileLocator($this->getProxiesTargetDir()),
97 1
                $this->getClassNameInflector()
98
            );
99 1
    }
100 1
101 1
    public function setProxiesNamespace(string $proxiesNamespace) : void
102 1
    {
103
        $this->proxiesNamespace = $proxiesNamespace;
104
    }
105
106
    public function getProxiesNamespace() : string
107
    {
108
        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
    public function setGeneratorStrategy(GeneratorStrategyInterface $generatorStrategy) : void
122
    {
123
        $this->generatorStrategy = $generatorStrategy;
124
    }
125
126 1
    public function getGeneratorStrategy() : GeneratorStrategyInterface
127
    {
128 1
        return $this->generatorStrategy
129 1
            ?: $this->generatorStrategy = new EvaluatingGeneratorStrategy();
130
    }
131 1
132
    public function setClassNameInflector(ClassNameInflectorInterface $classNameInflector) : void
133 1
    {
134
        $this->classNameInflector = $classNameInflector;
135
    }
136
137
    public function getClassNameInflector() : ClassNameInflectorInterface
138
    {
139
        return $this->classNameInflector
140
            ?: $this->classNameInflector = new ClassNameInflector($this->getProxiesNamespace());
141 1
    }
142
143 1
    public function setSignatureGenerator(SignatureGeneratorInterface $signatureGenerator) : void
144 1
    {
145
        $this->signatureGenerator = $signatureGenerator;
146 2
    }
147
148 2
    public function getSignatureGenerator() : SignatureGeneratorInterface
149 2
    {
150
        return $this->signatureGenerator ?: $this->signatureGenerator = new SignatureGenerator();
151
    }
152
153
    public function setSignatureChecker(SignatureCheckerInterface $signatureChecker) : void
154
    {
155
        $this->signatureChecker = $signatureChecker;
156
    }
157 1
158
    public function getSignatureChecker() : SignatureCheckerInterface
159 1
    {
160 1
        return $this->signatureChecker
161
            ?: $this->signatureChecker = new SignatureChecker($this->getSignatureGenerator());
162 1
    }
163
164 1
    public function setClassSignatureGenerator(ClassSignatureGeneratorInterface $classSignatureGenerator) : void
165 1
    {
166
        $this->classSignatureGenerator = $classSignatureGenerator;
167
    }
168
169
    public function getClassSignatureGenerator() : ClassSignatureGeneratorInterface
170
    {
171
        return $this->classSignatureGenerator
172
            ?: new ClassSignatureGenerator($this->getSignatureGenerator());
173 1
    }
174
}
175