PHP Класс Spatie\Menu\Menu

Наследование: implements Spatie\Menu\Item, implements Countabl\Countable, implements Spatie\Menu\HasHtmlAttributes, implements Spatie\Menu\HasParentAttributes, use trait Spatie\Menu\Traits\HasHtmlAttributes, use trait Spatie\Menu\Traits\HasParentAttributes
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$activeClass string
$append
$filters array
$htmlAttributes
$items array
$parentAttributes
$prepend
$wrap array

Открытые методы

Метод Описание
__toString ( ) : string
add ( Spatie\Menu\Item $item ) Add an item to the menu. This also applies all registered filters to the item.
addIf ( boolean $condition, Spatie\Menu\Item $item ) Add an item to the menu if a (non-strict) condition is met.
addItemClass ( string $class ) Add a class to all items in the menu.
addItemParentClass ( string $class ) Add a parent class to all items in the menu.
append ( string $append ) Append a string of html to the menu on render.
appendIf ( boolean $condition, string $append ) : static Append the menu with a string of html on render if a certain condition is met.
applyToAll ( callable $callable ) Apply a callable to all existing items, and register it as a filter so it will get applied to all new items too. If you typehint the item parameter in the callable, it wil only be applied to items of that type.
blueprint ( ) : static Create a empty blueprint of the menu (copies filters and activeClass).
build ( array | Iterator $items, callable $callback, Menu $initial = null ) : static Build a new menu from an array. The callback receives a menu instance as the accumulator, the array item as the second parameter, and the item's key as the third.
count ( ) : integer The amount of items in the menu.
each ( callable $callable ) Iterate over all the items and apply a callback. If you typehint the item parameter in the callable, it wil only be applied to items of that type.
fill ( array | Iterator $items, callable $callback ) : static Fill a menu from an array. The callback receives a menu instance as the accumulator, the array item as the second parameter, and the item's key as the third.
html ( string $html, array $parentAttributes = [] ) Shortcut function to add raw html to the menu.
htmlIf ( boolean $condition, string $html, array $parentAttributes = [] ) Add a chunk of html if a (non-strict) condition is met.
isActive ( ) : boolean Determine whether the menu is active.
link ( string $url, string $text ) Shortcut function to add a plain link to the menu.
linkIf ( boolean $condition, string $url, string $text ) Add a link to the menu if a (non-strict) condition is met.
new ( array $items = [] ) : static Create a new menu, optionally prefilled with items.
prepend ( string $prepend ) Prepend the menu with a string of html on render.
prependIf ( boolean $condition, string $prepend ) Prepend the menu with a string of html on render if a certain condition is met.
registerFilter ( callable $callable ) Register a filter to the menu. When an item is added, all filters will be applied to the item. If you typehint the item parameter in the callable, it will only be applied to items of that type.
render ( ) : string Render the menu.
setActive ( callable | string $urlOrCallable, string $root = '/' ) Set multiple items in the menu as active based on a callable that filters through items. If you typehint the item parameter in the callable, it will only be applied to items of that type.
setActiveClass ( string $class ) Set the class name that will be used on active items for this menu.
setActiveFromCallable ( callable $callable )
setActiveFromUrl ( string $url, string $root = '/' ) Set all relevant children active based on the current request's URL.
setItemAttribute ( string $attribute, string $value = '' ) Set an attribute on all items in the menu.
setItemParentAttribute ( string $attribute, string $value = '' ) Add a parent attribute to all items in the menu.
submenu ( callable | Menu | Spatie\Menu\Item $header, callable | Menu | null $menu = null )
submenuIf ( boolean $condition, callable | Menu | Spatie\Menu\Item $header, callable | Menu | null $menu = null )
wrap ( string $element, array $attributes = [] ) Wrap the menu in an html element.

Защищенные методы

Метод Описание
__construct ( variadic $items )
applyFilter ( callable $filter, Spatie\Menu\Item $item ) Apply a filter to an item. Returns the result of the filter.
createSubmenuHeader ( Spatie\Menu\Item | string $header ) : string
createSubmenuMenu ( Menu | callable $menu ) : Menu
parseSubmenuArgs ( $args ) : array

Описание методов

__construct() защищенный Метод

protected __construct ( variadic $items )
$items variadic

__toString() публичный Метод

public __toString ( ) : string
Результат string

add() публичный Метод

Add an item to the menu. This also applies all registered filters to the item.
public add ( Spatie\Menu\Item $item )
$item Spatie\Menu\Item

addIf() публичный Метод

Add an item to the menu if a (non-strict) condition is met.
public addIf ( boolean $condition, Spatie\Menu\Item $item )
$condition boolean
$item Spatie\Menu\Item

addItemClass() публичный Метод

Add a class to all items in the menu.
public addItemClass ( string $class )
$class string

addItemParentClass() публичный Метод

Add a parent class to all items in the menu.
public addItemParentClass ( string $class )
$class string

append() публичный Метод

Append a string of html to the menu on render.
public append ( string $append )
$append string

appendIf() публичный Метод

Append the menu with a string of html on render if a certain condition is met.
public appendIf ( boolean $condition, string $append ) : static
$condition boolean
$append string
Результат static

applyFilter() защищенный Метод

Apply a filter to an item. Returns the result of the filter.
protected applyFilter ( callable $filter, Spatie\Menu\Item $item )
$filter callable
$item Spatie\Menu\Item

