Skip to content

Commit b130c10

Browse files
rhwilrRalph Huwiler
authored andcommitted
Rename the router's middleware method to aliasMiddleware
1 parent ecf0023 commit b130c10

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

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 $name
127+
* @param $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)