Skip to content

Commit

Permalink
Merge pull request dingo#1316 from rhwilrForks/master
Browse files Browse the repository at this point in the history
L5.4: Rename the router's middleware method to aliasMiddleware
  • Loading branch information
jasonlewis authored Jan 26, 2017
2 parents 446bab2 + c4e29ad commit a852013
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
"require": {
"php": "^5.5.9 || ^7.0",
"dingo/blueprint": "0.2.*",
"illuminate/routing": "5.1.* || 5.2.* || 5.3.*",
"illuminate/support": "5.1.* || 5.2.* || 5.3.*",
"illuminate/routing": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"league/fractal": ">=0.12.0"
},
"require-dev": {
"illuminate/auth": "5.1.* || 5.2.* || 5.3.*",
"illuminate/cache": "5.1.* || 5.2.* || 5.3.*",
"illuminate/console": "5.1.* || 5.2.* || 5.3.*",
"illuminate/database": "5.1.* || 5.2.* || 5.3.*",
"illuminate/events": "5.1.* || 5.2.* || 5.3.*",
"illuminate/filesystem": "5.1.* || 5.2.* || 5.3.*",
"illuminate/log": "5.1.* || 5.2.* || 5.3.*",
"illuminate/pagination": "5.1.* || 5.2.* || 5.3.*",
"illuminate/auth": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/cache": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/console": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/database": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/filesystem": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/log": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"illuminate/pagination": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
"laravel/lumen-framework": "5.1.* || 5.2.*",
"lucadegasperi/oauth2-server-laravel": "5.0.*",
"mockery/mockery": "~0.9",
Expand Down
27 changes: 24 additions & 3 deletions src/Provider/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function boot()
$this->updateRouterBindings();
});

$this->app['router']->middleware('api.auth', Auth::class);
$this->app['router']->middleware('api.throttle', RateLimit::class);
$this->app['router']->middleware('api.controllers', PrepareController::class);
$this->addMiddlewareAlias('api.auth', Auth::class);
$this->addMiddlewareAlias('api.throttle', RateLimit::class);
$this->addMiddlewareAlias('api.controllers', PrepareController::class);
}

/**
Expand Down Expand Up @@ -118,6 +118,27 @@ protected function addRequestMiddlewareToBeginning(Kernel $kernel)
$kernel->prependMiddleware(Request::class);
}

/**
* Register a short-hand name for a middleware. For Compatability
* with Laravel < 5.4 check if aliasMiddleware exists since this
* method has been renamed.
*
* @param string $name
* @param string $class
*
* @return void
*/
protected function addMiddlewareAlias($name, $class)
{
$router = $this->app['router'];

if (method_exists($router, 'aliasMiddleware')) {
return $router->aliasMiddleware($name, $class);
}

return $router->middleware($name, $class);
}

/**
* Gather the application middleware besides this one so that we can send
* our request through them, exactly how the developer wanted.
Expand Down

0 comments on commit a852013

Please sign in to comment.