Skip to content

Commit a852013

Browse files
authored
Merge pull request dingo#1316 from rhwilrForks/master
L5.4: Rename the router's middleware method to aliasMiddleware
2 parents 446bab2 + c4e29ad commit a852013

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
"require": {
1818
"php": "^5.5.9 || ^7.0",
1919
"dingo/blueprint": "0.2.*",
20-
"illuminate/routing": "5.1.* || 5.2.* || 5.3.*",
21-
"illuminate/support": "5.1.* || 5.2.* || 5.3.*",
20+
"illuminate/routing": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
21+
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
2222
"league/fractal": ">=0.12.0"
2323
},
2424
"require-dev": {
25-
"illuminate/auth": "5.1.* || 5.2.* || 5.3.*",
26-
"illuminate/cache": "5.1.* || 5.2.* || 5.3.*",
27-
"illuminate/console": "5.1.* || 5.2.* || 5.3.*",
28-
"illuminate/database": "5.1.* || 5.2.* || 5.3.*",
29-
"illuminate/events": "5.1.* || 5.2.* || 5.3.*",
30-
"illuminate/filesystem": "5.1.* || 5.2.* || 5.3.*",
31-
"illuminate/log": "5.1.* || 5.2.* || 5.3.*",
32-
"illuminate/pagination": "5.1.* || 5.2.* || 5.3.*",
25+
"illuminate/auth": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
26+
"illuminate/cache": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
27+
"illuminate/console": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
28+
"illuminate/database": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
29+
"illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
30+
"illuminate/filesystem": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
31+
"illuminate/log": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
32+
"illuminate/pagination": "5.1.* || 5.2.* || 5.3.* || 5.4.*",
3333
"laravel/lumen-framework": "5.1.* || 5.2.*",
3434
"lucadegasperi/oauth2-server-laravel": "5.0.*",
3535
"mockery/mockery": "~0.9",

src/Provider/LaravelServiceProvider.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function boot()
3939
$this->updateRouterBindings();
4040
});
4141

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

4747
/**
@@ -118,6 +118,27 @@ protected function addRequestMiddlewareToBeginning(Kernel $kernel)
118118
$kernel->prependMiddleware(Request::class);
119119
}
120120

121+
/**
122+
* Register a short-hand name for a middleware. For Compatability
123+
* with Laravel < 5.4 check if aliasMiddleware exists since this
124+
* method has been renamed.
125+
*
126+
* @param string $name
127+
* @param string $class
128+
*
129+
* @return void
130+
*/
131+
protected function addMiddlewareAlias($name, $class)
132+
{
133+
$router = $this->app['router'];
134+
135+
if (method_exists($router, 'aliasMiddleware')) {
136+
return $router->aliasMiddleware($name, $class);
137+
}
138+
139+
return $router->middleware($name, $class);
140+
}
141+
121142
/**
122143
* Gather the application middleware besides this one so that we can send
123144
* our request through them, exactly how the developer wanted.

0 commit comments

Comments
 (0)