Skip to content

Commit

Permalink
Merge pull request #45 from wikigods/master
Browse files Browse the repository at this point in the history
laravel 10 and AdminLTE 3 support
  • Loading branch information
patrickbrouwers authored Nov 13, 2023
2 parents b737d26 + 3c16261 commit ea522b7
Show file tree
Hide file tree
Showing 30 changed files with 270 additions and 41 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PHP Pipeline

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
max-parallel: 2
matrix:
php-versions: ['8.1', '8.2', '8.3']

name: PHP ${{ matrix.php-versions }}

steps:
- uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: composer run-script test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ composer.phar
composer.lock
.DS_Store
.php_cs.cache
/build
coverage
.phpunit.result.cache
/.idea
build/report.junit.xml

27 changes: 18 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/cache": "~5.0|~6.0|~7.0|~8.0|~9.0",
"illuminate/container": "~5.0|~6.0|~7.0|~8.0|~9.0",
"illuminate/contracts": "~5.0|~6.0|~7.0|~8.0|~9.0",
"illuminate/support": "~5.0|~6.0|~7.0|~8.0|~9.0",
"illuminate/routing": "~5.0|~6.0|~7.0|~8.0|~9.0",
"illuminate/view": "~5.0|~6.0|~7.0|~8.0|~9.0"
"php": "^8.1",
"illuminate/cache": "~10.0",
"illuminate/container": "~10.0",
"illuminate/contracts": "~10.0",
"illuminate/support": "~10.0",
"illuminate/routing": "~10.0",
"illuminate/view": "~10.0"
},
"require-dev": {
"phpunit/phpunit": "~4.1",
"mockery/mockery": "~0.9"
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^10.4"
},
"autoload": {
"psr-4": {
"Maatwebsite\\Sidebar\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Maatwebsite\\Sidebar\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
Expand All @@ -41,5 +46,9 @@
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
}
}
18 changes: 17 additions & 1 deletion config/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,21 @@
'cache' => [
'method' => null,
'duration' => 1440
]
],

/*
|--------------------------------------------------------------------------
| View Name
|--------------------------------------------------------------------------
|
| Choose a view to use to render the sidebar.
| Built in templates are:
|
| - 'AdminLTE2' - Bootstrap 3
| - 'AdminLTE3' - Bootstrap 4
| - 'AdminLTE4' - Bootstrap 5 (coming soon)
| Or a custom view, for example 'custom'. [by default AdminLTE2 will be used so you can publish and modify it as you wish ].
|
*/
'view' => 'AdminLTE2',
];
29 changes: 21 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticProperties="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions resources/views/adminlte-3/append.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a title="{{ $append->getName() }}" class="append right" href="{{ $append->getUrl() }}">
<i class="{{ $append->getIcon() }}"></i>
</a>
1 change: 1 addition & 0 deletions resources/views/adminlte-3/badge.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="right badge {{ $badge->getClass() }}">{{ $badge->getValue() }}</span>
7 changes: 7 additions & 0 deletions resources/views/adminlte-3/group.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@if($group->shouldShowHeading())
<li class="nav-header">{{ $group->getName() }}</li>
@endif

@foreach($items as $item)
{!! $item !!}
@endforeach
26 changes: 26 additions & 0 deletions resources/views/adminlte-3/item.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<li class="nav-item @if($item->getItemClass()){{ $item->getItemClass() }}@endif @if($active)menu-open @endif @if($item->hasItems())treeview @endif clearfix">
<a href="{{ $item->getUrl() }}" class="nav-link @if(count($appends) > 0) hasAppend @endif @if($active)active @endif " @if($item->getNewTab())target="_blank"@endif>
<i class="nav-icon {{ $item->getIcon() }}"></i>
<p>
{{ $item->getName() }}

@foreach($badges as $badge)
{!! $badge !!}
@endforeach

@if($item->hasItems())<i class="right {{ $item->getToggleIcon() }}"></i>@endif
</p>
</a>

@foreach($appends as $append)
{!! $append !!}
@endforeach

@if(count($items) > 0)
<ul class="nav nav-treeview">
@foreach($items as $item)
{!! $item !!}
@endforeach
</ul>
@endif
</li>
5 changes: 5 additions & 0 deletions resources/views/adminlte-3/menu.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
@foreach($groups as $group)
{!! $group !!}
@endforeach
</ul>
16 changes: 16 additions & 0 deletions src/Domain/DefaultAppend.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,20 @@ public function icon($icon)

return $this;
}

public function __serialize():array
{
return [
'name' => $this->name,
'url' => $this->url,
'icon' => $this->icon,
];
}

