Completed
Push — dependabot/composer/symfony/ht... ( 5f4f25...9dd149 )
by
unknown
11:20 queued 05:11
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace phpDocumentor\Guides;
6
7
use Doctrine\Common\EventManager;
8
use phpDocumentor\Guides\Formats\Format;
9
use phpDocumentor\Guides\TemplateRenderer;
10
use RuntimeException;
11
use Twig\Environment as TwigEnvironment;
12
use function sprintf;
13
use function sys_get_temp_dir;
14
15
class Configuration
16
{
17
    public const THEME_DEFAULT = 'default';
18
19
    /** @var string */
20
    private $cacheDir;
21
22
    /** @var string */
23
    private $theme = self::THEME_DEFAULT;
24
25
    /** @var string */
26
    private $baseUrl = '';
27
28
    /** @var callable|null */
29
    private $baseUrlEnabledCallable;
30
31
    /** @var bool */
32
    private $ignoreInvalidReferences = false;
33
34
    /** @var bool */
35
    private $indentHTML = false;
36
37
    /** @var int */
38
    private $initialHeaderLevel = 1;
39
40
    /** @var bool */
41
    private $useCachedMetas = true;
42
43
    /** @var string */
44
    private $fileExtension = Format::HTML;
45
46
    /** @var string */
47
    private $indexName = 'index';
48
49
    /** @var string */
50
    private $sourceFileExtension = 'rst';
51
52
    /** @var TemplateRenderer */
53
    private $templateRenderer;
54
55
    /** @var Format[] */
56
    private $formats;
57
58
    /** @var EventManager */
59
    private $eventManager;
60
61
    public function __construct()
62
    {
63
        $this->cacheDir = sys_get_temp_dir() . '/doctrine-rst-parser';
64
65
        $this->eventManager = new EventManager();
66
    }
67
68
    public function getCacheDir() : string
69
    {
70
        return $this->cacheDir;
71
    }
72
73
    public function setCacheDir(string $cacheDir) : void
74
    {
75
        $this->cacheDir = $cacheDir;
76
    }
77
78
    public function getTemplateRenderer() : TemplateRenderer
79
    {
80
        return $this->templateRenderer;
81
    }
82
83
    public function setTemplateRenderer(TemplateRenderer $templateRenderer) : void
84
    {
85
        $this->templateRenderer = $templateRenderer;
86
    }
87
88
    /**
89
     * @return mixed|TwigEnvironment
90
     */
91
    public function getTemplateEngine()
92
    {
93
        return $this->templateRenderer->getTemplateEngine();
94
    }
95
96
    public function getTheme() : string
97
    {
98
        return $this->theme;
99
    }
100
101
    public function setTheme(string $theme) : void
102
    {
103
        $this->theme = $theme;
104
    }
105
106
    public function getBaseUrl() : string
107
    {
108
        return $this->baseUrl;
109
    }
110
111
    public function setBaseUrl(string $baseUrl) : self
112
    {
113
        $this->baseUrl = $baseUrl;
114
115
        return $this;
116
    }
117
118
    public function setBaseUrlEnabledCallable(?callable $baseUrlEnabledCallable) : void
119
    {
120
        $this->baseUrlEnabledCallable = $baseUrlEnabledCallable;
121
    }
122
123
    public function getBaseUrlEnabledCallable() : ?callable
124
    {
125
        return $this->baseUrlEnabledCallable;
126
    }
127
128
    public function isBaseUrlEnabled(string $path) : bool
129
    {
130
        if ($this->baseUrl === '') {
131
            return false;
132
        }
133
134
        if ($this->baseUrlEnabledCallable !== null) {
135
            /** @var callable $baseUrlEnabledCallable */
136
            $baseUrlEnabledCallable = $this->baseUrlEnabledCallable;
137
138
            return $baseUrlEnabledCallable($path);
139
        }
140
141
        return true;
142
    }
143
144
    public function getIgnoreInvalidReferences() : bool
145
    {
146
        return $this->ignoreInvalidReferences;
147
    }
148
149
    public function setIgnoreInvalidReferences(bool $ignoreInvalidReferences) : void
150
    {
151
        $this->ignoreInvalidReferences = $ignoreInvalidReferences;
152
    }
153
154
    public function setIndentHTML(bool $indentHTML) : void
155
    {
156
        $this->indentHTML = $indentHTML;
157
    }
158
159
    public function getIndentHTML() : bool
160
    {
161
        return $this->indentHTML;
162
    }
163
164
    public function setInitialHeaderLevel(int $initialHeaderLevel) : void
165
    {
166
        $this->initialHeaderLevel = $initialHeaderLevel;
167
    }
168
169
    public function getInitialHeaderLevel() : int
170
    {
171
        return $this->initialHeaderLevel;
172
    }
173
174
    public function setUseCachedMetas(bool $useCachedMetas) : void
175
    {
176
        $this->useCachedMetas = $useCachedMetas;
177
    }
178
179
    public function getUseCachedMetas() : bool
180
    {
181
        return $this->useCachedMetas;
182
    }
183
184
    public function getFileExtension() : string
185
    {
186
        return $this->fileExtension;
187
    }
188
189
    public function setFileExtension(string $fileExtension) : void
190
    {
191
        $this->fileExtension = $fileExtension;
192
    }
193
194
    public function getEventManager() : EventManager
195
    {
196
        return $this->eventManager;
197
    }
198
199
    public function addFormat(Format $format) : void
200
    {
201
        $this->formats[$format->getFileExtension()] = $format;
202
    }
203
204
    public function getFormat() : Format
205
    {
206
        if (! isset($this->formats[$this->fileExtension])) {
207
            throw new RuntimeException(
208
                sprintf('Format %s does not exist.', $this->fileExtension)
209
            );
210
        }
211
212
        return $this->formats[$this->fileExtension];
213
    }
214
215
    public function getNameOfIndexFile() : string
216
    {
217
        return $this->indexName;
218
    }
219
220
    public function getSourceFileExtension() : string
221
    {
222
        return $this->sourceFileExtension;
223
    }
224
}
225