Completed
Push — master ( 396a44...7d840c )
by Tobias
11:02
created

Configuration::getDirs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\Model;
13
14
/**
15
 * This class is a PHP representation of `translation.configs.xxx`.
16
 *
17
 * @author Tobias Nyholm <[email protected]>
18
 */
19
final class Configuration
20
{
21
    /**
22
     * @var string
23
     */
24
    private $name;
25
26
    /**
27
     * @var array
28
     */
29
    private $locales;
30
31
    /**
32
     * Usually dirname('kernel.root_dir').
33
     *
34
     * @var string
35
     */
36
    private $projectRoot;
37
38
    /**
39
     * This is where we dump all translations.
40
     *
41
     * @var string
42
     */
43
    private $outputDir;
44
45
    /**
46
     * The absolute path to folders we scan for translations.
47
     *
48
     * @var array
49
     */
50
    private $dirs;
51
52
    /**
53
     * Directories we should not extract translations from.
54
     *
55
     * @var array
56
     */
57
    private $excludedDirs;
58
59
    /**
60
     * File names we should not extract translations from.
61
     *
62
     * @var array
63
     */
64
    private $excludedNames;
65
66
    /**
67
     * Directories that holds translation files but is out of our control.
68
     *
69
     * @var array
70
     */
71
    private $externalTranslationsDirs;
72
73
    /**
74
     * The format we store translation files in.
75
     *
76
     * @var string
77
     */
78
    private $outputFormat;
79
80
    /**
81
     * @var array
82
     */
83
    private $blacklistDomains;
84
85
    /**
86
     * @var array
87
     */
88
    private $whitelistDomains;
89
90
    /**
91
     * @var string
92
     */
93
    private $xliffVersion;
94
95
    /**
96
     * @param array $data
97
     */
98 17
    public function __construct(array $data)
99
    {
100 17
        $this->name = $data['name'];
101 17
        $this->locales = $data['locales'];
102 17
        $this->projectRoot = $data['project_root'];
103 17
        $this->outputDir = $data['output_dir'];
104 17
        $this->dirs = $data['dirs'];
105 17
        $this->excludedDirs = $data['excluded_dirs'];
106 17
        $this->excludedNames = $data['excluded_names'];
107 17
        $this->externalTranslationsDirs = $data['external_translations_dirs'];
108 17
        $this->outputFormat = $data['output_format'];
109 17
        $this->blacklistDomains = $data['blacklist_domains'];
110 17
        $this->whitelistDomains = $data['whitelist_domains'];
111 17
        $this->xliffVersion = $data['xliff_version'];
112 17
    }
113
114
    /**
115
     * @return string
116
     */
117 3
    public function getName()
118
    {
119 3
        return $this->name;
120
    }
121
122
    /**
123
     * @return array
124
     */
125 3
    public function getLocales()
126
    {
127 3
        return $this->locales;
128
    }
129
130
    /**
131
     * @return string
132
     */
133 2
    public function getProjectRoot()
134
    {
135 2
        return $this->projectRoot;
136
    }
137
138
    /**
139
     * @return string
140
     */
141 8
    public function getOutputDir()
142
    {
143 8
        return $this->outputDir;
144
    }
145
146
    /**
147
     * @return array
148
     */
149 2
    public function getDirs()
150
    {
151 2
        return $this->dirs;
152
    }
153
154
    /**
155
     * @return array
156
     */
157 2
    public function getExcludedDirs()
158
    {
159 2
        return $this->excludedDirs;
160
    }
161
162
    /**
163
     * @return array
164
     */
165 2
    public function getExcludedNames()
166
    {
167 2
        return $this->excludedNames;
168
    }
169
170
    /**
171
     * @return array
172
     */
173 1
    public function getExternalTranslationsDirs()
174
    {
175 1
        return $this->externalTranslationsDirs;
176
    }
177
178
    /**
179
     * @return string
180
     */
181 2
    public function getOutputFormat()
182
    {
183 2
        return $this->outputFormat;
184
    }
185
186
    /**
187
     * @return array
188
     */
189 2
    public function getBlacklistDomains()
190
    {
191 2
        return $this->blacklistDomains;
192
    }
193
194
    /**
195
     * @return array
196
     */
197 2
    public function getWhitelistDomains()
198
    {
199 2
        return $this->whitelistDomains;
200
    }
201
202
    /**
203
     * Get all paths where translation paths are stored. Both external files and
204
     * files created by us.
205
     *
206
     * @return array
207
     */
208 6
    public function getPathsToTranslationFiles()
209
    {
210 6
        return array_merge($this->externalTranslationsDirs, [$this->getOutputDir()]);
211
    }
212
213
    /**
214
     * @return string
215
     */
216 2
    public function getXliffVersion()
217
    {
218 2
        return $this->xliffVersion;
219
    }
220
221
    /**
222
     * Reconfigures the directories so we can use one configuration for extracting
223
     * the messages only from one bundle.
224
     *
225
     * @param string $bundleDir
226
     * @param string $outputDir
227
     */
228
    public function reconfigureBundleDirs($bundleDir, $outputDir)
229
    {
230
        $this->dirs = is_array($bundleDir) ? $bundleDir : [$bundleDir];
231
        $this->outputDir = $outputDir;
232
    }
233
}
234