1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Providers; |
6
|
|
|
|
7
|
|
|
use App\Contracts\Http\Responses\ResponseFactory as ResponseFactoryContract; |
8
|
|
|
use App\Http\Responses\ResponseFactory; |
9
|
|
|
use Illuminate\Cache\RateLimiter; |
10
|
|
|
use Illuminate\Cache\RateLimiting\Limit; |
11
|
|
|
use Illuminate\Contracts\Container\Container; |
12
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
13
|
|
|
use Illuminate\Routing\Router; |
14
|
|
|
|
15
|
|
|
final class RouteServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
protected $namespace = '\\App\\Http\\Controllers\\'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
21
|
|
|
*/ |
22
|
|
|
public function boot() |
23
|
|
|
{ |
24
|
|
|
$this->configureRateLimiting(); |
25
|
|
|
|
26
|
|
|
$this->routes(function () { |
27
|
|
|
$router = $this->app->make(Router::class); |
28
|
|
|
|
29
|
|
|
$this->mapApiRoutes($router); |
30
|
58 |
|
|
31
|
|
|
$this->mapWebRoutes($router); |
32
|
58 |
|
}); |
33
|
|
|
} |
34
|
58 |
|
|
35
|
|
|
public function register() |
36
|
58 |
|
{ |
37
|
58 |
|
parent::register(); |
38
|
|
|
|
39
|
58 |
|
$this->app->singleton(ResponseFactoryContract::class, static function (Container $container) { |
40
|
|
|
return $container->make(ResponseFactory::class); |
41
|
|
|
}); |
42
|
18 |
|
} |
43
|
58 |
|
|
44
|
58 |
|
/** |
45
|
|
|
* Define the "web" routes for the application. |
46
|
|
|
* |
47
|
|
|
* These routes all receive session state, CSRF protection, etc. |
48
|
|
|
* |
49
|
|
|
* @param \Illuminate\Routing\Router $router |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
private function mapWebRoutes(Router $router): void |
53
|
|
|
{ |
54
|
58 |
|
$router->middleware('web')->namespace($this->namespace)->group(base_path('routes/web.php')); |
55
|
|
|
} |
56
|
58 |
|
|
57
|
58 |
|
/** |
58
|
58 |
|
* Define the "api" routes for the application. |
59
|
58 |
|
* |
60
|
|
|
* These routes are typically stateless. |
61
|
|
|
* |
62
|
|
|
* @param \Illuminate\Routing\Router $router |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
private function mapApiRoutes(Router $router): void |
66
|
|
|
{ |
67
|
|
|
$router->middleware('api')->namespace($this->namespace)->group(base_path('routes/api.php')); |
68
|
|
|
} |
69
|
58 |
|
|
70
|
|
|
/** |
71
|
58 |
|
* Configure the rate limiters for the application. |
72
|
58 |
|
* |
73
|
58 |
|
* @return void |
74
|
58 |
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
75
|
|
|
*/ |
76
|
|
|
private function configureRateLimiting() |
77
|
|
|
{ |
78
|
|
|
/** @var RateLimiter $rateLimiter */ |
79
|
|
|
$rateLimiter = $this->app->make(RateLimiter::class); |
80
|
|
|
|
81
|
|
|
$rateLimiter->for('spa_login_lock', function () { |
82
|
|
|
return new Limit('spa_login_lock', 15, 5); |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
$rateLimiter->for('spa_invitation_lock', function () { |
86
|
|
|
return new Limit('spa_invitation_lock', 15, 5); |
87
|
|
|
}); |
88
|
|
|
|
89
|
|
|
$rateLimiter->for('spa_password_reset_lock', function () { |
90
|
|
|
return new Limit('spa_password_reset_lock', 15, 5); |
91
|
|
|
}); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|