|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* @copyright 2018 Hilmi Erdem KEREN |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Erdemkeren\Otp; |
|
9
|
|
|
|
|
10
|
|
|
use Erdemkeren\Otp\Http\Middleware\Otp; |
|
|
|
|
|
|
11
|
|
|
use Erdemkeren\Otp\Repositories\DatabaseTokenRepository; |
|
12
|
|
|
use Illuminate\Routing\Router; |
|
13
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class ServiceProvider. |
|
17
|
|
|
*/ |
|
18
|
|
|
class ServiceProvider extends BaseServiceProvider |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Indicates if loading of the provider is deferred. |
|
22
|
|
|
* |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
protected bool $defer = true; |
|
26
|
|
|
|
|
27
|
|
|
public function boot(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->publishes([$this->configPath() => config_path('otp.php')]); |
|
|
|
|
|
|
30
|
|
|
$this->publishes([$this->migrationPath() => database_path('migrations')]); |
|
|
|
|
|
|
31
|
|
|
$this->publishes([$this->viewPath() => resource_path('views')]); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Register the otp service. |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
public function register(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$service = $this->createServiceInstance(); |
|
42
|
|
|
$this->registerDefaultPasswordGenerators($service); |
|
43
|
|
|
|
|
44
|
|
|
$this->app->singleton('otp', function () use ($service) { |
|
45
|
|
|
return $service; |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
/** @var Router $router */ |
|
49
|
|
|
$router = $this->app['router']; |
|
50
|
|
|
$router->aliasMiddleware('otp', Otp::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the services provided by the provider. |
|
55
|
|
|
* |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public function provides(): array |
|
59
|
|
|
{ |
|
60
|
|
|
return [ |
|
61
|
|
|
'otp', |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Create a new otp service instance. |
|
67
|
|
|
* |
|
68
|
|
|
* @return OtpService |
|
69
|
|
|
*/ |
|
70
|
|
|
private function createServiceInstance(): OtpService |
|
71
|
|
|
{ |
|
72
|
|
|
return new OtpService( |
|
73
|
|
|
new GeneratorManager(), |
|
74
|
|
|
new Encryptor(config('app.secret')), |
|
|
|
|
|
|
75
|
|
|
new DatabaseTokenRepository() |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Register default password generators to the |
|
81
|
|
|
* given otp service instance. |
|
82
|
|
|
* |
|
83
|
|
|
* @param OtpService $service |
|
84
|
|
|
*/ |
|
85
|
|
|
private function registerDefaultPasswordGenerators($service): void |
|
86
|
|
|
{ |
|
87
|
|
|
$service->addPasswordGenerator('string', Generators\StringGenerator::class); |
|
88
|
|
|
$service->addPasswordGenerator('numeric', Generators\NumericGenerator::class); |
|
89
|
|
|
$service->addPasswordGenerator('numeric-no-0', Generators\NumericNo0Generator::class); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get the project config path. |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
private function configPath(): string |
|
98
|
|
|
{ |
|
99
|
|
|
return __DIR__.'/../config/otp.php'; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get the migration path. |
|
104
|
|
|
* |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
private function migrationPath(): string |
|
108
|
|
|
{ |
|
109
|
|
|
return __DIR__.'/../database/migrations/'; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get the view path. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
private function viewPath(): string |
|
118
|
|
|
{ |
|
119
|
|
|
return __DIR__.'/../views/'; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths