Completed
Push — EZP-26835-load-translation-pac... ( 513076...1a5c64 )
by Nicolas
12:39
created

GlobCollector::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the GlobCollector class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\Translation;
10
11
/**
12
 * Retrieves all installed ezplatform translation files ie those installed as ezsystems/ezplatform-i18n-* package
13
 */
14
class GlobCollector implements Collector
15
{
16
    /**
17
     * @var
18
     */
19
    protected $tranlationPattern;
20
21
    /**
22
     * @param string $kernelRootDir
23
     */
24
    public function __construct($kernelRootDir)
25
    {
26
        $this->tranlationPattern = $kernelRootDir . sprintf('%1$s..%1$svendor%1$sezsystems%1$sezplatform-i18n-*%1$s*%1$s*.xlf', DIRECTORY_SEPARATOR);
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function collect()
33
    {
34
        $meta = [];
35
        foreach (glob($this->tranlationPattern) as $file) {
36
            list($domain, $locale, $format) = explode('.', basename($file), 3);
37
            $meta[] = [
38
                'file' => $file,
39
                'domain' => $domain,
40
                'locale' => $locale,
41
                'format' => $format,
42
            ];
43
        }
44
45
        return $meta;
46
    }
47
}
48