From 028e1a191e1d0615cfba34c324e861d2607079e5 Mon Sep 17 00:00:00 2001 From: Shift Date: Wed, 24 May 2023 21:33:08 +0000 Subject: [PATCH] Shift core files --- app/Exceptions/Handler.php | 18 ------- app/Http/Controllers/Controller.php | 2 - app/Http/Kernel.php | 8 ++-- app/Http/Middleware/TrustHosts.php | 2 +- app/Providers/BroadcastServiceProvider.php | 4 +- app/Providers/RouteServiceProvider.php | 56 +++++++++------------- tests/CreatesApplication.php | 7 ++- 7 files changed, 32 insertions(+), 65 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index de89608..487dcc8 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -12,24 +12,6 @@ use Symfony\Component\HttpKernel\Exception\HttpException; class Handler extends ExceptionHandler { - /** - * A list of exception types with their corresponding custom log levels. - * - * @var array, \Psr\Log\LogLevel::*> - */ - protected $levels = [ - // - ]; - - /** - * A list of the exception types that are not reported. - * - * @var array> - */ - protected $dontReport = [ - // - ]; - /** * A list of the inputs that are never flashed to the session on validation exceptions. * diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index ce1176d..f1406be 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -3,13 +3,11 @@ namespace App\Http\Controllers; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; -use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; class Controller extends BaseController { use AuthorizesRequests; - use DispatchesJobs; use ValidatesRequests; } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index b63ff09..ca0a07b 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -40,7 +40,7 @@ class Kernel extends HttpKernel 'api' => [ // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, - 'throttle:api', + \Illuminate\Routing\Middleware\ThrottleRequests::class.':api', \Illuminate\Routing\Middleware\SubstituteBindings::class, // \App\Http\Middleware\ForceJsonResponse::class, 'useSanctumGuard', @@ -49,13 +49,13 @@ class Kernel extends HttpKernel ]; /** - * The application's route middleware. + * The application's middleware aliases. * - * These middleware may be assigned to groups or used individually. + * Aliases may be used to conveniently assign middleware to routes and groups. * * @var array */ - protected $routeMiddleware = [ + protected $middlewareAliases = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class, diff --git a/app/Http/Middleware/TrustHosts.php b/app/Http/Middleware/TrustHosts.php index 7186414..c9c58bd 100644 --- a/app/Http/Middleware/TrustHosts.php +++ b/app/Http/Middleware/TrustHosts.php @@ -11,7 +11,7 @@ class TrustHosts extends Middleware * * @return array */ - public function hosts() + public function hosts(): array { return [ $this->allSubdomainsOfApplicationUrl(), diff --git a/app/Providers/BroadcastServiceProvider.php b/app/Providers/BroadcastServiceProvider.php index 395c518..2be04f5 100644 --- a/app/Providers/BroadcastServiceProvider.php +++ b/app/Providers/BroadcastServiceProvider.php @@ -9,10 +9,8 @@ class BroadcastServiceProvider extends ServiceProvider { /** * Bootstrap any application services. - * - * @return void */ - public function boot() + public function boot(): void { Broadcast::routes(); diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index de4213d..85b20a8 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -28,7 +28,29 @@ class RouteServiceProvider extends ServiceProvider */ public function boot() { - $this->configureRateLimiting(); + // RateLimiter::for('api', function (Request $request) { + // return Limit::perMinute(60)->by($request->user()?->id !== null ?: $request->ip()); + // }); + + $rateLimitEnabled = true; + $user = auth()->user(); + + if (app()->environment('testing')) { + $rateLimitEnabled = false; + } elseif ($user !== null && $user->hasPermission('admin/ratelimit') === true) { + // Admin users with the "admin/ratelimit" permission are not rate limited + $rateLimitEnabled = false; + } + + if ($rateLimitEnabled === true) { + RateLimiter::for('api', function (Request $request) { + return Limit::perMinute(180)->by($request->user()?->id ?: $request->ip()); + }); + } else { + RateLimiter::for('api', function () { + return Limit::none(); + }); + } $this->routes(function () { Route::middleware('api') @@ -55,36 +77,4 @@ class RouteServiceProvider extends ServiceProvider ->name("{{$singularUri}}.attachments.destroy"); }); } - - /** - * Configure the rate limiters for the application. - * - * @return void - */ - protected function configureRateLimiting() - { - // RateLimiter::for('api', function (Request $request) { - // return Limit::perMinute(60)->by($request->user()?->id !== null ?: $request->ip()); - // }); - - $rateLimitEnabled = true; - $user = auth()->user(); - - if (app()->environment('testing')) { - $rateLimitEnabled = false; - } elseif ($user !== null && $user->hasPermission('admin/ratelimit') === true) { - // Admin users with the "admin/ratelimit" permission are not rate limited - $rateLimitEnabled = false; - } - - if ($rateLimitEnabled === true) { - RateLimiter::for('api', function (Request $request) { - return Limit::perMinute(180)->by($request->user()?->id ?: $request->ip()); - }); - } else { - RateLimiter::for('api', function () { - return Limit::none(); - }); - } - } } diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index ab92402..cc68301 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -3,17 +3,16 @@ namespace Tests; use Illuminate\Contracts\Console\Kernel; +use Illuminate\Foundation\Application; trait CreatesApplication { /** * Creates the application. - * - * @return \Illuminate\Foundation\Application */ - public function createApplication() + public function createApplication(): Application { - $app = require __DIR__ . '/../bootstrap/app.php'; + $app = require __DIR__.'/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap();