Skip to content
Permalink
Browse files

Fix grammar and use an early return.

  • Loading branch information...
markstory committed May 6, 2016
1 parent 18c3009 commit 1f50eec608285132f71f3d2106bea1bd4d7d931f
@@ -46,14 +46,16 @@ public function __construct(array $locales = [])
/**
* @param ServerRequestInterface $request The request.
* @param ResponseInterface $response The response.
* @param callable $next The next middleware to call
* @return \Psr\Http\Message\ResponseInterface A response
* @param callable $next The next middleware to call.
* @return \Psr\Http\Message\ResponseInterface A response.
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
{
$locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language'));
if ($locale && (in_array($locale, $this->locales) || $this->locales === ['*'])) {
if (!$locale) {
return $next($request, $response);
}
if (in_array($locale, $this->locales) || $this->locales === ['*']) {
I18n::locale($locale);
}
return $next($request, $response);
@@ -65,6 +65,12 @@ public function testInvokeNoAcceptedLocales()
$middleware = new LocaleSelectorMiddleware([]);
$middleware($request, $response, $this->next);
$this->assertSame($this->locale, I18n::locale());
$request = ServerRequestFactory::fromGlobals(['HTTP_ACCEPT_LANGUAGE' => 'garbage']);
$response = new Response();
$middleware = new LocaleSelectorMiddleware([]);
$middleware($request, $response, $this->next);
$this->assertSame($this->locale, I18n::locale());
}
/**

0 comments on commit 1f50eec

Please sign in to comment.
You can’t perform that action at this time.