|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Rinvex\Auth\Providers; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Routing\Router; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider; |
|
9
|
|
|
use Illuminate\Support\Facades\Validator; |
|
10
|
|
|
use Rinvex\Auth\Console\Commands\PublishCommand; |
|
11
|
|
|
use Rinvex\Auth\Services\PasswordResetBrokerManager; |
|
12
|
|
|
use Rinvex\Auth\Services\EmailVerificationBrokerManager; |
|
13
|
|
|
|
|
14
|
|
|
class AuthServiceProvider extends ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The commands to be registered. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $commands = [ |
|
22
|
|
|
PublishCommand::class => 'command.rinvex.auth.publish', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function register() |
|
29
|
|
|
{ |
|
30
|
|
|
// Merge config |
|
31
|
|
|
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.auth'); |
|
32
|
|
|
|
|
33
|
|
|
// Register console commands |
|
34
|
|
|
! $this->app->runningInConsole() || $this->registerCommands(); |
|
35
|
|
|
|
|
36
|
|
|
// Register the password reset broker manager |
|
37
|
|
|
$this->app->singleton('auth.password', function ($app) { |
|
38
|
|
|
return new PasswordResetBrokerManager($app); |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
// Register the verification broker manager |
|
42
|
|
|
$this->app->singleton('rinvex.auth.emailverification', function ($app) { |
|
43
|
|
|
return new EmailVerificationBrokerManager($app); |
|
44
|
|
|
}); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function boot(Router $router) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
// Add country validation rule |
|
53
|
|
|
Validator::extend('country', function ($attribute, $value) { |
|
54
|
|
|
return in_array($value, array_keys(countries())); |
|
55
|
|
|
}, 'Country MUST be valid!'); |
|
56
|
|
|
|
|
57
|
|
|
// Add langauge validation rule |
|
58
|
|
|
Validator::extend('language', function ($attribute, $value) { |
|
59
|
|
|
return in_array($value, array_keys(languages())); |
|
60
|
|
|
}, 'Language MUST be valid!'); |
|
61
|
|
|
|
|
62
|
|
|
// Publish resources |
|
63
|
|
|
! $this->app->runningInConsole() || $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.auth.php')], 'rinvex-auth-config'); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Register console commands. |
|
68
|
|
|
* |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function registerCommands(): void |
|
72
|
|
|
{ |
|
73
|
|
|
// Register artisan commands |
|
74
|
|
|
foreach ($this->commands as $key => $value) { |
|
75
|
|
|
$this->app->singleton($value, $key); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->commands(array_values($this->commands)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.