|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MagicLink; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Cache\RateLimiting\Limit; |
|
6
|
|
|
use Illuminate\Support\Facades\RateLimiter; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
|
|
9
|
|
|
class MagicLinkServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
public function register() |
|
12
|
|
|
{ |
|
13
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/magiclink.php', 'magiclink'); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function boot() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->offerPublishing(); |
|
19
|
|
|
|
|
20
|
|
|
$this->registerRateLimit(); |
|
21
|
|
|
|
|
22
|
|
|
$this->loadRouteMagicLink(); |
|
23
|
|
|
|
|
24
|
|
|
$this->loadViewMagicLink(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
private function registerRateLimit(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$rateLimit = config('magiclink.rate_limit', 'none'); |
|
30
|
|
|
|
|
31
|
|
|
RateLimiter::for( |
|
32
|
|
|
'magiclink', |
|
33
|
|
|
fn () => $rateLimit === 'none' |
|
34
|
|
|
? Limit::none() |
|
35
|
|
|
: Limit::perMinute($rateLimit) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
private function loadRouteMagicLink(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$disableRegisterRoute = config('magiclink.disable_default_route', false); |
|
42
|
|
|
|
|
43
|
|
|
if ($disableRegisterRoute) { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/routes.php'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function loadViewMagicLink(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'magiclink'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function offerPublishing(): void |
|
56
|
|
|
{ |
|
57
|
|
|
if (! $this->app->runningInConsole()) { |
|
58
|
|
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->publishes([ |
|
62
|
|
|
__DIR__.'/../config/magiclink.php' => config_path('magiclink.php'), |
|
63
|
|
|
], 'config'); |
|
64
|
|
|
|
|
65
|
|
|
$this->publishes([ |
|
66
|
|
|
__DIR__.'/../databases/migrations' => database_path('migrations'), |
|
67
|
|
|
], 'migrations'); |
|
68
|
|
|
|
|
69
|
|
|
$this->publishes([ |
|
70
|
|
|
__DIR__.'/../resources/views' => resource_path('views/vendor/magiclink'), |
|
71
|
|
|
], 'views'); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|