From 6318760807f554731b56d1d4432f05dd41c64db3 Mon Sep 17 00:00:00 2001 From: Andrey Pokidov Date: Thu, 26 Mar 2020 17:25:18 +0700 Subject: [PATCH] =?UTF-8?q?+=D0=91=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D0=B0=20=D1=85=D0=BB=D0=B5=D0=B1=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BA=D1=80=D0=BE=D1=88=D0=B5=D0=BA=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?Laravel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 18 ++++++++++ src/Breadcrumbs.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Crumb.php | 72 ++++++++++++++++++++++++++++++++++++++++ src/CrumbInterface.php | 35 ++++++++++++++++++++ 4 files changed, 215 insertions(+) create mode 100644 composer.json create mode 100644 src/Breadcrumbs.php create mode 100644 src/Crumb.php create mode 100644 src/CrumbInterface.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..41e14da --- /dev/null +++ b/composer.json @@ -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/" + } + } +} diff --git a/src/Breadcrumbs.php b/src/Breadcrumbs.php new file mode 100644 index 0000000..fd4bd07 --- /dev/null +++ b/src/Breadcrumbs.php @@ -0,0 +1,90 @@ + + */ +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; + } +} diff --git a/src/Crumb.php b/src/Crumb.php new file mode 100644 index 0000000..a27c66d --- /dev/null +++ b/src/Crumb.php @@ -0,0 +1,72 @@ + + */ +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; + } +} diff --git a/src/CrumbInterface.php b/src/CrumbInterface.php new file mode 100644 index 0000000..1efdb86 --- /dev/null +++ b/src/CrumbInterface.php @@ -0,0 +1,35 @@ + + */ +interface CrumbInterface +{ + /** + * URL ссылки элемента хлебных крошек + * @return string + */ + public function url(); + + /** + * Текст элемента хлебных крошек + * @return string + */ + public function label(); + + /** + * Задана или нет иконка для элемента хлебных крошек + * @return boolean + */ + public function hasIcon(); + + /** + * Возвращает URL иконки + * @return string + */ + public function icon(); +}