GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( fda5f3...39ed76 )
by Steeven
03:31
created

Theme::getPublicPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Containers\Modules\DataStructures\Module;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\DataStructures\SplArrayObject;
19
use O2System\Spl\Info\SplDirectoryInfo;
20
use O2System\Spl\Info\SplFileInfo;
21
22
/**
23
 * Class Theme
24
 *
25
 * @package O2System\Framework\Containers\Modules\DataStructures\Module
26
 */
27
class Theme extends SplDirectoryInfo
28
{
29
    /**
30
     * Theme Properties
31
     *
32
     * @var array
33
     */
34
    private $properties = [];
35
36
    /**
37
     * Theme Presets
38
     *
39
     * @var array
40
     */
41
    private $presets = [];
42
43
    /**
44
     * Theme Layout
45
     *
46
     * @var Theme\Layout
47
     */
48
    private $layout;
49
50
    /**
51
     * Theme::__construct
52
     *
53
     * @param string $dir
54
     */
55
    public function __construct($dir)
56
    {
57
        parent::__construct($dir);
58
59
        // Set Theme Properties
60
        if (is_file($propFilePath = $dir . 'theme.json')) {
61
            $properties = json_decode(file_get_contents($propFilePath), true);
62
63
            if (json_last_error() === JSON_ERROR_NONE) {
64
                if (isset($properties[ 'config' ])) {
65
                    $this->presets = $properties[ 'presets' ];
66
                    unset($properties[ 'presets' ]);
67
                }
68
69
                $this->properties = $properties;
70
            }
71
        }
72
73
        // Set Default Theme Layout
74
        $this->setLayout('theme');
75
    }
76
77
    // ------------------------------------------------------------------------
78
79
    /**
80
     * Theme::isValid
81
     *
82
     * @return bool
83
     */
84
    public function isValid()
85
    {
86
        if (count($this->properties)) {
87
            return true;
88
        }
89
90
        return false;
91
    }
92
93
    // ------------------------------------------------------------------------
94
95
    /**
96
     * Theme::getParameter
97
     *
98
     * @return string
99
     */
100
    public function getParameter()
101
    {
102
        return $this->getDirName();
103
    }
104
105
    // ------------------------------------------------------------------------
106
107
    /**
108
     * Theme::getCode
109
     *
110
     * @return string
111
     */
112
    public function getCode()
113
    {
114
        return strtoupper(substr(md5($this->getDirName()), 2, 7));
115
    }
116
117
    // ------------------------------------------------------------------------
118
119
    /**
120
     * Theme::getChecksum
121
     *
122
     * @return string
123
     */
124
    public function getChecksum()
125
    {
126
        return md5($this->getMTime());
127
    }
128
129
    // ------------------------------------------------------------------------
130
131
    /**
132
     * Theme::getProperties
133
     *
134
     * @return \O2System\Spl\DataStructures\SplArrayObject
135
     */
136
    public function getProperties()
137
    {
138
        return new SplArrayObject($this->properties);
139
    }
140
141
    // ------------------------------------------------------------------------
142
143
    /**
144
     * Theme::getPresets
145
     *
146
     * @return \O2System\Spl\DataStructures\SplArrayObject
147
     */
148
    public function getPresets()
149
    {
150
        return new SplArrayObject($this->presets);
151
    }
152
153
    // ------------------------------------------------------------------------
154
155
    /**
156
     * Theme::getUrl
157
     *
158
     * @param string|null $path
159
     *
160
     * @return string
161
     */
162
    public function getUrl($path = null)
163
    {
164
        return path_to_url($this->getRealPath() . $path);
165
    }
166
167
    // ------------------------------------------------------------------------
168
169
    /**
170
     * Theme::getPublicPath
171
     */
172
    public function getPublicPath()
173
    {
174
        return str_replace(PATH_RESOURCES, PATH_PUBLIC, $this->getRealPath());
175
    }
176
177
    /**
178
     * Theme::load
179
     *
180
     * @return static
181
     */
182
    public function load()
183
    {
184
        if ($this->getPresets()->offsetExists('assets')) {
185
            presenter()->assets->autoload($this->getPresets()->offsetGet('assets'));
186
        }
187
188
        presenter()->assets->loadCss('theme');
189
        presenter()->assets->loadJs('theme');
190
191
        // Autoload default theme layout
192
        $this->loadLayout();
193
194
        return $this;
195
    }
196
197
    // ------------------------------------------------------------------------
198
199
    /**
200
     * Theme::hasLayout
201
     * 
202
     * @return bool
203
     */
204
    public function hasLayout($layout)
205
    {
206
        $extensions = ['.php', '.phtml', '.html', '.tpl'];
207
208
        if (isset($this->presets[ 'extensions' ])) {
209
            array_unshift($partialsExtensions, $this->presets[ 'extension' ]);
210
        } elseif (isset($this->presets[ 'extension' ])) {
211
            array_unshift($extensions, $this->presets[ 'extension' ]);
212
        }
213
214
        $found = false;
215
        foreach ($extensions as $extension) {
216
            $extension = trim($extension, '.');
217
218
            if ($layout === 'theme') {
219
                $layoutFilePath = $this->getRealPath() . 'theme.' . $extension;
220
            } else {
221
                $layoutFilePath = $this->getRealPath() . 'layouts' . DIRECTORY_SEPARATOR . dash($layout) . DIRECTORY_SEPARATOR . 'layout.' . $extension;
222
            }
223
224
            if (is_file($layoutFilePath)) {
225
                $found = true;
226
                break;
227
            }
228
        }
229
230
        return (bool) $found;
231
    }
232
233
    // ------------------------------------------------------------------------
234
235
    /**
236
     * Theme::setLayout
237
     *
238
     * @param string $layout
239
     *
240
     * @return static
241
     */
242
    public function setLayout($layout)
243
    {
244
        $extensions = ['.php', '.phtml', '.html', '.tpl'];
245
246
        if (isset($this->presets[ 'extensions' ])) {
247
            array_unshift($partialsExtensions, $this->presets[ 'extension' ]);
248
        } elseif (isset($this->presets[ 'extension' ])) {
249
            array_unshift($extensions, $this->presets[ 'extension' ]);
250
        }
251
252
        foreach ($extensions as $extension) {
253
            $extension = trim($extension, '.');
254
255
            if ($layout === 'theme') {
256
                $layoutFilePath = $this->getRealPath() . 'theme.' . $extension;
257
            } else {
258
                $layoutFilePath = $this->getRealPath() . 'layouts' . DIRECTORY_SEPARATOR . dash($layout) . DIRECTORY_SEPARATOR . 'layout.' . $extension;
259
            }
260
261
            if (is_file($layoutFilePath)) {
262
                $this->layout = new Theme\Layout($layoutFilePath);
263
                //$this->loadLayout();
264
                break;
265
            }
266
        }
267
268
        return $this;
269
    }
270
271
    // ------------------------------------------------------------------------
272
273
    /**
274
     * Theme::getLayout
275
     *
276
     * @return Theme\Layout
277
     */
278
    public function getLayout()
279
    {
280
        return $this->layout;
281
    }
282
283
    // ------------------------------------------------------------------------
284
285
    /**
286
     * Theme::loadLayout
287
     *
288
     * @return static
289
     */
290
    protected function loadLayout()
291
    {
292
        if ($this->layout instanceof Theme\Layout) {
0 ignored issues
show
introduced by
$this->layout is always a sub-type of O2System\Framework\Conta...res\Module\Theme\Layout.
Loading history...
293
            // add theme layout public directory
294
            loader()->addPublicDir($this->layout->getPath() . 'assets');
295
296
            presenter()->assets->autoload(
297
                [
298
                    'css' => ['layout'],
299
                    'js'  => ['layout'],
300
                ]
301
            );
302
303
            $partials = $this->layout->getPartials()->getArrayCopy();
304
305
            foreach ($partials as $offset => $partial) {
306
                if ($partial instanceof SplFileInfo) {
307
                    presenter()->partials->addPartial($offset, $partial->getPathName());
308
                }
309
            }
310
        }
311
312
        return $this;
313
    }
314
}