PHP Class Lavary\Menu\Builder

This provides the basic functionality to add, update and fetch menu items attached to a menu. Most of the functionality of this class is invoked using the menu facade.
See also: Facade
ファイルを表示 Open project: lavary/laravel-menu Class Usage Examples

Protected Properties

Property Type Description
$conf array The Menu configuration data
$groupStack array The route group attribute stack.
$items array The items container
$name string The Menu name
$reserved array The reserved attributes.

Public Methods

Method Description
__call ( string $method, array $args ) : Lavary\Menu\Item Search the menu based on an attribute
__construct ( $name, $conf ) : void Initializing the menu manager
__get ( $prop ) : Lavary\Menu\Item Returns menu item by name
add ( string $title, $options = '' ) : Lavary\Menu\Item Adds an item to the menu
all ( ) : array Return all items in the collection
asDiv ( $attributes = [], $childrenAttributes = [] ) : string Returns the menu as div containers
asOl ( $attributes = [], $childrenAttributes = [] ) : string Returns the menu as an ordered list.
asUl ( $attributes = [], $childrenAttributes = [] ) : string Returns the menu as an unordered list.
attributes ( array $attributes ) : string Build an HTML attribute string from an array.
conf ( string $key ) : string Return configuration value by key
dispatch ( $options ) : string Get the form action from the options.
divide ( array $attributes = [] ) : void Insert a separator after the item
extractAttributes ( array $options = [] ) : array Get the valid attributes from the options.
filter ( callable $callback ) : Lavary\Menu\Builder Filter menu items by user callbacks
filterRecursive ( string $attribute, mixed $value ) : Lavary\Menu\Collection Filter items recursively
find ( $id ) : Lavary\Menu\Item Returns menu item by Id
first ( ) : Lavary\Menu\Item Return the first item in the collection
formatGroupClass ( $new, $old ) : string Get the valid attributes from the options.
formatGroupPrefix ( array $new, array $old ) : string Format the prefix for the new group attributes.
get ( $title ) : Lavary\Menu\Item Returns menu item by name
getLastGroupPrefix ( ) : string Get the prefix from the last group on the stack.
group ( array $attributes, callable $closure ) : void Create a menu group with shared attributes.
isAbs ( string $url ) : boolean Check if the given url is an absolute url.
item ( $title ) : Lavary\Menu\Item Returns menu item by name
last ( ) : Lavary\Menu\Item Return the last item in the collection
mergeStatic ( $new = null, array $old = [] ) : string Merge item's attributes with a static string of attributes
raw ( $title, array $options = [] ) : Lavary\Menu\Item Add raw content
render ( string $type = 'ul', integer $parent = null, $childrenAttributes = [] ) : string Generate the menu items as list items using a recursive function
roots ( ) : Collection Returns items with no parent
sortBy ( $sort_by, string | callable $sort_type = 'asc' ) : Lavary\Menu\Builder Sorts the menu based on user's callable

Protected Methods

Method Description
attributeElement ( string $key, string $value ) : string Build a single attribute element.
getControllerAction ( array | string $options ) : string Get the action for an "action" option.
getRoute ( array | string $options ) : string Get the action for a "route" option.
getUrl ( array | string $options ) : string Get the action for a "url" option.
id ( ) : integer Generate an integer identifier for each new item
mergeGroup ( array $new, array $old ) : array Merge the given group attributes.
mergeWithLastGroup ( array $new ) : array Merge the given array with the last group stack.
prefix ( string $uri ) : string Prefix the given URI with the last prefix.
updateGroupStack ( array $attributes = [] ) : void Update the group stack with the given attributes.

Method Details

__call() public method

Search the menu based on an attribute
public __call ( string $method, array $args ) : Lavary\Menu\Item
$method string
$args array
return Lavary\Menu\Item

__construct() public method

Initializing the menu manager
public __construct ( $name, $conf ) : void
return void

__get() public method

Returns menu item by name
public __get ( $prop ) : Lavary\Menu\Item
return Lavary\Menu\Item

add() public method

Adds an item to the menu
public add ( string $title, $options = '' ) : Lavary\Menu\Item
$title string
return Lavary\Menu\Item $item

all() public method

Return all items in the collection
public all ( ) : array
return array

asDiv() public method

Returns the menu as div containers
public asDiv ( $attributes = [], $childrenAttributes = [] ) : string
return string

asOl() public method

Returns the menu as an ordered list.
public asOl ( $attributes = [], $childrenAttributes = [] ) : string
return string

asUl() public method

