Completed
Push — master ( d3d92b...e2ac41 )
by Park Jong-Hun
03:08
created

Application::setConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Core;
4
5
use JBZoo\Event\EventManager;
6
7
class Application
8
{
9
    private static $config = [];
10
11
    public static function setConfig(array $config)
12
    {
13
        self::$config = $config;
14
    }
15
16
    /**
17
     * Return url path with site url
18
     * @param  string $url sub url
19
     * @return string
20
     */
21
    public static function getUrl($url = '')
22
    {
23
        return self::getPrefixUrl(self::$config['url'], $url);
24
    }
25
26
    public static function getPublicUrl($url = '')
27
    {
28
        return self::getPrefixUrl(self::$config['publicPath'], $url);
29
    }
30
31
    private static function getPrefixUrl($prefix, $path)
32
    {
33
        $prefix = $prefix . (substr($prefix, -1) !== '/' ? '/' : '');
34
        $path = substr($path, 0, 1) === '/' ? substr($path, 1) : $path;
35
36
        return $prefix . $path;
37
    }
38
}
39