+Библиотека хлебных крошек для Laravel

master
Andrey Pokidov 5 years ago
commit 6318760807

@ -0,0 +1,18 @@
{
"name": "artmark/laravel-breadcrumbs",
"type": "library",
"license": "Proprietary",
"authors": [
{
"name": "Andrey Pokidov",
"email": "pokidov@e-traffic.ru"
}
],
"require": {
},
"autoload": {
"psr-0": {
"Artmark\\BreadCrumbs\\": "src/"
}
}
}

@ -0,0 +1,90 @@
<?php
namespace Artmark\CrumbSequence;
/**
* Description of CrumbSequence
*
* @author Andrey Pokidov <pokidov@e-traffic.ru>
*/
class CrumbSequence
{
/**
*
* @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;
}
}

@ -0,0 +1,72 @@
<?php
namespace Artmark\BreadCrumbs;
/**
* Description of Crumb
*
* @author Andrey Pokidov <pokidov@e-traffic.ru>
*/
class Crumb implements CrumbInterface
{
/**
*
* @var string
*/
private $url;
/**
*
* @var string
*/
private $label;
/**
*
* @var string
*/
private $icon;
public function __construct(string $url, string $label, string $icon = '')
{
$this->url = trim($url);
$this->label = trim($label);
$this->icon = trim($icon);
}
/**
* URL ссылки элемента хлебных крошек
* @return string
*/
public function url()
{
return $this->url;
}
/**
* Текст элемента хлебных крошек
* @return string
*/
public function label()
{
return $this->label;
}
/**
* Задана или нет иконка для элемента хлебных крошек
* @return boolean
*/
public function hasIcon()
{
return !empty($this->icon);
}
/**
* Возвращает URL иконки
* @return string
*/
public function icon()
{
return $this->icon;
}
}

@ -0,0 +1,35 @@
<?php
namespace Artmark\BreadCrumbs;
/**
* Description of CrumbInterface
*
* @author Andrey Pokidov <pokidov@e-traffic.ru>
*/
interface CrumbInterface
{
/**
* URL ссылки элемента хлебных крошек
* @return string
*/
public function url();
/**
* Текст элемента хлебных крошек
* @return string
*/
public function label();
/**
* Задана или нет иконка для элемента хлебных крошек
* @return boolean
*/
public function hasIcon();
/**
* Возвращает URL иконки
* @return string
*/
public function icon();
}
Loading…
Cancel
Save