|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Artmark\BreadCrumbs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of BreadCrumbSequence
|
|
|
|
*
|
|
|
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
|
|
|
*/
|
|
|
|
class BreadCrumbSequence
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var BreadCrumbSequence
|
|
|
|
*/
|
|
|
|
private static $instance = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @var CrumbInterface[]
|
|
|
|
*/
|
|
|
|
private $crumbs = [];
|
|
|
|
|
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return BreadCrumbSequence
|
|
|
|
*/
|
|
|
|
public static function instance()
|
|
|
|
{
|
|
|
|
if (is_null(self::$instance)) {
|
|
|
|
self::$instance = new BreadCrumbSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return CrumbInterface[]
|
|
|
|
*/
|
|
|
|
public function crumbs()
|
|
|
|
{
|
|
|
|
return $this->crumbs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function reset()
|
|
|
|
{
|
|
|
|
if (count($this->crumbs) > 0) {
|
|
|
|
$this->crumbs = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
* @param string $label
|
|
|
|
* @param string $icon
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function append(string $url, string $label, string $icon = '')
|
|
|
|
{
|
|
|
|
$this->push(new Crumb($url, $label, $icon));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param CrumbInterface $crumb
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function push(CrumbInterface $crumb)
|
|
|
|
{
|
|
|
|
if (!in_array($crumb, $this->crumbs)) {
|
|
|
|
$this->crumbs[] = $crumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|