Manager::getMenu()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace Iatstuti\SimpleMenu;
4
5
/**
6
 * SimpleMenu manager
7
 *
8
 * @package    Iatstuti
9
 * @subpackage SimpleMenu
10
 * @copyright  2016 IATSTUTI
11
 * @author     Michael Dyrynda <[email protected]>
12
 */
13
class Manager
14
{
15
16
    /**
17
     * @var array
18
     */
19
    protected $menus = [ ];
20
21
22
    /**
23
     * Initialise a new menu.
24
     *
25
     * This will attach the menu to the array of menus,
26
     * which can later be retrieved for adding items.
27
     *
28
     * @param  string $name
29
     *
30
     * @return mixed
31
     */
32
    public function init($name)
33
    {
34
        if (! isset($this->menus[$name])) {
35
            $this->menus[$name] = new Menu();
36
        }
37
38
        return $this->menus[$name];
39
    }
40
41
42
    /**
43
     * Return a new menu item with the given label.
44
     *
45
     * @param  string $label
46
     * @param  array $options
47
     *
48
     * @return \Iatstuti\SimpleMenu\Menu
49
     */
50
    public function create($label, array $options = [ ])
51
    {
52
        return new Menu($label, $options);
53
    }
54
55
56
    /**
57
     * Return the menu for the given name, if available.
58
     *
59
     * @param  string $name
60
     *
61
     * @return \Iatstuti\SimpleMenu\Menu|null
62
     */
63
    public function getMenu($name)
64
    {
65
        return isset($this->menus[$name]) ? $this->menus[$name] : null;
66
    }
67
}
68