PHP Class Caffeinated\Menus\Builder

ファイルを表示 Open project: caffeinated/menus Class Usage Examples

Protected Properties

Property Type Description
$config array
$html Collective\Html\HtmlBuilder
$items array
$lastId integer
$name string
$reserved array
$url Illuminate\Routing\UrlGenerator

Public Methods

Method Description
__call ( string $method, array $args ) : Item | boolean Dynamic search method against a menu attribute.
__construct ( string $name, array $config, HtmlBuilder $html, UrlGenerator $url ) Create a new Builder instance.
__get ( string $property ) : Item Returns menu item by name.
active ( ) : Caffeinated\Menus\Collection Fetches and returns all active state menu items.
add ( string $title, array | string $options = '' ) : Item Add an item to the defined menu.
all ( ) : Caffeinated\Menus\Collection Fetches and returns all menu items.
asUl ( array $attributes = [] ) : string Renders the menu as an unordered list.
attributes ( array $attributes = [] ) : string Converts the defined attributes into HTML.
config ( string $key ) : string Return the configuration value by key.
dispatch ( array $options ) : string Get the action type from the options.
divide ( array $attributes = [] ) : void Insert a divider after the item.
extractAttributes ( array $options = [] ) : array Extract the valid attributes from the passed options.
filter ( callable $callback ) : Builder Filter menu items through a callback.
filterRecursively ( string $attribute, mixed $value ) : Caffeinated\Menus\Collection Filter menu items recursively.
find ( integer $id ) : Item Fetches and returns a menu item by it's ID.
first ( ) : Item Fetches and returns the first menu item.
formatGroupClass ( $new, $old ) : mixed Format the groups class.
get ( string $slug ) : Item Fetches and returns a menu item by it's slug.
getLastGroupPrefix ( ) : mixed Get the prefix from the last group of the stack.
guard ( ) : Builder Filter menu items based on Shinobi permissions.
isAbsolute ( string $url ) : boolean Determines if the given URL is absolute.
item ( string $slug ) : Item Facade method for the get() method.
last ( ) : Item Fetches and returns the last menu item.
roots ( ) : Caffeinated\Menus\Collection Returns all items with no parents.
sortBy ( string $key ) : Builder Sorts the menu based on key given in ascending order.
sortByDesc ( string $key ) : Builder Sorts the menu based on key given in descending order.

Protected Methods

Method Description
getAction ( array | string $action ) : string Get the controller action for a "action" option.
getRoute ( array | string $route ) : string Get the route action for a "route" option.
getUrl ( array | string $options ) : string Get the action for a "url" option.
id ( ) : integer Generate a unique ID for every item added to the menu.
render ( string $type = 'ul', integer $parent = null ) : string Generate the menu items as list items, recursively.

Method Details

__call() public method

Dynamic search method against a menu attribute.
public __call ( string $method, array $args ) : Item | boolean
$method string
$args array
return Item | boolean

__construct() public method

Create a new Builder instance.
public __construct ( string $name, array $config, HtmlBuilder $html, UrlGenerator $url )
$name string
$config array
$html Collective\Html\HtmlBuilder
$url Illuminate\Routing\UrlGenerator

__get() public method

Returns menu item by name.
public __get ( string $property ) : Item
$property string
return Item

active() public method

Fetches and returns all active state menu items.
public active ( ) : Caffeinated\Menus\Collection
return Caffeinated\Menus\Collection

add() public method

Add an item to the defined menu.
public add ( string $title, array | string $options = '' ) : Item
$title string
$options array | string
return Item

all() public method

Fetches and returns all menu items.
public all ( ) : Caffeinated\Menus\Collection
return Caffeinated\Menus\Collection

asUl() public method

Renders the menu as an unordered list.
public asUl ( array $attributes = [] ) : string
$attributes array
return string

attributes() public method

Converts the defined attributes into HTML.
public attributes ( array $attributes = [] ) : string
$attributes array
return string

config() public method

Return the configuration value by key.
public config ( string $key ) : string
$key string
return string

dispatch() public method

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

divide() public method

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

extractAttributes() public method

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

filter() public method

Since menu items are stored as a collection, this will simply forward the callback to the Laravel Collection filter() method and return the results.
public filter ( callable $callback ) : Builder
$callback callable
return Builder

filterRecursively() public method

Filter menu items recursively.
public filterRecursively ( string $attribute, mixed $value ) : Caffeinated\Menus\Collection
$attribute string
$value mixed
return Caffeinated\Menus\Collection

find() public method

Fetches and returns a menu item by it's ID.
public find ( integer $id ) : Item
$id integer
return Item

first() public method

Fetches and returns the first menu item.
public first ( ) : Item
return Item

formatGroupClass() public static method

Format the groups class.
public static formatGroupClass ( $new, $old ) : mixed
return mixed

get() public method

Fetches and returns a menu item by it's slug.
public get ( string $slug ) : Item
$slug string
return Item

getAction() protected method

Get the controller action for a "action" option.
protected getAction ( array | string $action ) : string
$action array | string
return string

getLastGroupPrefix() public method

Get the prefix from the last group of the stack.
public getLastGroupPrefix ( ) : mixed
return mixed

getRoute() protected method

Get the route action for a "route" option.
protected getRoute ( array | string $route ) : string
$route 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

guard() public method

Filter menu items based on Shinobi permissions.
public guard ( ) : Builder
return Builder

id() protected method

Generate a unique ID for every item added to the menu.
protected id ( ) : integer
return integer

isAbsolute() public static method

Determines if the given URL is absolute.
public static isAbsolute ( string $url ) : boolean
$url string
return boolean

item() public method

Facade method for the get() method.
public item ( string $slug ) : Item
$slug string
return Item

last() public method

Fetches and returns the last menu item.
public last ( ) : Item
return Item

render() protected method

Generate the menu items as list items, recursively.
protected render ( string $type = 'ul', integer $parent = null ) : string
$type string
$parent integer
return string

roots() public method

Returns all items with no parents.
public roots ( ) : Caffeinated\Menus\Collection
return Caffeinated\Menus\Collection

sortBy() public method

Sorts the menu based on key given in ascending order.
public sortBy ( string $key ) : Builder
$key string
return Builder

sortByDesc() public method

Sorts the menu based on key given in descending order.
public sortByDesc ( string $key ) : Builder
$key string
return Builder

Property Details

$config protected_oe property

protected array $config
return array

$html protected_oe property

protected HtmlBuilder,Collective\Html $html
return Collective\Html\HtmlBuilder

$items protected_oe property

protected array $items
return array

$lastId protected_oe property

protected int $lastId
return integer

$name protected_oe property

protected string $name
return string

$reserved protected_oe property

protected array $reserved
return array

$url protected_oe property

protected UrlGenerator,Illuminate\Routing $url
return Illuminate\Routing\UrlGenerator