forked from KnpLabs/KnpMenuBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.php
62 lines (54 loc) · 1.57 KB
/
Menu.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Knplabs\Bundle\MenuBundle;
/**
* A convenience class for creating the root node of a menu.
* Decoupled from Symfony2, can be used in any PHP 5.3 project.
* Originally taken from ioMenuPlugin (http://github.com/weaverryan/ioMenuPlugin)
*
* When creating the root menu object, you can use this class or the
* normal MenuItem class. For example, the following are equivalent:
* $menu = new Menu(array('class' => 'root'));
* $menu = new MenuItem(null, null, array('class' => 'root'));
*/
class Menu extends MenuItem
{
/**
* @var string
*/
protected $childClass;
/**
* Class constructor
*
* @see MenuItem
* @param array $attributes
* @param string $childClass The class to use if instantiating children menu items
*/
public function __construct($attributes = array(), $childClass = 'Knplabs\Bundle\MenuBundle\MenuItem')
{
$this->childClass = $childClass;
parent::__construct(null, null, $attributes);
}
public function initialize(array $options = array())
{
}
/**
* Overridden to specify what the child class should be
*/
protected function createChild($name, $route = null, $attributes = array(), $class = null)
{
if (null === $class)
{
$class = $this->childClass;
}
return parent::createChild($name, $route, $attributes, $class);
}
/**
* Get the class used to instanciate children
*
* @return string
**/
public function getChildClass()
{
return $this->childClass;
}
}