Skip to content

Commit

Permalink
improvment
Browse files Browse the repository at this point in the history
  • Loading branch information
salkhwlani committed Oct 4, 2017
1 parent bee924a commit 8c1f9a3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Yemenifree\LaravelArabicNumbersMiddleware;

use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Yemenifree\LaravelArabicNumbersMiddleware\Middleware\TransformArabicToEasternNumbers;
use Yemenifree\LaravelArabicNumbersMiddleware\Middleware\TransformEasternToArabicNumbers;
Expand Down Expand Up @@ -33,7 +32,7 @@ class ServiceProvider extends BaseServiceProvider
/**
* auto append middleware.
*
* @var Collection
* @var array
*/
protected $auto_middleware;

Expand Down Expand Up @@ -65,18 +64,22 @@ protected function autoAppendMiddleware()

if ($this->groupMiddleware === true) { // Register middleware as global Middleware
$this->app->make('Illuminate\Contracts\Http\Kernel')->pushMiddleware($this->auto_middleware);
} elseif (is_array($this->groupMiddleware) && count($this->groupMiddleware) > 0) { // Register Middleware for route group
$this->pushMiddlewareToGroups($this->auto_middleware);
}

// Register Middleware for route group
$this->pushMiddlewareToGroups($this->auto_middleware);
}

/**
* push middleware to route groups.
*
* @param $middleware
* @param array $middleware
*/
public function pushMiddlewareToGroups($middleware)
{
if (!is_array($this->groupMiddleware))
return;

foreach ($this->groupMiddleware as $group) {
$this->app['router']->pushMiddlewareToGroup($group, $middleware);
}
Expand Down

0 comments on commit 8c1f9a3

Please sign in to comment.