Returns the menu as an unordered list.
public asUl ( $attributes = [], $childrenAttributes = [] ) : string
return string

attributeElement() protected static method

Build a single attribute element.
protected static attributeElement ( string $key, string $value ) : string
$key string
$value string
return string

attributes() public static method

Build an HTML attribute string from an array.
public static attributes ( array $attributes ) : string
$attributes array
return string

conf() public method

Return configuration value by key
public conf ( string $key ) : string
$key string
return string

dispatch() public method

Get the form action from the options.
public dispatch ( $options ) : string
return string

divide() public method

Insert a separator after the item
public divide ( array $attributes = [] ) : void
$attributes array
return void

extractAttributes() public method

Get the valid attributes from the options.
public extractAttributes ( array $options = [] ) : array
$options array
return array

filter() public method

Filter menu items by user callbacks
public filter ( callable $callback ) : Lavary\Menu\Builder
$callback callable
return Lavary\Menu\Builder

filterRecursive() public method

Filter items recursively
public filterRecursive ( string $attribute, mixed $value ) : Lavary\Menu\Collection
$attribute string
$value mixed
return Lavary\Menu\Collection

find() public method

Returns menu item by Id
public find ( $id ) : Lavary\Menu\Item
return Lavary\Menu\Item

first() public method

Return the first item in the collection
public first ( ) : Lavary\Menu\Item
return Lavary\Menu\Item

formatGroupClass() public static method

Get the valid attributes from the options.
public static formatGroupClass ( $new, $old ) : string
return string

formatGroupPrefix() public static method

Format the prefix for the new group attributes.
public static formatGroupPrefix ( array $new, array $old ) : string
$new array
$old array
return string

get() public method

Returns menu item by name
public get ( $title ) : Lavary\Menu\Item
return Lavary\Menu\Item

getControllerAction() protected method

Get the action for an "action" option.
protected getControllerAction ( array | string $options ) : string
$options array | string
return string

getLastGroupPrefix() public method

Get the prefix from the last group on the stack.
public getLastGroupPrefix ( ) : string
return string

getRoute() protected method

Get the action for a "route" option.
protected getRoute ( array | string $options ) : string
$options array | string
return string

getUrl() protected method

Get the action for a "url" option.
protected getUrl ( array | string $options ) : string
$options array | string
return string

group() public method

Create a menu group with shared attributes.
public group ( array $attributes, callable $closure ) : void
$attributes array
$closure callable
return void

id() protected method

Generate an integer identifier for each new item
protected id ( ) : integer
return integer

isAbs() public static method

Check if the given url is an absolute url.
public static isAbs ( string $url ) : boolean
$url string
return boolean

item() public method

Returns menu item by name
public item ( $title ) : Lavary\Menu\Item
return Lavary\Menu\Item

last() public method

Return the last item in the collection
public last ( ) : Lavary\Menu\Item
return Lavary\Menu\Item

mergeGroup() protected static method

Merge the given group attributes.
protected static mergeGroup ( array $new, array $old ) : array
$new array
$old array
return array

mergeStatic() public static method

Merge item's attributes with a static string of attributes
public static mergeStatic ( $new = null, array $old = [] ) : string
$old array
return string

mergeWithLastGroup() protected method

Merge the given array with the last group stack.
protected mergeWithLastGroup ( array $new ) : array
$new array
return array

prefix() protected method

Prefix the given URI with the last prefix.
protected prefix ( string $uri ) : string
$uri string
return string

raw() public method

Add raw content
public raw ( $title, array $options = [] ) : Lavary\Menu\Item
$options array
return Lavary\Menu\Item

render() public method

Generate the menu items as list items using a recursive function
public render ( string $type = 'ul', integer $parent = null, $childrenAttributes = [] ) : string
$type string
$parent integer
return string

roots() public method

Returns items with no parent
public roots ( ) : Collection
return Illuminate\Support\Collection

sortBy() public method

Sorts the menu based on user's callable
public sortBy ( $sort_by, string | callable $sort_type = 'asc' ) : Lavary\Menu\Builder
$sort_type string | callable
return Lavary\Menu\Builder

updateGroupStack() protected method

Update the group stack with the given attributes.
protected updateGroupStack ( array $attributes = [] ) : void
$attributes array
return void

Property Details

$conf protected_oe property

The Menu configuration data
protected array $conf
return array

$groupStack protected_oe property

The route group attribute stack.
protected array $groupStack
return array

$items protected_oe property

The items container
protected array $items
return array

$name protected_oe property

The Menu name
protected string $name
return string

$reserved protected_oe property

The reserved attributes.
protected array $reserved
return array