Passed
Push — master ( ff8ca7...001f87 )
by Julien
05:55 queued 01:01
created

ServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 1
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Provider\Translate;
13
14
use Phalcon\Di\DiInterface;
15
use Phalcon\Translate\Adapter\Gettext;
16
use Phalcon\Translate\InterpolatorFactory;
17
use Zemit\Config\ConfigInterface;
18
use Zemit\Provider\AbstractServiceProvider;
19
20
class ServiceProvider extends AbstractServiceProvider
21
{
22
    protected string $serviceName = 'translate';
23
    
24 23
    public function register(DiInterface $di): void
25
    {
26 23
        $di->setShared($this->getName(), function () use ($di) {
27
            
28 2
            $config = $di->get('config');
29 2
            assert($config instanceof ConfigInterface);
30 2
            $translateConfig = $config->pathToArray('translate') ?? [];
31
            
32 2
            $translate = new Gettext(new InterpolatorFactory(), $translateConfig);
33 2
            $translate->setLocale(LC_MESSAGES, [$di->get('locale')->get() . '.utf8']);
34
            
35 2
            return $translate;
36 23
        });
37
    }
38
}
39