You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
1.5 KiB
PHP
91 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Artmark\CrumbSequence;
|
|
|
|
/**
|
|
* Description of BreadCrumbSequence
|
|
*
|
|
* @author Andrey Pokidov <pokidov@e-traffic.ru>
|
|
*/
|
|
class BreadCrumbSequence
|
|
{
|
|
/**
|
|
*
|
|
* @var CrumbSequence
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
*
|
|
* @var CrumbInterface[]
|
|
*/
|
|
private $crumbs = [];
|
|
|
|
private function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return CrumbSequence
|
|
*/
|
|
public static function instance()
|
|
{
|
|
if (is_null(self::$instance)) {
|
|
self::$instance = new CrumbSequence();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|