PHP Class Creitive\Breadcrumbs\Breadcrumbs

Datei anzeigen Open project: creitive/breadcrumbs Class Usage Examples

Protected Properties

Property Type Description
$breadcrumbs array The array which will store all of our breadcrumbs.
$breadcrumbsCssClasses array Classes applied to the main
    container element.
$divider string The divider symbol between the breadcrumbs. Uses a slash as a default, since that's the Twitter Bootstrap style.
$listElement The DOM-element that wraps the breadcrumbs. Set to ul by default.

Public Methods

Method Description
__construct ( array $breadcrumbs = [], array $cssClasses = [] ) The class constructor. Accepts an optional array of breadcrumbs, and an optional array of CSS classes to be applied to the container element.
__toString ( ) : string __toString magic method.
add ( string $name = '', string $href = '', boolean $hrefIsFullUrl = false ) Adds a crumb to the internal array.
addCrumb ( string $name = '', string $href = '', boolean $hrefIsFullUrl = false ) Adds a crumb to the internal array.
addCssClasses ( $cssClasses ) Adds more CSS classes which will be applied to the containing
    element. Can be passed a string or an array. If passed a string, separate CSS classes should be separated with spaces.
count ( ) : integer Gets the current amount of breadcrumbs
getBreadcrumbs ( ) : array Gets the currently configured breadcrumbs.
getBreadcrumbsCssClasses ( ) : array Gets the currently configured breadcrumbs CSS classes.
getDivider ( ) : string Gets the divider currently in use.
isEmpty ( ) : boolean Checks whether there are any breadcrumbs added yet.
isValidCrumb ( array $crumb ) : boolean Checks whether a crumb is valid, so that it can safely be added to the internal breadcrumbs array.
removeAll ( ) Removes all breadcrumbs.
removeCssClasses ( string | array $cssClasses ) Removes one or more CSS classes that have been set by other methods. This method won't fail if the passed class has not been set already.
render ( ) : string Renders the complete breadcrumbs into Twitter Bootstrap-compatible HTML.
setBreadcrumbs ( array $breadcrumbs ) Sets all the breadcrumbs. Useful for quickly configuring the instance.
setCssClasses ( string | array $cssClasses ) Sets the CSS classes to be applied to the containing
    element. Can be passed a string or an array. If passed a string, separate CSS classes should be separated with spaces.
setDivider ( string $divider ) Sets the divider which will be printed between the breadcrumbs.
setListElement ( string $element ) Set the containing list DOM element

Protected Methods

Method Description
renderCrumb ( string $name, string $href, boolean $isLast = false, number $position = null ) : string Renders a single breadcrumb, Twitter Bootstrap-style.
renderCrumbs ( ) : string Renders the crumbs one by one, and returns them concatenated.

Method Details

__construct() public method

The class constructor. Accepts an optional array of breadcrumbs, and an optional array of CSS classes to be applied to the container element.
public __construct ( array $breadcrumbs = [], array $cssClasses = [] )
$breadcrumbs array
$cssClasses array

__toString() public method

__toString magic method.
public __toString ( ) : string
return string

add() public method

Alias for Breadcrumbs::addCrumb method.
public add ( string $name = '', string $href = '', boolean $hrefIsFullUrl = false )
$name string The name of this breadcrumb, which will be seen by the users.
$href string If this parameter begins with a forward slash, it will be treated as a full URL, and the `$hrefIsFullUrl` parameter will be forced to `true`, regardless of its value.
$hrefIsFullUrl boolean Whether the `$href` argument is a full URL or just a segment. The difference is that segments will be built upon previous breadcrumbs, while full URLs will be returned as they are inputted. This can be automatically forced to `true`, depending on the `$href` argument - read its description for details.

addCrumb() public method

Adds a crumb to the internal array.
public addCrumb ( string $name = '', string $href = '', boolean $hrefIsFullUrl = false )
$name string The name of this breadcrumb, which will be seen by the users.
$href string If this parameter begins with a forward slash, it will be treated as a full URL, and the `$hrefIsFullUrl` parameter will be forced to `true`, regardless of its value.
$hrefIsFullUrl boolean Whether the `$href` argument is a full URL or just a segment. The difference is that segments will be built upon previous breadcrumbs, while full URLs will be returned as they are inputted. This can be automatically forced to `true`, depending on the `$href` argument - read its description for details.

addCssClasses() public method

Adds more CSS classes which will be applied to the containing
    element. Can be passed a string or an array. If passed a string, separate CSS classes should be separated with spaces.
public addCssClasses ( $cssClasses )

count() public method

Gets the current amount of breadcrumbs
public count ( ) : integer
return integer

getBreadcrumbs() public method

Gets the currently configured breadcrumbs.
public getBreadcrumbs ( ) : array
return array

getBreadcrumbsCssClasses() public method

Gets the currently configured breadcrumbs CSS classes.
public getBreadcrumbsCssClasses ( ) : array
return array

getDivider() public method

Gets the divider currently in use.
public getDivider ( ) : string
return string

isEmpty() public method

Checks whether there are any breadcrumbs added yet.
public isEmpty ( ) : boolean
return boolean

isValidCrumb() public static method

Checks whether a crumb is valid, so that it can safely be added to the internal breadcrumbs array.
public static isValidCrumb ( array $crumb ) : boolean
$crumb array
return boolean

removeAll() public method

Removes all breadcrumbs.
public removeAll ( )

removeCssClasses() public method

Removes one or more CSS classes that have been set by other methods. This method won't fail if the passed class has not been set already.
public removeCssClasses ( string | array $cssClasses )
$cssClasses string | array

render() public method

Renders the complete breadcrumbs into Twitter Bootstrap-compatible HTML.
public render ( ) : string
return string

renderCrumb() protected method

Renders a single breadcrumb, Twitter Bootstrap-style.
protected renderCrumb ( string $name, string $href, boolean $isLast = false, number $position = null ) : string
$name string
$href string
$isLast boolean
$position number
return string

renderCrumbs() protected method

Renders the crumbs one by one, and returns them concatenated.
protected renderCrumbs ( ) : string
return string

setBreadcrumbs() public method

Sets all the breadcrumbs. Useful for quickly configuring the instance.
public setBreadcrumbs ( array $breadcrumbs )
$breadcrumbs array

setCssClasses() public method

Sets the CSS classes to be applied to the containing
    element. Can be passed a string or an array. If passed a string, separate CSS classes should be separated with spaces.
public setCssClasses ( string | array $cssClasses )
$cssClasses string | array

setDivider() public method

If set to null, the divider won't be printed at all.
public setDivider ( string $divider )
$divider string

setListElement() public method

Set the containing list DOM element
public setListElement ( string $element )
$element string

Property Details

$breadcrumbs protected_oe property

The array which will store all of our breadcrumbs.
protected array $breadcrumbs
return array

$breadcrumbsCssClasses protected_oe property

Classes applied to the main
    container element.
protected array $breadcrumbsCssClasses
return array

$divider protected_oe property

The divider symbol between the breadcrumbs. Uses a slash as a default, since that's the Twitter Bootstrap style.
protected string $divider
return string

$listElement protected_oe property

The DOM-element that wraps the breadcrumbs. Set to ul by default.
protected $listElement