applyToAll() публичный Метод

Apply a callable to all existing items, and register it as a filter so it will get applied to all new items too. If you typehint the item parameter in the callable, it wil only be applied to items of that type.
public applyToAll ( callable $callable )
$callable callable

blueprint() публичный Метод

Create a empty blueprint of the menu (copies filters and activeClass).
public blueprint ( ) : static
Результат static

build() публичный статический Метод

Build a new menu from an array. The callback receives a menu instance as the accumulator, the array item as the second parameter, and the item's key as the third.
public static build ( array | Iterator $items, callable $callback, Menu $initial = null ) : static
$items array | Iterator
$callback callable
$initial Menu
Результат static

count() публичный Метод

The amount of items in the menu.
public count ( ) : integer
Результат integer

createSubmenuHeader() защищенный Метод

protected createSubmenuHeader ( Spatie\Menu\Item | string $header ) : string
$header Spatie\Menu\Item | string
Результат string

createSubmenuMenu() защищенный Метод

protected createSubmenuMenu ( Menu | callable $menu ) : Menu
$menu Menu | callable
Результат Menu

each() публичный Метод

Iterate over all the items and apply a callback. If you typehint the item parameter in the callable, it wil only be applied to items of that type.
public each ( callable $callable )
$callable callable

fill() публичный Метод

Fill a menu from an array. The callback receives a menu instance as the accumulator, the array item as the second parameter, and the item's key as the third.
public fill ( array | Iterator $items, callable $callback ) : static
$items array | Iterator
$callback callable
Результат static

html() публичный Метод

Shortcut function to add raw html to the menu.
public html ( string $html, array $parentAttributes = [] )
$html string
$parentAttributes array

htmlIf() публичный Метод

Add a chunk of html if a (non-strict) condition is met.
public htmlIf ( boolean $condition, string $html, array $parentAttributes = [] )
$condition boolean
$html string
$parentAttributes array

isActive() публичный Метод

Determine whether the menu is active.
public isActive ( ) : boolean
Результат boolean

linkIf() публичный Метод

Add a link to the menu if a (non-strict) condition is met.
public linkIf ( boolean $condition, string $url, string $text )
$condition boolean
$url string
$text string

new() публичный статический Метод

Create a new menu, optionally prefilled with items.
public static new ( array $items = [] ) : static
$items array
Результат static

parseSubmenuArgs() защищенный Метод

protected parseSubmenuArgs ( $args ) : array
Результат array

prepend() публичный Метод

Prepend the menu with a string of html on render.
public prepend ( string $prepend )
$prepend string

prependIf() публичный Метод

Prepend the menu with a string of html on render if a certain condition is met.
public prependIf ( boolean $condition, string $prepend )
$condition boolean
$prepend string

registerFilter() публичный Метод

Register a filter to the menu. When an item is added, all filters will be applied to the item. If you typehint the item parameter in the callable, it will only be applied to items of that type.
public registerFilter ( callable $callable )
$callable callable

render() публичный Метод

Render the menu.
public render ( ) : string
Результат string

setActive() публичный Метод

Set multiple items in the menu as active based on a callable that filters through items. If you typehint the item parameter in the callable, it will only be applied to items of that type.
public setActive ( callable | string $urlOrCallable, string $root = '/' )
$urlOrCallable callable | string
$root string

setActiveClass() публичный Метод

Set the class name that will be used on active items for this menu.
public setActiveClass ( string $class )
$class string

setActiveFromCallable() публичный Метод

public setActiveFromCallable ( callable $callable )
$callable callable

setActiveFromUrl() публичный Метод

, /about, /contact => request to /about will set the about link active. en, /en/about, /en/contact => request to /en won't set /en active if the request root is set to /en.
public setActiveFromUrl ( string $url, string $root = '/' )
$url string The current request url.
$root string If the link's URL is an exact match with the request root, the link won't be set active. This behavior is to avoid having home links active on every request.

setItemAttribute() публичный Метод

Set an attribute on all items in the menu.
public setItemAttribute ( string $attribute, string $value = '' )
$attribute string
$value string

setItemParentAttribute() публичный Метод

Add a parent attribute to all items in the menu.
public setItemParentAttribute ( string $attribute, string $value = '' )
$attribute string
$value string

submenu() публичный Метод

public submenu ( callable | Menu | Spatie\Menu\Item $header, callable | Menu | null $menu = null )
$header callable | Menu | Spatie\Menu\Item
$menu callable | Menu | null

submenuIf() публичный Метод

public submenuIf ( boolean $condition, callable | Menu | Spatie\Menu\Item $header, callable | Menu | null $menu = null )
$condition boolean
$header callable | Menu | Spatie\Menu\Item
$menu callable | Menu | null

wrap() публичный Метод

Wrap the menu in an html element.
public wrap ( string $element, array $attributes = [] )
$element string
$attributes array

Описание свойств

$activeClass защищенное свойство

protected string $activeClass
Результат string

$append защищенное свойство

protected $append

$filters защищенное свойство

protected array $filters
Результат array

$htmlAttributes защищенное свойство

protected $htmlAttributes

$items защищенное свойство

protected array $items
Результат array

$parentAttributes защищенное свойство

protected $parentAttributes

$prepend защищенное свойство

protected $prepend

$wrap защищенное свойство

protected array $wrap
Результат array