Menu::setActive()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.net)
4
 * @author Aleksandr Torosh <[email protected]>
5
 */
6
7
namespace Menu\Helper;
8
9
use Menu\Item;
10
11
class Menu
12
{
13
14
    private static $instance;
15
    private $active_items = [];
16
17
    public static function getInstance()
18
    {
19
        if (!self::$instance) {
20
            self::$instance = new Menu();
21
        }
22
        return self::$instance;
23
    }
24
25
    public function __construct()
26
    {
27
28
    }
29
30
    public function item($title, $id = null, $url = null, array $params = [], array $children = [])
31
    {
32
        $item = new Item($title, $id, $url, $params);
33
        if (!empty($children)) {
34
            $item->setChildren($children);
35
        }
36
        $item->setActiveItems($this->active_items);
37
        $item->make();
38
        return $item;
39
    }
40
41
    public function setActive($id)
42
    {
43
        if (!in_array($id, $this->active_items)) {
44
            $this->active_items[] = $id;
45
        }
46
    }
47
48
}