class MenuItem extends RootMenuItem

Main package functionality lies here; It is used to create sub-elements or to add attributes to a menu item, either by using magic method or magic assignments.

Traits

Implements an add function that inserts MenuItem references; Used in RootMenuItem and MenuItem (by subclassing)

Properties

protected $_items from RootMenuItem

Methods

add(string $title, string|array|null $config = null)

Adds a new underlying (submenu) MenuItem;

items()

No description

hasSubItems()

No description

replaceItemName($old, $new)

No description

mixed|null
__get($name)

Gets a submenu item using magic

getIterator()

Retrieve an external iterator

boolean
offsetExists(mixed $offset)

Whether a offset exists

mixed
offsetGet(mixed $offset)

Offset to retrieve

void
offsetSet(mixed $offset, mixed $value)

No description

void
offsetUnset(mixed $offset)

Offset to unset

string
toJson(int $options)

Convert the object to its JSON representation.

int
count()

Count elements of an object

mixed
jsonSerialize()

Specify data which should be serialized to JSON

toArray()

No description

$this
route(string $route, array $params = [], bool $addToMatches = true)

Sets the url parameter to the resolved value of $route

$this
matches($m)

Adds a match for a URL (path) or a route name.

$this
remove(string $slug)

Removes an item from the menu item configuration. Also works on sub-menus.

null|string
makeTag($item)

Creates an HTML Tag out of the item

$this
strict(bool $strict = true)

Enabled strict mode (This means that query params are also evaluated). Full URL is then required to match.

boolean
hasActiveSubMenu()

Checks if a sub-menu is active

$this
slug($new_slug)

Changes the slug-name of the element. This is useful when you want to make it easier for other people to extend your menus.

$this
setParent($parent)

No description

bool
active()

Returns true if the element is active. Checked against the current path, as well as the current route, and the matches set in the matches method.

__set($name, $value)

Sets a variable to a value (Direct assignement)

$this
__call($name, $arguments)

Sets a variable to a value (function chaining method) If nothing is passed as parameter,

applyConfig(array $config)

No description

Details

in CreatesMenuItems at line 48
MenuItem add(string $title, string|array|null $config = null)

Adds a new underlying (submenu) MenuItem;

Parameters

string $title The title of your menu item. The slug will be assigned automatically via snake_case if you did not assign one using the next argument's array config or
string|array|null $config $config can either be a string, array or null. Each of those choices will have an impact on the returned data. * String (Always returns $this): 1. Giving "/dashboard" will give it a direct URL (relative or not, depending if you preceed it with a /) 2. Giving it "route:admin.dashboard" will resolve the route and assign it to the menu item's url. To add route parameters, you can do "route:admin.dashboard|url,1|user,2", which will create the route with the "url" param as "1" and "user" as "2" * Array (Always returns $this): 1. By giving it an array, you directly specify the configuration and additional data to be passed to the menu item. This allows for quick configuration, rapidly, and directly onto the add function. 2. To set the route, use the route key, for a url, use the url key. * Null (Always returns a new MenuInstance class): 1. Normally, this is used for sub-menus. You can do something simply, like $menu->add('Dashboard')->route('admin.dashboard')

Return Value

MenuItem

in RootMenuItem at line 30
items()

in RootMenuItem at line 43
hasSubItems()

in RootMenuItem at line 54
replaceItemName($old, $new)

Parameters

$old
$new

in RootMenuItem at line 76
mixed|null __get($name)

Gets a submenu item using magic

Parameters

$name

Return Value

mixed|null

in RootMenuItem at line 89
Traversable getIterator()

Retrieve an external iterator

Return Value

Traversable An instance of an object implementing Iterator or Traversable

in RootMenuItem at line 109
boolean offsetExists(mixed $offset)

Whether a offset exists

Parameters

mixed $offset An offset to check for.

Return Value

boolean true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

in RootMenuItem at line 126
mixed offsetGet(mixed $offset)

Offset to retrieve

Parameters

mixed $offset The offset to retrieve.

Return Value

mixed Can return all value types.

at line 229
void offsetSet(mixed $offset, mixed $value)

Parameters

mixed $offset The offset to assign the value to.
mixed $value The value to set.

Return Value

void

in RootMenuItem at line 163
void offsetUnset(mixed $offset)

Offset to unset

Parameters

mixed $offset The offset to unset.

Return Value

void

in RootMenuItem at line 175
string toJson(int $options)

Convert the object to its JSON representation.

Parameters

int $options

Return Value

string

in RootMenuItem at line 190
int count()

Count elements of an object

Return Value

int The custom count as an integer.

The return value is cast to an integer.

in RootMenuItem at line 203
mixed jsonSerialize()

Specify data which should be serialized to JSON

Return Value

mixed data which can be serialized by json_encode, which is a value of any type other than a resource.

in RootMenuItem at line 208
toArray()

at line 32
$this route(string $route, array $params = [], bool $addToMatches = true)

Sets the url parameter to the resolved value of $route

Parameters

string $route The route to resolve
array $params Additional parameters
bool $addToMatches

Return Value

$this

at line 55
$this matches($m)

Adds a match for a URL (path) or a route name.

This will affect the output of the active method. A wildcard identifier (*) is also acceptable to match any wildcard URL. (Useful for filters).

Parameters

$m

Return Value

$this

at line 73
$this remove(string $slug)

Removes an item from the menu item configuration. Also works on sub-menus.

Parameters

string $slug

Return Value

$this

at line 87
null|string makeTag($item)

Creates an HTML Tag out of the item

Parameters

$item

Return Value

null|string

at line 104
$this strict(bool $strict = true)

Enabled strict mode (This means that query params are also evaluated). Full URL is then required to match.

Parameters

bool $strict

Return Value

$this

at line 116
boolean hasActiveSubMenu()

Checks if a sub-menu is active

Return Value

boolean

at line 139
$this slug($new_slug)

Changes the slug-name of the element. This is useful when you want to make it easier for other people to extend your menus.

Parameters

$new_slug

Return Value

$this

at line 158
$this setParent($parent)

Parameters

$parent

Return Value

$this

at line 171
bool active()

Returns true if the element is active. Checked against the current path, as well as the current route, and the matches set in the matches method.

Return Value

bool

at line 205
__set($name, $value)

Sets a variable to a value (Direct assignement)

Parameters

$name
$value

at line 219
$this __call($name, $arguments)

Sets a variable to a value (function chaining method) If nothing is passed as parameter,

Parameters

$name
$arguments

Return Value

$this

at line 234
protected applyConfig(array $config)

Parameters

array $config