From 12e4b1bdf1d5220d5d1d207139107a3a8a8d8f1a Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 13 Feb 2021 06:48:00 -0800 Subject: [PATCH 01/19] Made MenuBuilder items also hideable in the event an entire section needed to be hidden --- Tests/MenuTest.php | 43 ++++++++++++++++++++++++++++++++++++++++++ src/MenuBuilder.php | 6 ++++-- src/MenuItem.php | 43 +++++------------------------------------- src/Traits/CanHide.php | 40 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 40 deletions(-) create mode 100644 src/Traits/CanHide.php diff --git a/Tests/MenuTest.php b/Tests/MenuTest.php index fb50338..3a0484b 100644 --- a/Tests/MenuTest.php +++ b/Tests/MenuTest.php @@ -133,4 +133,47 @@ public function it_can_destroy_all_menus() $this->menu->destroy(); $this->assertCount(0, $this->menu->all()); } + + /** @test */ + public function it_still_generates_empty_menu_after_adding_dropdown() + { + $this->menu->create('test', function (MenuBuilder $menu) { + $menu->dropdown('Test', function($sub) { + + })->hideWhen(function() { + return true; + }); + }); + + $expected = << + + + +TEXT; + + self::assertEquals($expected, $this->menu->get('test')); + } + + /** @test */ + public function it_still_generates_empty_menu_after_adding_item() + { + $this->menu->create('test', function (MenuBuilder $menu) { + $menu->url('/', 'Test') + ->hideWhen(function() { + return true; + }); + }); + + $expected = << + + + +TEXT; + + self::assertEquals($expected, $this->menu->get('test')); + } } diff --git a/src/MenuBuilder.php b/src/MenuBuilder.php index f1adb80..9db2934 100644 --- a/src/MenuBuilder.php +++ b/src/MenuBuilder.php @@ -3,12 +3,14 @@ namespace Nwidart\Menus; use Countable; -use Illuminate\Contracts\Config\Repository; use Illuminate\Support\Arr; +use Nwidart\Menus\Traits\CanHide; +use Illuminate\Contracts\Config\Repository; use Illuminate\View\Factory as ViewFactory; class MenuBuilder implements Countable { + use CanHide; /** * Menu name. * @@ -634,7 +636,7 @@ protected function renderMenu() $menu = $presenter->getOpenTagWrapper(); foreach ($this->getOrderedItems() as $item) { - if ($item->hidden()) { + if ($item->hidden() || $this->hidden()) { continue; } diff --git a/src/MenuItem.php b/src/MenuItem.php index 00c34ee..7d0a6dd 100644 --- a/src/MenuItem.php +++ b/src/MenuItem.php @@ -2,12 +2,12 @@ namespace Nwidart\Menus; -use Closure; -use Collective\Html\HtmlFacade as HTML; -use Illuminate\Contracts\Support\Arrayable as ArrayableContract; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Request; use Illuminate\Support\Str; +use Nwidart\Menus\Traits\CanHide; +use Collective\Html\HtmlFacade as HTML; +use Illuminate\Support\Facades\Request; +use Illuminate\Contracts\Support\Arrayable as ArrayableContract; /** * @property string url @@ -22,6 +22,7 @@ */ class MenuItem implements ArrayableContract { + use CanHide; /** * Array properties. * @@ -54,13 +55,6 @@ class MenuItem implements ArrayableContract 'hideWhen', ); - /** - * The hideWhen callback. - * - * @var Closure - */ - protected $hideWhen; - /** * Constructor. * @@ -592,33 +586,6 @@ public function order($order) return $this; } - /** - * Set hide condition for current menu item. - * - * @param Closure - * @return boolean - */ - public function hideWhen(Closure $callback) - { - $this->hideWhen = $callback; - - return $this; - } - - /** - * Determine whether the menu item is hidden. - * - * @return boolean - */ - public function hidden() - { - if (is_null($this->hideWhen)) { - return false; - } - - return call_user_func($this->hideWhen) == true; - } - /** * Get the instance as an array. * diff --git a/src/Traits/CanHide.php b/src/Traits/CanHide.php new file mode 100644 index 0000000..5710dc5 --- /dev/null +++ b/src/Traits/CanHide.php @@ -0,0 +1,40 @@ +hideWhen = $callback; + + return $this; + } + + /** + * Determine whether the menu item is hidden. + * + * @return boolean + */ + public function hidden() + { + if (is_null($this->hideWhen)) { + return false; + } + + return call_user_func($this->hideWhen) == true; + } +} From db69cf7c0a491674d894f0591fefa45ddc0fdefd Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 30 Mar 2024 20:54:19 -0700 Subject: [PATCH 02/19] Over Haul --- .gitignore | 1 + .php_cs.dist => .php-cs-fixer.dist.php | 15 +++-- Tests/BaseTestCase.php | 16 +++--- Tests/MenuBuilderTest.php | 6 +- Tests/MenuItemTest.php | 6 +- Tests/MenuTest.php | 12 ++-- composer.json | 37 +++++++----- config/config.php | 16 +++--- phpunit.xml.dist | 57 ++++++++++--------- src/Facades/Menu.php | 4 +- src/Menu.php | 6 +- src/MenuBuilder.php | 27 ++++++--- src/MenuItem.php | 45 +++++++++++++-- src/MenusServiceProvider.php | 2 +- src/Presenters/Admin/AdminltePresenter.php | 6 +- src/Presenters/Bootstrap/NavMenuPresenter.php | 4 +- .../Bootstrap/NavPillsPresenter.php | 2 +- src/Presenters/Bootstrap/NavTabPresenter.php | 2 +- src/Presenters/Bootstrap/NavbarPresenter.php | 6 +- .../Bootstrap/NavbarRightPresenter.php | 2 +- .../Bootstrap/SidebarMenuPresenter.php | 8 +-- .../Foundation/ZurbMenuPresenter.php | 4 +- .../MetronicHorizontalMenuPresenter.php | 2 +- src/Presenters/Presenter.php | 14 ++--- src/Presenters/PresenterInterface.php | 16 +++--- src/Traits/CanHide.php | 2 +- src/Traits/HasBadges.php | 11 ++++ 27 files changed, 200 insertions(+), 129 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (88%) create mode 100644 src/Traits/HasBadges.php diff --git a/.gitignore b/.gitignore index fbcfdaa..601027d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.phar composer.lock build .php_cs.cache +.idea/ diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 88% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 8bfd25f..4dc4261 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,14 +1,16 @@ in(__DIR__) ->exclude([ 'vendor', ]) ; -return PhpCsFixer\Config::create() - ->setFinder($finder) +return (new Config()) ->setRules([ '@PSR2' => true, // Concatenation should be used with at least one whitespace around. @@ -16,9 +18,9 @@ // Unused use statements must be removed. 'ordered_imports' => true, // Removes extra empty lines. - 'no_extra_consecutive_blank_lines' => true, + 'no_extra_blank_lines' => true, // An empty line feed should precede a return statement. - 'blank_line_before_return' => true, + 'blank_line_before_statement' => true, // Unused use statements must be removed. 'no_unused_imports' => true, // Remove trailing whitespace at the end of blank lines. @@ -34,7 +36,7 @@ // Remove duplicated semicolons. 'no_empty_statement' => true, // PHP multi-line arrays should have a trailing comma. - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => true, // There should be no empty lines after class opening brace. 'no_blank_lines_after_class_opening' => true, // There should not be blank lines between docblock and the documented element. @@ -42,4 +44,5 @@ // Phpdocs should start and end with content, excluding the very first and last line of the docblocks. 'phpdoc_trim' => true, ]) + ->setFinder($finder) ; diff --git a/Tests/BaseTestCase.php b/Tests/BaseTestCase.php index 4f7b585..e167fd3 100644 --- a/Tests/BaseTestCase.php +++ b/Tests/BaseTestCase.php @@ -1,9 +1,9 @@ set('menus', [ 'styles' => [ - 'navbar' => \Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter::class, - 'navbar-right' => \Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter::class, - 'nav-pills' => \Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter::class, - 'nav-tab' => \Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter::class, - 'sidebar' => \Nwidart\Menus\Presenters\Bootstrap\SidebarMenuPresenter::class, - 'navmenu' => \Nwidart\Menus\Presenters\Bootstrap\NavMenuPresenter::class, + 'navbar' => \KyleMassacre\Menus\Presenters\Bootstrap\NavbarPresenter::class, + 'navbar-right' => \KyleMassacre\Menus\Presenters\Bootstrap\NavbarRightPresenter::class, + 'nav-pills' => \KyleMassacre\Menus\Presenters\Bootstrap\NavPillsPresenter::class, + 'nav-tab' => \KyleMassacre\Menus\Presenters\Bootstrap\NavTabPresenter::class, + 'sidebar' => \KyleMassacre\Menus\Presenters\Bootstrap\SidebarMenuPresenter::class, + 'navmenu' => \KyleMassacre\Menus\Presenters\Bootstrap\NavMenuPresenter::class, ], 'ordering' => false, diff --git a/Tests/MenuBuilderTest.php b/Tests/MenuBuilderTest.php index 89121ee..8d74920 100644 --- a/Tests/MenuBuilderTest.php +++ b/Tests/MenuBuilderTest.php @@ -1,10 +1,10 @@ menu->create('test', function (MenuBuilder $menu) { - $menu->dropdown('Test', function($sub) { + $menu->dropdown('Test', function ($sub) { - })->hideWhen(function() { + })->hideWhen(function () { return true; }); }); @@ -161,7 +161,7 @@ public function it_still_generates_empty_menu_after_adding_item() { $this->menu->create('test', function (MenuBuilder $menu) { $menu->url('/', 'Test') - ->hideWhen(function() { + ->hideWhen(function () { return true; }); }); diff --git a/composer.json b/composer.json index 8df2336..c966dfd 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "nwidart/laravel-menus", + "name": "kylemassacre/laravel-menus", "description": "Laravel Menu management", "keywords": [ "laravel", @@ -17,29 +17,33 @@ { "name": "Pingpong Labs", "email": "pingpong.labs@gmail.com" + }, + { + "name": "Kyle Ellis", + "email": "ky.ellis83@gmail.com" } ], "require": { - "php": ">=7.3", - "illuminate/support": "^8.0", - "illuminate/config": "^8.0", - "illuminate/view": "^8.0", - "laravelcollective/html": "6.2.*" + "php": "^8.0", + "illuminate/support": "^10.0", + "illuminate/config": "^10.0", + "illuminate/view": "^10.0", + "laravelcollective/html": "^6.4" }, "require-dev": { - "phpunit/phpunit": "^8.5", - "mockery/mockery": "~1.0", - "orchestra/testbench": "^6.2", - "friendsofphp/php-cs-fixer": "^2.16" + "phpunit/phpunit": ">=9.6", + "mockery/mockery": "^1.6", + "orchestra/testbench": "^8", + "friendsofphp/php-cs-fixer": "^3.52" }, "autoload": { "psr-4": { - "Nwidart\\Menus\\": "src" + "KyleMassacre\\Menus\\": "src" } }, "autoload-dev": { "psr-4": { - "Nwidart\\Menus\\Tests\\": "Tests" + "KyleMassacre\\Menus\\Tests\\": "Tests" } }, "extra": { @@ -48,12 +52,15 @@ }, "laravel": { "providers": [ - "Nwidart\\Menus\\MenusServiceProvider" + "KyleMassacre\\Menus\\MenusServiceProvider" ], "aliases": { - "Menu": "Nwidart\\Menus\\Facades\\Menu" + "Menu": "KyleMassacre\\Menus\\Facades\\Menu" } } }, - "minimum-stability": "stable" + "minimum-stability": "stable", + "scripts": { + "php-cs-fixer": "php-cs-fixer --config=./.php-cs-fixer.dist.php" + } } diff --git a/config/config.php b/config/config.php index 9fb361b..5911106 100644 --- a/config/config.php +++ b/config/config.php @@ -3,14 +3,14 @@ return [ 'styles' => [ - 'navbar' => \Nwidart\Menus\Presenters\Bootstrap\NavbarPresenter::class, - 'navbar-right' => \Nwidart\Menus\Presenters\Bootstrap\NavbarRightPresenter::class, - 'nav-pills' => \Nwidart\Menus\Presenters\Bootstrap\NavPillsPresenter::class, - 'nav-tab' => \Nwidart\Menus\Presenters\Bootstrap\NavTabPresenter::class, - 'sidebar' => \Nwidart\Menus\Presenters\Bootstrap\SidebarMenuPresenter::class, - 'navmenu' => \Nwidart\Menus\Presenters\Bootstrap\NavMenuPresenter::class, - 'adminlte' => \Nwidart\Menus\Presenters\Admin\AdminltePresenter::class, - 'zurbmenu' => \Nwidart\Menus\Presenters\Foundation\ZurbMenuPresenter::class, + 'navbar' => \KyleMassacre\Menus\Presenters\Bootstrap\NavbarPresenter::class, + 'navbar-right' => \KyleMassacre\Menus\Presenters\Bootstrap\NavbarRightPresenter::class, + 'nav-pills' => \KyleMassacre\Menus\Presenters\Bootstrap\NavPillsPresenter::class, + 'nav-tab' => \KyleMassacre\Menus\Presenters\Bootstrap\NavTabPresenter::class, + 'sidebar' => \KyleMassacre\Menus\Presenters\Bootstrap\SidebarMenuPresenter::class, + 'navmenu' => \KyleMassacre\Menus\Presenters\Bootstrap\NavMenuPresenter::class, + 'adminlte' => \KyleMassacre\Menus\Presenters\Admin\AdminltePresenter::class, + 'zurbmenu' => \KyleMassacre\Menus\Presenters\Foundation\ZurbMenuPresenter::class, ], 'ordering' => false, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 785aa48..e8b6169 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,32 @@ - - - - Tests - - - - - src/ - - - - - - - - - + + + + + + + + + + + Tests + + + + + + + + src/ + + diff --git a/src/Facades/Menu.php b/src/Facades/Menu.php index df331c2..bf9eb13 100644 --- a/src/Facades/Menu.php +++ b/src/Facades/Menu.php @@ -1,10 +1,10 @@ $type, + 'text' => $text, + 'name' => 'badge', + ); + + return $this->add($properties); + } + /** * Add new header item. * - * @return \Nwidart\Menus\MenuItem + * @return \KyleMassacre\Menus\MenuItem */ public function addHeader($title, $order = null) { diff --git a/src/MenuItem.php b/src/MenuItem.php index 7d0a6dd..f5af812 100644 --- a/src/MenuItem.php +++ b/src/MenuItem.php @@ -1,13 +1,13 @@ addHeader($title); } + public function addBadge(string $type, $text) + { + $properties = array( + 'type' => $type, + 'text' => $text, + 'name' => 'badge', + ); + $item = static::make($properties); + $this->badge = $properties; + + return $item; + } + /** * Get childs. * @@ -339,6 +355,20 @@ public function getRequest() return ltrim(str_replace(url('/'), '', $this->getUrl()), '/'); } + /** + * @param string $type + * @param $text + */ + public function getBadge() + { + if($this->hasBadge()) { + extract($this->badge); + + return '' . $text . ''; + } + //dd('badge is null'); + } + /** * Get icon. * @@ -586,6 +616,11 @@ public function order($order) return $this; } + public function hasBadge() + { + return !empty($this->badge); + } + /** * Get the instance as an array. * diff --git a/src/MenusServiceProvider.php b/src/MenusServiceProvider.php index dc6cc5f..51e8189 100644 --- a/src/MenusServiceProvider.php +++ b/src/MenusServiceProvider.php @@ -1,6 +1,6 @@ Date: Sat, 30 Mar 2024 20:58:00 -0700 Subject: [PATCH 03/19] Create laravel.yml --- .github/workflows/laravel.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/laravel.yml diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml new file mode 100644 index 0000000..a5f2bc5 --- /dev/null +++ b/.github/workflows/laravel.yml @@ -0,0 +1,35 @@ +name: Laravel + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + laravel-tests: + + runs-on: ubuntu-latest + + steps: + - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e + with: + php-version: '8.0' + - uses: actions/checkout@v3 + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - name: Generate key + run: php artisan key:generate + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + - name: Create Database + run: | + mkdir -p database + touch database/database.sqlite + - name: Execute tests (Unit and Feature tests) via PHPUnit + env: + DB_CONNECTION: sqlite + DB_DATABASE: database/database.sqlite + run: vendor/bin/phpunit From af6303dd597f3fa97d9560da20e9a170cfdc82ee Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 30 Mar 2024 21:06:06 -0700 Subject: [PATCH 04/19] Updated readme and changelog --- CHANGELOG.md | 5 +++++ README.md | 45 +++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebf1b2..f89b54d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All Notable changes to `laravel-menus` will be documented in this file. ## Next +## 7.0.0 - 2024-03-30 + +### Added +- Laravel 10 support + ## 6.0.0 - 2020-11-11 ### Added diff --git a/README.md b/README.md index 633aee3..fcc9698 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,27 @@ # Laravel Menus -[![Latest Version on Packagist](https://img.shields.io/packagist/v/nwidart/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-menus) -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/travis/nWidart/laravel-menus/master.svg?style=flat-square)](https://travis-ci.org/nWidart/laravel-menus) -[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/nWidart/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-menus/?branch=master) -[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/6b187410-e586-465f-a137-2d1fbf7ac724.svg?style=flat-square)](https://insight.sensiolabs.com/projects/6b187410-e586-465f-a137-2d1fbf7ac724) -[![Quality Score](https://img.shields.io/scrutinizer/g/nWidart/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-menus) -[![Total Downloads](https://img.shields.io/packagist/dt/nwidart/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-menus) - -| **Laravel** | **laravel-menus** | -|---|---| -| 5.4 | ^0.5 | -| 5.5 | ^1.0 | -| 5.6 | ^2.0 | -| 5.7 | ^3.0 | -| 5.8 | ^4.0 | -| 6.0 | ^5.0 | -| 8.0 | ^7.0 | - -`nwidart/laravel-menus` is a laravel package which created to manage menus. It has a feature called presenters which enables easy styling and custom structure of menu rendering. - -This package is a re-published, re-organised and maintained version of [pingpong/menus](https://github.com/pingpong-labs/menus), which isn't maintained anymore. This package is used in [AsgardCMS](https://asgardcms.com/). +[//]: # ([![Latest Version on Packagist](https://img.shields.io/packagist/v/nwidart/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-menus)) + +[//]: # ([![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)) + +[//]: # ([![Build Status](https://img.shields.io/travis/nWidart/laravel-menus/master.svg?style=flat-square)](https://travis-ci.org/nWidart/laravel-menus)) + +[//]: # ([![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/nWidart/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-menus/?branch=master)) + +[//]: # ([![SensioLabsInsight](https://img.shields.io/sensiolabs/i/6b187410-e586-465f-a137-2d1fbf7ac724.svg?style=flat-square)](https://insight.sensiolabs.com/projects/6b187410-e586-465f-a137-2d1fbf7ac724)) + +[//]: # ([![Quality Score](https://img.shields.io/scrutinizer/g/nWidart/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-menus)) + +[//]: # ([![Total Downloads](https://img.shields.io/packagist/dt/nwidart/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-menus)) + + +| **Laravel** | **laravel-menus** | +|-------------|-------------------| +| 10.0 | ^8.0 | + +`kylemassacre/laravel-menus` is a laravel package which created to manage menus. It has a feature called presenters which enables easy styling and custom structure of menu rendering. + +This package is a re-published, re-organised and maintained version of [nwidart/laravel-menus](https://github.com/nWidart/laravel-menus), which isn't maintained anymore. This package is used in [AsgardCMS](https://asgardcms.com/). With one big added bonus that the original package didn't have: **tests**. @@ -29,7 +30,7 @@ With one big added bonus that the original package didn't have: **tests**. You'll find installation instructions and full documentation on https://nwidart.com/laravel-menus/. ## Credits - +- [Kyle Ellis](https://github.com/kylemassacre) - [Nicolas Widart](https://github.com/nwidart) - [gravitano](https://github.com/gravitano) - [All Contributors](../../contributors) From 0412c8aa328c45b60ec27db4bd5e64b3668b0712 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 30 Mar 2024 21:12:33 -0700 Subject: [PATCH 05/19] fixing tests --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index a5f2bc5..c439fd5 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -19,7 +19,7 @@ jobs: - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - name: Install Dependencies - run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + run: composer install -q --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Generate key run: php artisan key:generate - name: Directory Permissions From c541d6042924bb8707ea992b6631ccc9e7983b16 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 30 Mar 2024 21:16:00 -0700 Subject: [PATCH 06/19] fixing tests --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c966dfd..afb145c 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,8 @@ } } }, - "minimum-stability": "stable", + "minimum-stability": "dev", + "prefer-stable": true, "scripts": { "php-cs-fixer": "php-cs-fixer --config=./.php-cs-fixer.dist.php" } From e1bcfe4ba5757fda824ce00c9a90a98ed4ab1348 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 30 Mar 2024 21:17:40 -0700 Subject: [PATCH 07/19] fixing tests final time --- .github/workflows/laravel.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index c439fd5..6882bd0 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -20,14 +20,6 @@ jobs: run: php -r "file_exists('.env') || copy('.env.example', '.env');" - name: Install Dependencies run: composer install -q --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - name: Generate key - run: php artisan key:generate - - name: Directory Permissions - run: chmod -R 777 storage bootstrap/cache - - name: Create Database - run: | - mkdir -p database - touch database/database.sqlite - name: Execute tests (Unit and Feature tests) via PHPUnit env: DB_CONNECTION: sqlite From c0387c1df31e10ee205c0e0bb259735dd2e5fd67 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sat, 30 Mar 2024 21:25:46 -0700 Subject: [PATCH 08/19] fixing tests final time --- .github/workflows/laravel.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 6882bd0..cbb490d 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -7,14 +7,17 @@ on: branches: [ "master" ] jobs: - laravel-tests: - - runs-on: ubuntu-latest - + run: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ ubuntu-latest ] + php-versions: ['8.1', '8.2','8.3'] + name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: - - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e + - uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: ${{ matrix.php-versions }} - uses: actions/checkout@v3 - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" From 91d4d29895d209fd13cc7f3c31580157b79f44cb Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sun, 31 Mar 2024 08:09:26 -0700 Subject: [PATCH 09/19] updaing something things --- .github/workflows/laravel.yml | 7 ++++++- .gitignore | 3 ++- .php-cs-fixer.dist.php | 8 ++++---- README.md | 4 ++-- composer.json | 18 +++++++++--------- phpunit.xml.dist | 2 +- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index cbb490d..79563ff 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -19,12 +19,17 @@ jobs: with: php-version: ${{ matrix.php-versions }} - uses: actions/checkout@v3 + with: + fetch-depth: 5 - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - name: Install Dependencies - run: composer install -q --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Execute tests (Unit and Feature tests) via PHPUnit env: DB_CONNECTION: sqlite DB_DATABASE: database/database.sqlite run: vendor/bin/phpunit + - name: action-scrutinizer + uses: sudo-bot/action-scrutinizer@latest + diff --git a/.gitignore b/.gitignore index 601027d..c4d326d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ composer.phar composer.lock build -.php_cs.cache +.php-cs-fixer.cache .idea/ +.phpunit.cache/ diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 4dc4261..3e6ad8d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,8 +7,7 @@ ->in(__DIR__) ->exclude([ 'vendor', - ]) -; + ]); return (new Config()) ->setRules([ @@ -43,6 +42,7 @@ 'no_blank_lines_after_phpdoc' => true, // Phpdocs should start and end with content, excluding the very first and last line of the docblocks. 'phpdoc_trim' => true, + 'normalize_index_brace' => true, + 'whitespace_after_comma_in_array' => true, ]) - ->setFinder($finder) -; + ->setFinder($finder); diff --git a/README.md b/README.md index fcc9698..202f29d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Laravel Menus -[//]: # ([![Latest Version on Packagist](https://img.shields.io/packagist/v/nwidart/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-menus)) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/kylemassacre/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/kylemassacre/laravel-menus) -[//]: # ([![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [//]: # ([![Build Status](https://img.shields.io/travis/nWidart/laravel-menus/master.svg?style=flat-square)](https://travis-ci.org/nWidart/laravel-menus)) diff --git a/composer.json b/composer.json index afb145c..45357e0 100644 --- a/composer.json +++ b/composer.json @@ -25,16 +25,16 @@ ], "require": { "php": "^8.0", - "illuminate/support": "^10.0", - "illuminate/config": "^10.0", - "illuminate/view": "^10.0", - "laravelcollective/html": "^6.4" + "illuminate/support": "^9.21|^10.0", + "illuminate/config": "^10.21", + "illuminate/view": "^10.21", + "laravelcollective/html": "v6.4.1" }, "require-dev": { - "phpunit/phpunit": ">=9.6", - "mockery/mockery": "^1.6", - "orchestra/testbench": "^8", - "friendsofphp/php-cs-fixer": "^3.52" + "phpunit/phpunit": "^10.1", + "mockery/mockery": "~1.5.1", + "orchestra/testbench": "^v8.10.0", + "friendsofphp/php-cs-fixer": "^3.21.1" }, "autoload": { "psr-4": { @@ -62,6 +62,6 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "php-cs-fixer": "php-cs-fixer --config=./.php-cs-fixer.dist.php" + "php-cs-fixer": "php-cs-fixer fix --config=./.php-cs-fixer.dist.php" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e8b6169..db1748d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,7 +7,7 @@ processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" - cacheDirectory=".phpunit.cache" + cacheResult="false" backupStaticProperties="false"> From be68ca9d2eeefb17bd4c64c308d321b5f2e1132c Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sun, 31 Mar 2024 08:12:30 -0700 Subject: [PATCH 10/19] updaing something things --- .github/workflows/laravel.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 79563ff..70b2643 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -32,4 +32,6 @@ jobs: run: vendor/bin/phpunit - name: action-scrutinizer uses: sudo-bot/action-scrutinizer@latest + with: + cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}" From 8a98a7b89b7c1ece5281094f47bef0009bc7c62a Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sun, 31 Mar 2024 08:24:45 -0700 Subject: [PATCH 11/19] updaing scrutinizer --- .scrutinizer.yml | 6 ++++++ README.md | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d9998be..de0894c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -7,3 +7,9 @@ coding_style: tools: external_code_coverage: true php_code_coverage: true +build: + nodes: + analysis: + tests: + override: + - php-scrutinizer-run diff --git a/README.md b/README.md index 202f29d..908fe28 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ [//]: # ([![Build Status](https://img.shields.io/travis/nWidart/laravel-menus/master.svg?style=flat-square)](https://travis-ci.org/nWidart/laravel-menus)) -[//]: # ([![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/nWidart/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-menus/?branch=master)) +[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/kylemassacre/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/kylemassacre/laravel-menus/?branch=master) [//]: # ([![SensioLabsInsight](https://img.shields.io/sensiolabs/i/6b187410-e586-465f-a137-2d1fbf7ac724.svg?style=flat-square)](https://insight.sensiolabs.com/projects/6b187410-e586-465f-a137-2d1fbf7ac724)) -[//]: # ([![Quality Score](https://img.shields.io/scrutinizer/g/nWidart/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-menus)) +[![Quality Score](https://img.shields.io/scrutinizer/g/kylemassacre/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/kylemassacre/laravel-menus) -[//]: # ([![Total Downloads](https://img.shields.io/packagist/dt/nwidart/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-menus)) +[![Total Downloads](https://img.shields.io/packagist/dt/kylemassacre/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/kylemassacre/laravel-menus) | **Laravel** | **laravel-menus** | From 504233206284723047a361009921149c1651ec26 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sun, 31 Mar 2024 08:43:23 -0700 Subject: [PATCH 12/19] added php 8.1 to scrutinizer.yml --- .scrutinizer.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index de0894c..4a8a885 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -10,6 +10,8 @@ tools: build: nodes: analysis: + environment: + php: 8.1.0 tests: override: - php-scrutinizer-run From 2afe4f4da042b1aba6112bf550ccd710be199646 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sun, 31 Mar 2024 09:13:36 -0700 Subject: [PATCH 13/19] Updated badges and created issue/pull request templates Signed-off-by: Kyle Ellis --- .github/ISSUE_TEMPLATE/bug_report.yml | 76 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.yml | 53 +++++++++++++++ README.md | 6 +- 3 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..6ea4c08 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,76 @@ +name: 🐛 Bug Report +description: Create a report to help us improve +title: 'bug: ' + +body: + - type: checkboxes + id: prerequisites + attributes: + label: Prerequisites + description: Please ensure you have completed all of the following. + options: + - label: I have searched for [existing issues](https://github.com/KyleMassacre/laravel-menus/issues) that already report this problem, without success. + required: true + + - type: dropdown + id: affected-versions + attributes: + label: Version + description: Which version(s) of Laravel Menus does this issue impact? + options: + - v8.x + multiple: true + validations: + required: true + + - type: dropdown + id: affected-laravel-versions + attributes: + label: Version + description: Which version(s) of Laravel does this issue impact? + options: + - v10.x + multiple: false + validations: + required: true + + - type: textarea + id: current-behavior + attributes: + label: Current Behavior + description: A clear description of what the bug is and how it manifests. + validations: + required: true + + - type: textarea + id: expected-behavior + attributes: + label: Expected Behavior + description: A clear description of what you expected to happen. + validations: + required: true + + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to Reproduce + description: Please explain the steps required to duplicate this issue. + placeholder: | + 1. + 2. + 3. + validations: + required: true + + - type: input + id: reproduction-url + attributes: + label: Code Reproduction URL + description: Please reproduce this issue in a blank Laravel Invoices starter application and provide a link to the repo. + placeholder: https://github.com/... + + - type: textarea + id: additional-information + attributes: + label: Additional Information + description: List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..526d2e8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,53 @@ +name: 💡 Feature Request +description: Suggest an idea for Laravel Invoices +title: 'feat: ' + +body: + - type: checkboxes + id: prerequisites + attributes: + label: Prerequisites + description: Please ensure you have completed all of the following. + options: + - label: I have searched for [existing issues](https://github.com/KyleMassacre/laravel-menus/issues) that already report this problem, without success. + required: true + + - type: textarea + id: description + attributes: + label: Describe the Feature Request + description: A clear and concise description of what the feature does. + validations: + required: true + + - type: textarea + id: use-case + attributes: + label: Describe the Use Case + description: A clear and concise use case for what problem this feature would solve. + validations: + required: true + + - type: textarea + id: proposed-solution + attributes: + label: Describe Preferred Solution + description: A clear and concise description of what you how you want this feature to be added to Laravel Invoices. + + - type: textarea + id: alternatives-considered + attributes: + label: Describe Alternatives + description: A clear and concise description of any alternative solutions or features you have considered. + + - type: textarea + id: related-code + attributes: + label: Related Code + description: If you are able to illustrate the feature request with an example, please provide a sample Laravel Invoices application. Try out our [Getting Started Wizard](https://ionicframework.com/start#basics) to quickly spin up an Laravel Invoices starter app. + + - type: textarea + id: additional-information + attributes: + label: Additional Information + description: List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to implement, Stack Overflow links, forum links, etc. diff --git a/README.md b/README.md index 908fe28..dade361 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,11 @@ [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[//]: # ([![Build Status](https://img.shields.io/travis/nWidart/laravel-menus/master.svg?style=flat-square)](https://travis-ci.org/nWidart/laravel-menus)) +![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/kylemassacre/laravel-menus/laravel.yml) [![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/kylemassacre/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/kylemassacre/laravel-menus/?branch=master) -[//]: # ([![SensioLabsInsight](https://img.shields.io/sensiolabs/i/6b187410-e586-465f-a137-2d1fbf7ac724.svg?style=flat-square)](https://insight.sensiolabs.com/projects/6b187410-e586-465f-a137-2d1fbf7ac724)) - -[![Quality Score](https://img.shields.io/scrutinizer/g/kylemassacre/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/kylemassacre/laravel-menus) +![Scrutinizer quality (GitHub/Bitbucket) with branch](https://img.shields.io/scrutinizer/quality/g/kylemassacre/laravel-menus/master?style=flat-square) [![Total Downloads](https://img.shields.io/packagist/dt/kylemassacre/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/kylemassacre/laravel-menus) From b69f5477ae3a82b6e9dc712d62476cb97c5ba782 Mon Sep 17 00:00:00 2001 From: Kyle Ellis Date: Sun, 31 Mar 2024 11:11:59 -0700 Subject: [PATCH 14/19] overhaul --- .github/workflows/laravel.yml | 4 +- README.md | 5 - Tests/MenuItemTest.php | 22 +- config/config.php | 1 + src/Contracts/MenuItemContract.php | 205 +++++++++++++++ src/MenuItem.php | 246 +++++------------- src/Presenters/Admin/AdminltePresenter.php | 37 +-- src/Presenters/Bootstrap/NavMenuPresenter.php | 6 +- .../Bootstrap/NavPillsPresenter.php | 4 +- src/Presenters/Bootstrap/NavTabPresenter.php | 4 +- src/Presenters/Bootstrap/NavbarPresenter.php | 37 +-- .../Bootstrap/NavbarRightPresenter.php | 10 +- .../Bootstrap/SidebarMenuPresenter.php | 35 +-- .../Foundation/ZurbMenuPresenter.php | 15 +- .../MetronicHorizontalMenuPresenter.php | 17 +- src/Presenters/Presenter.php | 26 +- src/Presenters/PresenterInterface.php | 38 +-- src/Traits/CanHide.php | 8 +- 18 files changed, 412 insertions(+), 308 deletions(-) create mode 100644 src/Contracts/MenuItemContract.php diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 70b2643..5d1a855 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -2,9 +2,9 @@ name: Laravel on: push: - branches: [ "master" ] + branches: [ "master", "develop" ] pull_request: - branches: [ "master" ] + branches: [ "master", "develop" ] jobs: run: diff --git a/README.md b/README.md index dade361..8024092 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,10 @@ # Laravel Menus [![Latest Version on Packagist](https://img.shields.io/packagist/v/kylemassacre/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/kylemassacre/laravel-menus) - [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) - ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/kylemassacre/laravel-menus/laravel.yml) - [![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/kylemassacre/laravel-menus.svg?style=flat-square)](https://scrutinizer-ci.com/g/kylemassacre/laravel-menus/?branch=master) - ![Scrutinizer quality (GitHub/Bitbucket) with branch](https://img.shields.io/scrutinizer/quality/g/kylemassacre/laravel-menus/master?style=flat-square) - [![Total Downloads](https://img.shields.io/packagist/dt/kylemassacre/laravel-menus.svg?style=flat-square)](https://packagist.org/packages/kylemassacre/laravel-menus) diff --git a/Tests/MenuItemTest.php b/Tests/MenuItemTest.php index ec77f9e..6809fd5 100644 --- a/Tests/MenuItemTest.php +++ b/Tests/MenuItemTest.php @@ -86,7 +86,7 @@ public function it_can_add_a_child_menu_item() $menuItem = MenuItem::make(['title' => 'Parent Item']); $menuItem->child(['title' => 'Child Item']); - $this->assertCount(1, $menuItem->getChilds()); + $this->assertCount(1, $menuItem->getChildren()); } /** @test */ @@ -97,7 +97,7 @@ public function it_can_get_ordered_children() $menuItem->child(['title' => 'Child Item', 'order' => 10]); $menuItem->child(['title' => 'First Child Item', 'order' => 1]); - $children = $menuItem->getChilds(); + $children = $menuItem->getChildren(); $this->assertEquals('First Child Item', $children[1]->title); $this->assertEquals('Child Item', $children[0]->title); } @@ -110,8 +110,8 @@ public function it_can_create_a_dropdown_menu_item() $sub->url('settings/account', 'Account'); $sub->url('settings/password', 'Password'); }); - $this->assertCount(1, $menuItem->getChilds()); - $this->assertCount(2, $menuItem->getChilds()[0]->getChilds()); + $this->assertCount(1, $menuItem->getChildren()); + $this->assertCount(2, $menuItem->getChildren()[0]->getChilds()); } /** @test */ @@ -121,7 +121,7 @@ public function it_can_make_a_simple_route_menu_item() $menuItem->dropdown('Dropdown item', function (MenuItem $sub) { $sub->route('settings.account', 'Account', ['user_id' => 1]); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $this->assertCount(1, $children); $childMenuItem = Arr::first($children); @@ -136,7 +136,7 @@ public function it_can_make_a_route_menu_item() $menuItem->dropdown('Dropdown item', function (MenuItem $sub) { $sub->route('settings.account', 'Account', ['user_id' => 1], 1, ['my-attr' => 'value']); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $this->assertCount(1, $children); $childMenuItem = Arr::first($children); @@ -153,7 +153,7 @@ public function it_can_make_a_simple_url_menu_item() $menuItem->dropdown('Dropdown item', function (MenuItem $sub) { $sub->url('settings/account', 'Account'); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $this->assertCount(1, $children); $childMenuItem = Arr::first($children); @@ -168,7 +168,7 @@ public function it_can_make_a_url_menu_item() $menuItem->dropdown('Dropdown item', function (MenuItem $sub) { $sub->url('settings/account', 'Account', 1, ['my-attr' => 'value']); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $this->assertCount(1, $children); $childMenuItem = Arr::first($children); @@ -187,7 +187,7 @@ public function it_can_add_a_menu_item_divider() $sub->divider(); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $this->assertCount(2, $children); $dividerMenuItem = $children[1]; @@ -204,7 +204,7 @@ public function it_can_add_a_header_menu_item() $sub->url('settings/account', 'Account'); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $this->assertCount(2, $children); $headerItem = $children[0]; @@ -229,7 +229,7 @@ public function it_can_get_the_correct_url_for_route_type() $menuItem->dropdown('Dropdown item', function (MenuItem $sub) { $sub->route('settings.account', 'Account'); }); - $children = $menuItem->getChilds()[0]->getChilds(); + $children = $menuItem->getChildren()[0]->getChilds(); $childMenuItem = Arr::first($children); $this->assertEquals('http://localhost/settings/account', $childMenuItem->getUrl()); diff --git a/config/config.php b/config/config.php index 5911106..6ccbc8e 100644 --- a/config/config.php +++ b/config/config.php @@ -11,6 +11,7 @@ 'navmenu' => \KyleMassacre\Menus\Presenters\Bootstrap\NavMenuPresenter::class, 'adminlte' => \KyleMassacre\Menus\Presenters\Admin\AdminltePresenter::class, 'zurbmenu' => \KyleMassacre\Menus\Presenters\Foundation\ZurbMenuPresenter::class, + 'metronic' => \KyleMassacre\Menus\Presenters\Metronic\MetronicHorizontalMenuPresenter::class, ], 'ordering' => false, diff --git a/src/Contracts/MenuItemContract.php b/src/Contracts/MenuItemContract.php new file mode 100644 index 0000000..f87c806 --- /dev/null +++ b/src/Contracts/MenuItemContract.php @@ -0,0 +1,205 @@ +childs[] = $item; + + return $item; + } + + abstract public function addDivider($order = null): static; + + abstract public function divider($order = null): static; + + abstract public function addHeader(string $title): static; + + abstract public function header(string $title): static; + + abstract public function addBadge(string $type, string $text): static; + + abstract public function getChildren(): array; + + abstract public function getUrl(): string; + + abstract public function getRequest(): string; + + abstract public function getBadge(): string; + + abstract public function getIcon(null|string $default): ?string; + + abstract public function getProperties(): array; + + abstract public function getAttributes(): mixed; + + abstract public function is(string $name): bool; + + abstract public function hasSubMenu(): bool; + + abstract public function hasActiveOnChild(): mixed; + + abstract public function getActiveStateFromChildren(): bool; + + abstract public function inactive(): bool; + + abstract public function getActiveAttribute(): string; + + abstract public function getInactiveAttribute(): string; + + abstract public function isActive(): mixed; + + abstract protected function hasRoute(): mixed; + + abstract protected function getActiveStateFromRoute(): bool; + + abstract protected function getActiveStateFromUrl(): bool; + + abstract public function order(int $order): self; + + abstract public function hasBadge(): bool; + + /** + * Get the instance as an array. + * + * @return array + */ + public function toArray(): array + { + return $this->getProperties(); + } + + /** + * Get property. + * + * @param string $key + * + * @return string|null + */ + public function __get(string $key): ?string + { + $return = null; + if(property_exists($this, $key)) { + $return = $this->$key ?? null; + } + + return $return; + } + + public function __call($name, $arguments) + { + if(str($name)->is('is*')) { + $slice = str($name)->after('is')->lower(); + + return $this->is($slice); + } + } +} diff --git a/src/MenuItem.php b/src/MenuItem.php index f5af812..9c0ec36 100644 --- a/src/MenuItem.php +++ b/src/MenuItem.php @@ -2,11 +2,11 @@ namespace KyleMassacre\Menus; +use AllowDynamicProperties; use Collective\Html\HtmlFacade as HTML; -use Illuminate\Contracts\Support\Arrayable as ArrayableContract; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Request; -use Illuminate\Support\Str; +use KyleMassacre\Menus\Contracts\MenuItemContract; use KyleMassacre\Menus\Traits\CanHide; /** @@ -21,107 +21,27 @@ * @property int order * @property array badge */ -class MenuItem implements ArrayableContract +#[AllowDynamicProperties] class MenuItem extends MenuItemContract { use CanHide; - /** - * Array properties. - * - * @var array - */ - protected $properties = []; - - /** - * The child collections for current menu item. - * - * @var array - */ - protected $childs = array(); - - /** - * The fillable attribute. - * - * @var array - */ - protected $fillable = array( - 'url', - 'route', - 'title', - 'name', - 'icon', - 'parent', - 'attributes', - 'active', - 'order', - 'hideWhen', - 'badge', - 'class', - ); /** * Constructor. * * @param array $properties */ - public function __construct($properties = array()) + public function __construct(array $properties = array()) { $this->properties = $properties; $this->fill($properties); } - /** - * Set the icon property when the icon is defined in the link attributes. - * - * @param array $properties - * - * @return array - */ - protected static function setIconAttribute(array $properties) - { - $icon = Arr::get($properties, 'attributes.icon'); - if (!is_null($icon)) { - $properties['icon'] = $icon; - - Arr::forget($properties, 'attributes.icon'); - - return $properties; - } - - return $properties; - } - - /** - * Get random name. - * - * @param array $attributes - * - * @return string - */ - protected static function getRandomName(array $attributes) - { - return substr(md5(Arr::get($attributes, 'title', Str::random(6))), 0, 5); - } - - /** - * Create new static instance. - * - * @param array $properties - * - * @return static - */ - public static function make(array $properties) - { - $properties = self::setIconAttribute($properties); - - return new static($properties); - } - /** * Fill the attributes. * * @param array $attributes */ - public function fill($attributes) + public function fill(array $attributes): void { foreach ($attributes as $key => $value) { if (in_array($key, $this->fillable)) { @@ -133,11 +53,11 @@ public function fill($attributes) /** * Create new menu child item using array. * - * @param $attributes + * @param array $attributes * - * @return $this + * @return self */ - public function child($attributes) + public function child(array $attributes): self { $this->childs[] = static::make($attributes); @@ -148,11 +68,12 @@ public function child($attributes) * Register new child menu with dropdown. * * @param $title - * @param callable $callback - * + * @param \Closure $callback + * @param int $order + * @param array $attributes * @return $this */ - public function dropdown($title, \Closure $callback, $order = 0, array $attributes = array()) + public function dropdown(string $title, \Closure $callback, int $order = 0, array $attributes = array()): static { $properties = compact('title', 'order', 'attributes'); @@ -182,9 +103,9 @@ public function dropdown($title, \Closure $callback, $order = 0, array $attribut * @param array $parameters * @param array $attributes * - * @return MenuItem + * @return MenuItemContract */ - public function route($route, $title, $parameters = array(), $order = 0, $attributes = array()) + public function route($route, $title, array $parameters = array(), $order = 0, array $attributes = array()): static { if (func_num_args() === 4) { $arguments = func_get_args(); @@ -208,9 +129,9 @@ public function route($route, $title, $parameters = array(), $order = 0, $attrib * @param $title * @param array $attributes * - * @return MenuItem + * @return static */ - public function url($url, $title, $order = 0, $attributes = array()) + public function url($url, $title, $order = 0, array $attributes = array()): static { if (func_num_args() === 3) { $arguments = func_get_args(); @@ -225,22 +146,6 @@ public function url($url, $title, $order = 0, $attributes = array()) return $this->add(compact('url', 'title', 'order', 'attributes')); } - /** - * Add new child item. - * - * @param array $properties - * - * @return $this - */ - public function add(array $properties) - { - $item = static::make($properties); - - $this->childs[] = $item; - - return $item; - } - /** * Add new divider. * @@ -248,7 +153,7 @@ public function add(array $properties) * * @return self */ - public function addDivider($order = null) + public function addDivider($order = null): static { $item = static::make(array('name' => 'divider', 'order' => $order)); @@ -264,7 +169,7 @@ public function addDivider($order = null) * * @return MenuItem */ - public function divider($order = null) + public function divider($order = null): static { return $this->addDivider($order); } @@ -276,7 +181,7 @@ public function divider($order = null) * * @return $this */ - public function addHeader($title) + public function addHeader($title): static { $item = static::make(array( 'name' => 'header', @@ -295,12 +200,12 @@ public function addHeader($title) * * @return $this */ - public function header($title) + public function header($title): static { return $this->addHeader($title); } - public function addBadge(string $type, $text) + public function addBadge(string $type, $text): static { $properties = array( 'type' => $type, @@ -313,12 +218,21 @@ public function addBadge(string $type, $text) return $item; } + /** + * @deprecated See `getChildren` + * @return array + */ + public function getChilds(): array + { + return $this->getChildren(); + } + /** * Get childs. * * @return array */ - public function getChilds() + public function getChildren(): array { if (config('menus.ordering')) { return collect($this->childs)->sortBy('order')->all(); @@ -332,7 +246,7 @@ public function getChilds() * * @return string */ - public function getUrl() + public function getUrl(): string { if ($this->route !== null) { return route($this->route[0], $this->route[1]); @@ -350,33 +264,31 @@ public function getUrl() * * @return string */ - public function getRequest() + public function getRequest(): string { return ltrim(str_replace(url('/'), '', $this->getUrl()), '/'); } /** - * @param string $type - * @param $text + * @return string */ - public function getBadge() + public function getBadge(): string { if($this->hasBadge()) { extract($this->badge); return '' . $text . ''; } - //dd('badge is null'); } /** * Get icon. * - * @param null|string $default + * @param string|null $default * - * @return string + * @return string|null */ - public function getIcon($default = null) + public function getIcon(string $default = null): ?string { if ($this->icon !== null && $this->icon !== '') { return ''; @@ -393,7 +305,7 @@ public function getIcon($default = null) * * @return array */ - public function getProperties() + public function getProperties(): array { return $this->properties; } @@ -403,9 +315,9 @@ public function getProperties() * * @return mixed */ - public function getAttributes() + public function getAttributes(): mixed { - $attributes = $this->attributes ? $this->attributes : []; + $attributes = $this->attributes ?: []; Arr::forget($attributes, ['active', 'icon']); @@ -417,7 +329,7 @@ public function getAttributes() * * @return bool */ - public function isDivider() + public function isDivider(): bool { return $this->is('divider'); } @@ -427,7 +339,7 @@ public function isDivider() * * @return bool */ - public function isHeader() + public function isHeader(): bool { return $this->is('header'); } @@ -439,7 +351,7 @@ public function isHeader() * * @return bool */ - public function is($name) + public function is($name): bool { return $this->name == $name; } @@ -449,17 +361,17 @@ public function is($name) * * @return bool */ - public function hasSubMenu() + public function hasSubMenu(): bool { return !empty($this->childs); } /** - * Same with hasSubMenu. + * @deprecated Same with hasSubMenu. * * @return bool */ - public function hasChilds() + public function hasChilds(): bool { return $this->hasSubMenu(); } @@ -469,23 +381,18 @@ public function hasChilds() * * @return mixed */ - public function hasActiveOnChild() + public function hasActiveOnChild(): mixed { if ($this->inactive()) { return false; } - return $this->hasChilds() ? $this->getActiveStateFromChilds() : false; + return $this->hasSubMenu() && $this->getActiveStateFromChildren(); } - /** - * Get active state from child menu items. - * - * @return bool - */ - public function getActiveStateFromChilds() + public function getActiveStateFromChildren(): bool { - foreach ($this->getChilds() as $child) { + foreach ($this->getChildren() as $child) { if ($child->inactive()) { continue; } @@ -505,12 +412,23 @@ public function getActiveStateFromChilds() return false; } + /** + * @deprecated See `getActiveStateFromChildren()` + * Get active state from child menu items. + * + * @return bool + */ + public function getActiveStateFromChilds(): bool + { + return $this->getActiveStateFromChildren(); + } + /** * Get inactive state. * * @return bool */ - public function inactive() + public function inactive(): bool { $inactive = $this->getInactiveAttribute(); @@ -530,7 +448,7 @@ public function inactive() * * @return string */ - public function getActiveAttribute() + public function getActiveAttribute(): string { return Arr::get($this->attributes, 'active'); } @@ -540,7 +458,7 @@ public function getActiveAttribute() * * @return string */ - public function getInactiveAttribute() + public function getInactiveAttribute(): string { return Arr::get($this->attributes, 'inactive'); } @@ -550,7 +468,7 @@ public function getInactiveAttribute() * * @return mixed */ - public function isActive() + public function isActive(): mixed { if ($this->inactive()) { return false; @@ -578,7 +496,7 @@ public function isActive() * * @return bool */ - protected function hasRoute() + protected function hasRoute(): bool { return !empty($this->route); } @@ -588,7 +506,7 @@ protected function hasRoute() * * @return bool */ - protected function getActiveStateFromRoute() + protected function getActiveStateFromRoute(): bool { return Request::is(str_replace(url('/') . '/', '', $this->getUrl())); } @@ -598,7 +516,7 @@ protected function getActiveStateFromRoute() * * @return bool */ - protected function getActiveStateFromUrl() + protected function getActiveStateFromUrl(): bool { return Request::is($this->url); } @@ -609,37 +527,15 @@ protected function getActiveStateFromUrl() * @param int $order * @return self */ - public function order($order) + public function order(int $order): self { $this->order = $order; return $this; } - public function hasBadge() + public function hasBadge(): bool { return !empty($this->badge); } - - /** - * Get the instance as an array. - * - * @return array - */ - public function toArray() - { - return $this->getProperties(); - } - - /** - * Get property. - * - * @param string $key - * - * @return string|null - */ - public function __get($key) - { - return isset($this->$key) ? $this->$key : null; - } } diff --git a/src/Presenters/Admin/AdminltePresenter.php b/src/Presenters/Admin/AdminltePresenter.php index 4cf8faf..dea4351 100644 --- a/src/Presenters/Admin/AdminltePresenter.php +++ b/src/Presenters/Admin/AdminltePresenter.php @@ -2,38 +2,39 @@ namespace KyleMassacre\Menus\Presenters\Admin; +use KyleMassacre\Menus\Contracts\MenuItemContract; use KyleMassacre\Menus\Presenters\Presenter; class AdminltePresenter extends Presenter { /** - * {@inheritdoc }. + * {@inheritdoc} */ - public function getOpenTagWrapper() + public function getOpenTagWrapper(): ?string { return PHP_EOL . '' . PHP_EOL; } /** - * {@inheritdoc }. + * {@inheritdoc} */ - public function getMenuWithoutDropdownWrapper($item) + public function getMenuWithoutDropdownWrapper(MenuItemContract $item): ?string { return 'getActiveState($item) . '>getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '' . PHP_EOL; } /** - * {@inheritdoc }. + * {@inheritdoc}. */ - public function getActiveState($item, $state = ' class="active"') + public function getActiveState(MenuItemContract $item, $state = ' class="active"'): mixed { return $item->isActive() ? $state : null; } @@ -46,31 +47,31 @@ public function getActiveState($item, $state = ' class="active"') * * @return null|string */ - public function getActiveStateOnChild($item, $state = 'active') + public function getActiveStateOnChild(MenuItemContract $item, string $state = 'active'): ?string { return $item->hasActiveOnChild() ? $state : null; } /** - * {@inheritdoc }. + * {@inheritdoc} */ - public function getDividerWrapper() + public function getDividerWrapper(): ?string { return '
  • '; } /** - * {@inheritdoc }. + * {@inheritdoc} */ - public function getHeaderWrapper($item) + public function getHeaderWrapper(MenuItemContract $item): ?string { return '
  • ' . $item->title . '
  • '; } /** - * {@inheritdoc }. + * {@inheritdoc}. */ - public function getMenuWithDropDownWrapper($item) + public function getMenuWithDropDownWrapper(MenuItemContract $item): ?string { return '
  • @@ -89,11 +90,11 @@ public function getMenuWithDropDownWrapper($item) /** * Get multilevel menu wrapper. * - * @param \KyleMassacre\Menus\MenuItem $item + * @param MenuItemContract $item * - * @return string` + * @return string */ - public function getMultiLevelDropdownWrapper($item) + public function getMultiLevelDropdownWrapper(MenuItemContract $item): string { return '
  • diff --git a/src/Presenters/Bootstrap/NavMenuPresenter.php b/src/Presenters/Bootstrap/NavMenuPresenter.php index 8aaa181..a8d3829 100644 --- a/src/Presenters/Bootstrap/NavMenuPresenter.php +++ b/src/Presenters/Bootstrap/NavMenuPresenter.php @@ -5,7 +5,7 @@ class NavMenuPresenter extends NavbarPresenter { /** - * {@inheritdoc }. + * {@inheritdoc} */ public function getOpenTagWrapper() { @@ -13,7 +13,7 @@ public function getOpenTagWrapper() } /** - * {@inheritdoc }. + * {@inheritdoc} */ public function getMenuWithDropDownWrapper($item) { @@ -34,7 +34,7 @@ public function getMenuWithDropDownWrapper($item) * * @param \KyleMassacre\Menus\MenuItem $item * - * @return string` + * @return string */ public function getMultiLevelDropdownWrapper($item) { diff --git a/src/Presenters/Bootstrap/NavPillsPresenter.php b/src/Presenters/Bootstrap/NavPillsPresenter.php index 27bc7dc..0663fbf 100644 --- a/src/Presenters/Bootstrap/NavPillsPresenter.php +++ b/src/Presenters/Bootstrap/NavPillsPresenter.php @@ -5,9 +5,9 @@ class NavPillsPresenter extends NavbarPresenter { /** - * {@inheritdoc }. + * {@inheritdoc} */ - public function getOpenTagWrapper() + public function getOpenTagWrapper(): ?string { return PHP_EOL . '