Completed
Push — master ( 8ffed2...c2606f )
by Cheren
03:01
created

Theme::get()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.2
cc 4
eloc 11
nc 6
nop 1
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Core
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Core".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core;
17
18
use Cake\Core\App;
19
use JBZoo\Utils\FS;
20
use Cake\Core\Configure;
21
22
/**
23
 * Class Theme
24
 *
25
 * @package Core
26
 */
27
class Theme extends Plugin
28
{
29
30
    /**
31
     * Get current theme.
32
     *
33
     * @param null $prefix
34
     * @return mixed|string
35
     */
36
    public static function get($prefix = null)
37
    {
38
        $theme = ($prefix == 'admin') ? Configure::read('Theme.admin') : Configure::read('Theme.site');
39
        $path = self::_find($theme);
40
41
        if ($path !== null) {
42
            self::loadList([$theme]);
43
            $config = self::getData($theme, 'meta');
44
            if ($config->get('type') == 'theme') {
45
                return $theme;
46
            } else {
47
                self::unload($theme);
48
            }
49
        }
50
51
        return null;
52
    }
53
54
    /**
55
     * Find theme plugin in path.
56
     *
57
     * @param string $theme
58
     * @return null|string
59
     */
60
    protected static function _find($theme)
61
    {
62
        $paths = App::path('Plugin');
63
        foreach ($paths as $path) {
64
            $path = FS::clean($path . '/', DS);
65
            $themeFolder = $path . $theme;
66
67
            if (FS::isDir($themeFolder)) {
68
                return $themeFolder;
69
            }
70
        }
71
72
        return null;
73
    }
74
}
75