Completed
Push — master ( 9154e6...0b8712 )
by Mihail
03:12
created

Alias::getVendor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Ffcms\Core;
4
5
use Ffcms\Core\Helper\Type\Arr;
6
use Ffcms\Core\Helper\Type\Obj;
7
use Ffcms\Core\Helper\Type\Str;
8
9
10
/**
11
 * Class Alias - fast alias for core property's
12
 * @package Ffcms\Core
13
 */
14
class Alias
15
{
16
17
    /**
18
     * Absolute path to current view folder
19
     * @var string
20
     */
21
    public $currentViewPath;
22
23
    /**
24
     * Return full URL of current view folder
25
     * @var string
26
     */
27
    public $currentViewUrl;
28
29
    /**
30
     * Current app basic domain address, obtained from request
31
     * @var string
32
     */
33
    public $baseDomain;
34
35
    /**
36
     * Current app basic URL without language path
37
     * @var string
38
     */
39
    public $baseUrlNoLang;
40
41
    /**
42
     * Current app basic URL address, obtained from request
43
     * @var string
44
     */
45
    public $baseUrl;
46
47
    /**
48
     * Current app basic URL without any changes in pathway(lang-defined, etc)
49
     * @var string
50
     */
51
    public $scriptUrl;
52
53
54
    /**
55
     * Default vendor library's
56
     * @var array
57
     */
58
    protected $vendorNamedLibrary = [
59
        'js' => null,
60
        'css' => null
61
    ];
62
63
    /**
64
     * Custom code library's
65
     * @var array
66
     */
67
    protected $codeCustomLibrary = [
68
        'js' => null,
69
        'css' => null
70
    ];
71
72
    /**
73
     * Custom code storage for templates
74
     * @var array
75
     */
76
    protected $plainCode = [
77
        'js' => null,
78
        'css' => null
79
    ];
80
81
82
    public function __construct()
83
    {
84
        // make alias for view pathway
85
        $this->currentViewPath = App::$View->themePath;
86
87
        // make alias for baseUrl, script url and domain
88
        $this->baseDomain = App::$Request->getHost();
89
        $this->scriptUrl = App::$Request->getSchemeAndHttpHost();
90
        if (App::$Properties->get('basePath') !== '/') {
91
            $this->scriptUrl .= rtrim(App::$Properties->get('basePath'), '/');
92
        }
93
        $this->baseUrl = $this->scriptUrl;
94
        if (App::$Request->getInterfaceSlug() !== null) {
95
            $this->baseUrl .= App::$Request->getInterfaceSlug();
96
        }
97
98
        $this->baseUrlNoLang = $this->baseUrl;
99
        if (App::$Request->languageInPath() && App::$Request->getLanguage() !== null) {
100
            $this->baseUrl .= '/' . App::$Request->getLanguage();
101
        }
102
103
        // build vendor libs alias
104
        $this->vendorNamedLibrary['js']['jquery'] = $this->scriptUrl . '/vendor/bower/jquery/dist/jquery.min.js';
105
        $this->vendorNamedLibrary['css']['bootstrap'] = $this->scriptUrl . '/vendor/bower/bootstrap/dist/css/bootstrap.min.css';
106
        $this->vendorNamedLibrary['js']['bootstrap'] = $this->scriptUrl . '/vendor/bower/bootstrap/dist/js/bootstrap.min.js';
107
        $this->vendorNamedLibrary['css']['fa'] = $this->scriptUrl . '/vendor/bower/components-font-awesome/css/font-awesome.min.css';
108
        $this->vendorNamedLibrary['js']['jquery-ui'] = $this->scriptUrl . '/vendor/bower/jquery-ui/jquery-ui.min.js';
109
        $this->vendorNamedLibrary['css']['jquery-ui'] = $this->scriptUrl . '/vendor/bower/jquery-ui/themes/base/jquery-ui.min.css';
110
111
        $themeAll = App::$Properties->get('theme');
112
        if (!isset($themeAll[env_name]) || Str::length($themeAll[env_name]) < 1) {
113
            $themeAll[env_name] = 'default';
114
        }
115
        $this->currentViewUrl = $this->scriptUrl . '/Apps/View/' . env_name . '/' . $themeAll[env_name];
116
    }
117
118
    /**
119
     * @param string $type
120
     * @param string $name
121
     * @return string|null
122
     */
123
    public function getVendor($type, $name)
124
    {
125
        return $this->vendorNamedLibrary[$type][$name];
126
    }
127
128
    /**
129
     * Set custom library $link by $type
130
     * @param string $type
131
     * @param string $link
132
     */
133
    public function setCustomLibrary($type, $link)
134
    {
135
        $this->codeCustomLibrary[$type][] = $link;
136
    }
137
138
    /**
139
     * Get custom library array by type
140
     * @param string $type
141
     * @return array|null
142
     */
143
    public function getCustomLibraryArray($type)
144
    {
145
        return $this->codeCustomLibrary[$type];
146
    }
147
148
    /**
149
     * Unset custom library's by type
150
     * @param $type
151
     */
152
    public function unsetCustomLibrary($type)
153
    {
154
        unset($this->codeCustomLibrary[$type]);
155
    }
156
157
    /**
158
     * @param string $type
159
     * @param string $code
160
     * @return bool
161
     */
162
    public function addPlainCode($type, $code)
163
    {
164
        $allowed = ['css', 'js'];
165
        if (!Arr::in($type, $allowed)) {
166
            return false;
167
        }
168
169
        $this->plainCode[$type][] = $code;
170
        return true;
171
    }
172
173
    /**
174
     * Get plain code build container as string
175
     * @param string $type
176
     * @return null|string
177
     */
178
    public function getPlainCode($type)
179
    {
180
        return $this->plainCode[$type];
181
    }
182
183
184
}