Skip to content

Commit 8042ba1

Browse files
committed
Use facades with full import
1 parent 9b40ac2 commit 8042ba1

File tree

10 files changed

+116
-95
lines changed

10 files changed

+116
-95
lines changed

routes/routes.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?php
22

33
use CodeZero\StageFront\Controllers\StageFrontController;
4+
use Illuminate\Support\Facades\Config;
5+
use Illuminate\Support\Facades\Route;
46

5-
if (config('stagefront.enabled') === true) {
7+
if (Config::get('stagefront.enabled') === true) {
68

7-
Route::group(['middleware' => config('stagefront.middleware')], function () {
9+
Route::group(['middleware' => Config::get('stagefront.middleware')], function () {
810

9-
$url = config('stagefront.url');
10-
$throttle = config('stagefront.throttle');
11-
$tries = config('stagefront.throttle_tries');
12-
$delay = config('stagefront.throttle_delay');
11+
$url = Config::get('stagefront.url');
12+
$throttle = Config::get('stagefront.throttle');
13+
$tries = Config::get('stagefront.throttle_tries');
14+
$delay = Config::get('stagefront.throttle_delay');
1315
$middleware = $throttle ? "throttle:{$tries},{$delay}" : [];
1416

1517
Route::get($url, StageFrontController::class.'@create');

src/Authenticator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use CodeZero\StageFront\Authenticators\DatabaseAuthenticator;
66
use CodeZero\StageFront\Authenticators\EncryptedAuthenticator;
77
use CodeZero\StageFront\Authenticators\PlainTextAuthenticator;
8+
use Illuminate\Support\Facades\App;
9+
use Illuminate\Support\Facades\Config;
810

911
class Authenticator
1012
{
@@ -20,14 +22,14 @@ class Authenticator
2022
public static function checkCredentials($login, $password)
2123
{
2224
$checkers = [
23-
DatabaseAuthenticator::class => config('stagefront.database') === true,
24-
EncryptedAuthenticator::class => config('stagefront.encrypted') === true,
25+
DatabaseAuthenticator::class => Config::get('stagefront.database') === true,
26+
EncryptedAuthenticator::class => Config::get('stagefront.encrypted') === true,
2527
PlainTextAuthenticator::class => true, //=> Default
2628
];
2729

2830
foreach ($checkers as $checker => $applicable) {
2931
if ($applicable === true) {
30-
return app($checker)->check($login, $password);
32+
return App::make($checker)->check($login, $password);
3133
}
3234
}
3335
}

src/Authenticators/DatabaseAuthenticator.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace CodeZero\StageFront\Authenticators;
44

5-
use DB;
6-
use Hash;
5+
use Illuminate\Support\Facades\Config;
6+
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Hash;
78

89
class DatabaseAuthenticator implements Authenticator
910
{
@@ -32,7 +33,7 @@ public function check($login, $password)
3233
*/
3334
protected function checkPassword($password, $user)
3435
{
35-
$passwordField = config('stagefront.database_password_field');
36+
$passwordField = Config::get('stagefront.database_password_field');
3637

3738
return Hash::check($password, $user->{$passwordField});
3839
}
@@ -50,8 +51,8 @@ protected function findUser($login)
5051
return null;
5152
}
5253

53-
$table = config('stagefront.database_table');
54-
$loginField = config('stagefront.database_login_field');
54+
$table = Config::get('stagefront.database_table');
55+
$loginField = Config::get('stagefront.database_login_field');
5556

5657
return DB::table($table)->where($loginField, '=', $login)->first();
5758
}
@@ -77,7 +78,7 @@ protected function loginIsAllowed($login)
7778
*/
7879
protected function getWhitelist()
7980
{
80-
$whitelist = config('stagefront.database_whitelist', []);
81+
$whitelist = Config::get('stagefront.database_whitelist', []);
8182

8283
if ( ! is_array($whitelist)) {
8384
$whitelist = explode(',', $whitelist) ?: [];

src/Authenticators/EncryptedAuthenticator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace CodeZero\StageFront\Authenticators;
44

5-
use Hash;
5+
use Illuminate\Support\Facades\Config;
6+
use Illuminate\Support\Facades\Hash;
67

78
class EncryptedAuthenticator implements Authenticator
89
{
@@ -28,7 +29,7 @@ public function check($login, $password)
2829
*/
2930
protected function checkLogin($login)
3031
{
31-
return $login === config('stagefront.login');
32+
return $login === Config::get('stagefront.login');
3233
}
3334

3435
/**
@@ -40,6 +41,6 @@ protected function checkLogin($login)
4041
*/
4142
protected function checkPassword($password)
4243
{
43-
return Hash::check($password, config('stagefront.password'));
44+
return Hash::check($password, Config::get('stagefront.password'));
4445
}
4546
}

src/Authenticators/PlainTextAuthenticator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CodeZero\StageFront\Authenticators;
44

5+
use Illuminate\Support\Facades\Config;
6+
57
class PlainTextAuthenticator implements Authenticator
68
{
79
/**
@@ -26,7 +28,7 @@ public function check($login, $password)
2628
*/
2729
protected function checkLogin($login)
2830
{
29-
return $login === config('stagefront.login');
31+
return $login === Config::get('stagefront.login');
3032
}
3133

3234
/**
@@ -38,6 +40,6 @@ protected function checkLogin($login)
3840
*/
3941
protected function checkPassword($password)
4042
{
41-
return $password === config('stagefront.password');
43+
return $password === Config::get('stagefront.password');
4244
}
4345
}

src/Composers/ThrottleTimeRemaining.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use Carbon\Carbon;
66
use Illuminate\Cache\RateLimiter;
77
use Illuminate\Contracts\View\View;
8+
use Illuminate\Support\Facades\App;
9+
use Illuminate\Support\Facades\Lang;
10+
use Illuminate\Support\Facades\Request;
811

912
class ThrottleTimeRemaining
1013
{
@@ -28,12 +31,12 @@ public function compose(View $view)
2831
protected function getTimeRemaining()
2932
{
3033
if ( ! $key = $this->getCacheKey()) {
31-
return trans('stagefront::errors.throttled.moment');
34+
return Lang::get('stagefront::errors.throttled.moment');
3235
}
3336

3437
$secondsRemaining = $this->getSecondsRemaining($key);
3538

36-
Carbon::setLocale(app()->getLocale());
39+
Carbon::setLocale(App::getLocale());
3740

3841
return Carbon::now()
3942
->addSeconds($secondsRemaining)
@@ -49,14 +52,12 @@ protected function getTimeRemaining()
4952
*/
5053
protected function getCacheKey()
5154
{
52-
$request = request();
53-
54-
if ($user = $request->user()) {
55+
if ($user = Request::user()) {
5556
return sha1($user->getAuthIdentifier());
5657
}
5758

58-
if ($route = $request->route()) {
59-
return sha1($route->getDomain().'|'.$request->ip());
59+
if ($route = Request::route()) {
60+
return sha1($route->getDomain().'|'.Request::ip());
6061
}
6162

6263
return null;
@@ -71,6 +72,6 @@ protected function getCacheKey()
7172
*/
7273
protected function getSecondsRemaining($key)
7374
{
74-
return app(RateLimiter::class)->availableIn($key);
75+
return App::make(RateLimiter::class)->availableIn($key);
7576
}
7677
}

src/Controllers/StageFrontController.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
use CodeZero\StageFront\Rules\LoginAndPasswordMatch;
66
use Illuminate\Routing\Controller;
7+
use Illuminate\Support\Facades\Config;
8+
use Illuminate\Support\Facades\Lang;
9+
use Illuminate\Support\Facades\Request;
10+
use Illuminate\Support\Facades\Session;
711

812
class StageFrontController extends Controller
913
{
@@ -14,11 +18,11 @@ class StageFrontController extends Controller
1418
*/
1519
public function create()
1620
{
17-
if (session('stagefront.unlocked') === true) {
21+
if (Session::get('stagefront.unlocked') === true) {
1822
return redirect('/');
1923
}
2024

21-
$liveSite = config('stagefront.live_site');
25+
$liveSite = Config::get('stagefront.live_site');
2226

2327
if ($liveSite) {
2428
$liveSite = [
@@ -27,7 +31,7 @@ public function create()
2731
];
2832
}
2933

30-
session()->flash('url.intended', session()->previousUrl());
34+
Session::flash('url.intended', Session::previousUrl());
3135

3236
return view('stagefront::login', compact('liveSite'));
3337
}
@@ -39,15 +43,15 @@ public function create()
3943
*/
4044
public function store()
4145
{
42-
request()->validate([
46+
Request::validate([
4347
'login' => ['required'],
4448
'password' => ['required', new LoginAndPasswordMatch()],
4549
], [
46-
'login.required' => trans('stagefront::errors.login.required'),
47-
'password.required' => trans('stagefront::errors.password.required'),
50+
'login.required' => Lang::get('stagefront::errors.login.required'),
51+
'password.required' => Lang::get('stagefront::errors.password.required'),
4852
]);
4953

50-
session()->put('stagefront.unlocked', true);
54+
Session::put('stagefront.unlocked', true);
5155

5256
return redirect()->intended('/');
5357
}

src/Middleware/RedirectIfStageFrontIsEnabled.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace CodeZero\StageFront\Middleware;
44

55
use Closure;
6+
use Illuminate\Support\Facades\Config;
7+
use Illuminate\Support\Facades\Session;
68

79
class RedirectIfStageFrontIsEnabled
810
{
@@ -16,10 +18,10 @@ class RedirectIfStageFrontIsEnabled
1618
*/
1719
public function handle($request, Closure $next)
1820
{
19-
$disabled = ! config('stagefront.enabled', false);
20-
$unlocked = session('stagefront.unlocked', false);
21-
$stageFrontUrl = config('stagefront.url');
22-
$ignoredUrls = config('stagefront.ignore_urls', []);
21+
$disabled = ! Config::get('stagefront.enabled', false);
22+
$unlocked = Session::get('stagefront.unlocked', false);
23+
$stageFrontUrl = Config::get('stagefront.url');
24+
$ignoredUrls = Config::get('stagefront.ignore_urls', []);
2325
array_push($ignoredUrls, $stageFrontUrl);
2426

2527
if ($unlocked || $disabled || $this->urlIsIgnored($request, $ignoredUrls)) {

src/Rules/LoginAndPasswordMatch.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use CodeZero\StageFront\Authenticator;
66
use Illuminate\Contracts\Validation\Rule;
7+
use Illuminate\Support\Facades\Lang;
8+
use Illuminate\Support\Facades\Request;
79

810
class LoginAndPasswordMatch implements Rule
911
{
@@ -21,7 +23,7 @@ class LoginAndPasswordMatch implements Rule
2123
*/
2224
public function __construct($loginField = 'login')
2325
{
24-
$this->login = request($loginField);
26+
$this->login = Request::get($loginField);
2527
}
2628

2729
/**
@@ -44,6 +46,6 @@ public function passes($passwordField, $password)
4446
*/
4547
public function message()
4648
{
47-
return trans('stagefront::errors.password.match');
49+
return Lang::get('stagefront::errors.password.match');
4850
}
4951
}

0 commit comments

Comments
 (0)