public function __unserialize(array $data): void
{
$this->name = $data['name'];
$this->url = $data['url'];
$this->icon = $data['icon'];
}
}
14 changes: 14 additions & 0 deletions src/Domain/DefaultBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,18 @@ public function setClass($class)

return $this;
}

public function __serialize():array
{
return [
'value' => $this->value,
'class' => $this->class,
];
}

public function __unserialize(array $data): void
{
$this->value = $data['value'];
$this->class = $data['class'];
}
}
18 changes: 18 additions & 0 deletions src/Domain/DefaultGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,22 @@ public function shouldShowHeading()
{
return $this->heading ? true : false;
}

public function __serialize():array
{
return [
'name' => $this->name,
'items' => $this->items,
'weight' => $this->weight,
'heading' => $this->heading,
];
}

public function __unserialize(array $data): void
{
$this->name = $data['name'];
$this->items = $data['items'];
$this->weight = $data['weight'];
$this->heading = $data['heading'];
}
}
28 changes: 28 additions & 0 deletions src/Domain/DefaultItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,32 @@ public function getItemClass()
{
return $this->itemClass;
}

public function __serialize():array
{
return [
'name' => $this->name,
'weight' => $this->weight,
'url' => $this->url,
'icon' => $this->icon,
'toggleIcon' => $this->toggleIcon,
'items' => $this->items,
'badges' => $this->badges,
'appends' => $this->appends,
'authorized' => $this->authorized,
];
}

public function __unserialize(array $data): void
{
$this->name = $data['name'];
$this->weight = $data['weight'];
$this->url = $data['url'];
$this->icon = $data['icon'];
$this->toggleIcon = $data['toggleIcon'];
$this->items = $data['items'];
$this->badges = $data['badges'];
$this->appends = $data['appends'];
$this->authorized = $data['authorized'];
}
}
11 changes: 8 additions & 3 deletions src/SidebarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ public function register()
*/
protected function registerViews()
{
$location = __DIR__ . '/../resources/views';
$view = match (config('sidebar.view')){
'AdminLTE3' => 'adminlte-3',
default => 'adminlte-2',
};

$location = __DIR__ . "/../resources/views/{$view}";

$this->loadViewsFrom($location, $this->shortName);

$this->publishes([
$location => base_path('resources/views/vendor/' . $this->shortName),
], 'views');
], 'sidebar-views');
}

/**
Expand All @@ -127,7 +132,7 @@ protected function registerConfig()

$this->publishes([
$location => config_path($this->shortName . '.php'),
], 'config');
], 'sidebar-config');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/CacheableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function unserialize($serialized)
/**
* @return array
*/
public function getCacheables()
public function getCacheables(): array
{
return isset($this->cacheables) ? $this->cacheables : ['menu'];
return $this->cacheables ?? ['menu'];
}
}
7 changes: 5 additions & 2 deletions tests/Domain/DefaultAppendTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace Maatwebsite\Sidebar\Tests\Domain;

use Maatwebsite\Sidebar\Append;
use Maatwebsite\Sidebar\Domain\DefaultAppend;
use Mockery as m;
use PHPUnit\Framework\TestCase as TestCase;

class DefaultAppendTest extends PHPUnit_Framework_TestCase
class DefaultAppendTest extends TestCase
{
/**
* @var Illuminate\Contracts\Container\Container
Expand All @@ -16,7 +19,7 @@ class DefaultAppendTest extends PHPUnit_Framework_TestCase
*/
protected $append;

protected function setUp()
protected function setUp(): void
{
$this->container = m::mock('Illuminate\Contracts\Container\Container');
$this->append = new DefaultAppend($this->container);
Expand Down
7 changes: 5 additions & 2 deletions tests/Domain/DefaultBadgeTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace Maatwebsite\Sidebar\Tests\Domain;

use Maatwebsite\Sidebar\Badge;
use Maatwebsite\Sidebar\Domain\DefaultBadge;
use Mockery as m;
use PHPUnit\Framework\TestCase as TestCase;

class DefaultBadgeTest extends PHPUnit_Framework_TestCase
class DefaultBadgeTest extends TestCase
{
/**
* @var Illuminate\Contracts\Container\Container
Expand All @@ -16,7 +19,7 @@ class DefaultBadgeTest extends PHPUnit_Framework_TestCase
*/
protected $badge;

protected function setUp()
protected function setUp(): void
{
$this->container = m::mock('Illuminate\Contracts\Container\Container');
$this->badge = new DefaultBadge($this->container);
Expand Down
Loading

0 comments on commit ea522b7

Please sign in to comment.