├── composer.json └── src ├── Breadcrumb.php ├── BreadcrumbGenerator.php ├── BreadcrumbServiceProvider.php ├── Contracts └── BreadcrumbDriverContract.php ├── Drivers ├── BootstrapDriver.php └── CubeDashboardDriver.php ├── Exceptions ├── DriverNotFoundException.php └── NotDriverException.php └── Facades └── Breadcrumb.php /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mateusjatenee/laravel-breadcrumb", 3 | "description": "PHP project.", 4 | "keywords": [], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Mateus Guimarães", 9 | "email": "mateus.jatene@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=7.0", 14 | "illuminate/support": "~5.1.0|~5.2.0|~5.3.0|~5.4.0", 15 | "illuminate/container": "~5.1.0|~5.2.0|~5.3.0|~5.4.0" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "Mateusjatenee\\Breadcrumb\\": "src/" 20 | } 21 | }, 22 | "autoload-dev": { 23 | "psr-4": { 24 | "Mateusjatenee\\Breadcrumb\\Tests\\": "tests/" 25 | } 26 | }, 27 | "minimum-stability": "stable", 28 | "config": { 29 | "sort-packages": true 30 | }, 31 | "scripts": { 32 | "test": "phpunit", 33 | "configure-commit-template": "git config --add commit.template .gitmessage" 34 | }, 35 | "require-dev": { 36 | "phpunit/phpunit": "^6.0", 37 | "orchestra/testbench" : "~3.3.0|~3.4.0", 38 | "mockery/mockery": "^0.9.5" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Breadcrumb.php: -------------------------------------------------------------------------------- 1 | drivers = new Collection([]); 19 | } 20 | 21 | public function __call($method, $args) 22 | { 23 | return $this->currentDriver()->$method(...$args); 24 | } 25 | 26 | public function addDriver(string $name, $breadcrumb) 27 | { 28 | if (is_string($breadcrumb)) { 29 | $breadcrumb = app()->make($breadcrumb); 30 | } 31 | 32 | $this->validateClass($breadcrumb); 33 | 34 | $this->drivers[$name] = $breadcrumb; 35 | 36 | return $this; 37 | } 38 | 39 | public function setDriver($name, $overwrite = true) 40 | { 41 | if ($this->currentDriver && !$overwrite) { 42 | return $this; 43 | } 44 | 45 | $this->currentDriver = $name; 46 | 47 | return $this; 48 | } 49 | 50 | public function getDrivers() 51 | { 52 | return $this->drivers; 53 | } 54 | 55 | public function flushDrivers() 56 | { 57 | $this->drivers = new Collection([]); 58 | 59 | return $this; 60 | } 61 | 62 | public function currentDriver() 63 | { 64 | if (!isset($this->drivers[$this->currentDriver])) { 65 | throw new DriverNotFoundException($this->currentDriver); 66 | } 67 | 68 | return $this->drivers[$this->currentDriver]; 69 | } 70 | 71 | public function validateClass($breadcrumb) 72 | { 73 | if (!$breadcrumb instanceof BreadcrumbDriverContract) { 74 | throw new NotDriverException($breadcrumb); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/BreadcrumbGenerator.php: -------------------------------------------------------------------------------- 1 | items = (new Collection(explode('.', $key)))->map(function ($word) { 15 | return $this->parseWord($word); 16 | }); 17 | 18 | return $this; 19 | } 20 | 21 | public function toArray() 22 | { 23 | return $this->items->toArray(); 24 | } 25 | 26 | public function generate($value = null) 27 | { 28 | if ($value) { 29 | $this->set($value); 30 | } 31 | 32 | $html = $this->getParentTags(); 33 | 34 | $string = $this->buildString(); 35 | 36 | return str_replace('{content}', $string, $html); 37 | } 38 | 39 | protected function parseWord($word) 40 | { 41 | $words = explode('_', $word); 42 | 43 | $string = ''; 44 | 45 | foreach ($words as $key => $word) { 46 | $string .= $key > 0 ? ' ' . ucfirst($word) : ucfirst($word); 47 | } 48 | 49 | return $string; 50 | } 51 | 52 | protected function buildString() 53 | { 54 | $string = ''; 55 | 56 | foreach ($this->items as $key => $item) { 57 | $string .= str_replace('{item}', $item, $this->getTag($key, $this->items)); 58 | } 59 | 60 | return $string; 61 | } 62 | 63 | protected function getTag(int $key, Collection $items) 64 | { 65 | return $key === ($items->count() - 1) ? $this->getLastItemTags() : $this->getItemTags(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/BreadcrumbServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton('breadcrumb', function ($app) { 19 | return $app->make(Breadcrumb::class); 20 | }); 21 | 22 | $this->app->bind('breadcrumbGenerator', function ($app) { 23 | return $app->make(BreadcrumbGenerator::class); 24 | }); 25 | 26 | app('breadcrumb') 27 | ->addDriver('cube', CubeDashboardDriver::class) 28 | ->addDriver('bootstrap', BootstrapDriver::class) 29 | ->setDriver('bootstrap', false); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Contracts/BreadcrumbDriverContract.php: -------------------------------------------------------------------------------- 1 | {content}'; 13 | } 14 | 15 | public function getItemTags() 16 | { 17 | return '