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