Completed
Push — master ( 648e7d...7ea321 )
by Mikołaj
03:46
created

AdminModel::flushCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Framework\Model;
4
5
use Rudolf\Component\Auth\Auth;
6
use Rudolf\Component\Helpers\Navigation\MenuItemCollection;
7
use Rudolf\Component\Modules\Manager as ModulesManager;
8
9
class AdminModel extends BaseModel
10
{
11
    /**
12
     * @var Auth
13
     */
14
    protected static $auth;
15
16
    /**
17
     * Returns Auth object.
18
     *
19
     * @return Auth
20
     */
21
    public function getAuth()
22
    {
23
        if (empty(self::$auth)) {
24
            self::$auth = new Auth($this->pdo, $this->prefix);
25
        }
26
27
        return self::$auth;
28
    }
29
30
    /**
31
     * @return MenuItemCollection
32
     */
33
    public function getMenuItems()
34
    {
35
        $modules = (new ModulesManager(MODULES_ROOT))->getCollection()->getActive();
36
37
        $collection = new MenuItemCollection();
38
39
        if (!empty($modules)) {
40
            foreach ($modules as $key => $value) {
41
                $file = MODULES_ROOT . '/' . $value->getName() . '/menu.php';
42
43
                if (is_file($file)) {
44
                    include $file;
45
                }
46
            }
47
        }
48
49
        return $collection;
50
    }
51
52
    public function flushCache($tableName = '')
53
    {
54
        if (!empty($tableName)) $table = $this->prefix . $tableName;
55
        else $table = $this->prefix . '*';
56
57
        array_map('unlink', glob(TEMP_ROOT . '/' . self::$config['engine'] . '/' . $table . '*'));
58
    }
59
}
60