Skip to content

Commit fd49e52

Browse files
committed
Update middleware code
1 parent 9706a8d commit fd49e52

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

app/Http/Middleware/LanguageMiddleware.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Http\Middleware;
114

125
use Closure;
136
use Illuminate\Http\Request;
14-
use Illuminate\Support\Facades\Auth;
157
use Illuminate\Foundation\Application;
16-
use Illuminate\Contracts\Config\Repository;
178

189
class LanguageMiddleware
1910
{
@@ -22,33 +13,26 @@ class LanguageMiddleware
2213
*/
2314
private $app;
2415

25-
/**
26-
* @var \Illuminate\Contracts\Config\Repository
27-
*/
28-
private $config;
29-
3016
/**
3117
* LanguageMiddleware constructor.
3218
*
33-
* @param \Illuminate\Foundation\Application $app
34-
* @param \Illuminate\Contracts\Config\Repository $config
19+
* @param \Illuminate\Foundation\Application $app
3520
*/
36-
public function __construct(Application $app, Repository $config)
21+
public function __construct(Application $app)
3722
{
3823
$this->app = $app;
39-
$this->config = $config;
4024
}
4125

4226
/**
43-
* Handle an incoming request.
27+
* Handle an incoming request and set the user's preferred language.
4428
*
4529
* @param \Illuminate\Http\Request $request
4630
* @param \Closure $next
4731
* @return mixed
4832
*/
4933
public function handle(Request $request, Closure $next)
5034
{
51-
$this->app->setLocale($request->user()->language ?? $this->config->get('app.locale', 'en'));
35+
$this->app->setLocale($request->user()->language ?? config('app.locale', 'en'));
5236

5337
return $next($request);
5438
}

tests/Unit/Http/Middleware/LanguageMiddlewareTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace Tests\Unit\Http\Middleware;
44

55
use Mockery as m;
6+
use Pterodactyl\Models\User;
67
use Illuminate\Foundation\Application;
7-
use Illuminate\Contracts\Config\Repository;
88
use Pterodactyl\Http\Middleware\LanguageMiddleware;
9-
use Pterodactyl\Models\User;
109

1110
class LanguageMiddlewareTest extends MiddlewareTestCase
1211
{
@@ -15,11 +14,6 @@ class LanguageMiddlewareTest extends MiddlewareTestCase
1514
*/
1615
private $appMock;
1716

18-
/**
19-
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
20-
*/
21-
private $config;
22-
2317
/**
2418
* Setup tests.
2519
*/
@@ -28,7 +22,6 @@ public function setUp()
2822
parent::setUp();
2923

3024
$this->appMock = m::mock(Application::class);
31-
$this->config = m::mock(Repository::class);
3225
}
3326

3427
/**
@@ -37,8 +30,6 @@ public function setUp()
3730
public function testLanguageIsSetForGuest()
3831
{
3932
$this->request->shouldReceive('user')->withNoArgs()->andReturnNull();
40-
41-
$this->config->shouldReceive('get')->with('app.locale', 'en')->once()->andReturn('en');
4233
$this->appMock->shouldReceive('setLocale')->with('en')->once()->andReturnNull();
4334

4435
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
@@ -47,7 +38,8 @@ public function testLanguageIsSetForGuest()
4738
/**
4839
* Test that a language is defined via the middleware for a user.
4940
*/
50-
public function testLanguageIsSetWithAuthenticatedUser() {
41+
public function testLanguageIsSetWithAuthenticatedUser()
42+
{
5143
$user = factory(User::class)->make(['language' => 'de']);
5244

5345
$this->request->shouldReceive('user')->withNoArgs()->andReturn($user);
@@ -63,6 +55,6 @@ public function testLanguageIsSetWithAuthenticatedUser() {
6355
*/
6456
private function getMiddleware(): LanguageMiddleware
6557
{
66-
return new LanguageMiddleware($this->appMock, $this->config);
58+
return new LanguageMiddleware($this->appMock);
6759
}
6860
}

0 commit comments

Comments
 (0)