Test Failed
Push — master ( c9926a...5520e1 )
by Julien
04:42
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 12
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 2
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\Url;
13
14
use Phalcon\Di\DiInterface;
15
use Phalcon\Mvc;
16
use Zemit\Mvc\Url;
17
use Zemit\Config\ConfigInterface;
18
use Zemit\Provider\AbstractServiceProvider;
19
20
class ServiceProvider extends AbstractServiceProvider
21
{
22
    protected string $serviceName = 'url';
23
    
24
    public function register(DiInterface $di): void
25
    {
26
        $di->setShared($this->getName(), function () use ($di) {
27
            
28
            $config = $di->get('config');
29
            assert($config instanceof ConfigInterface);
30
            $urlConfig = $config->pathToArray('ur') ?? [];
31
            
32
            $router = $di->get('router');
33
            $url = new Url($router instanceof Mvc\RouterInterface ? $router : null);
34
            $url->setStaticBaseUri($urlConfig['staticBaseUri'] ?? '/');
35
            $url->setBaseUri($urlConfig['baseUri'] ?? '/');
36
            $url->setBasePath($urlConfig['basePath'] ?? '/');
37
            $url->setDI($di);
38
            
39
            return $url;
40
        });
41
    }
42
}
43