1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of ibrand/laravel-sms. |
5
|
|
|
* |
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace iBrand\Sms; |
13
|
|
|
|
14
|
|
|
use iBrand\Sms\Storage\CacheStorage; |
15
|
|
|
use Illuminate\Support\Facades\Route; |
16
|
|
|
use Overtrue\EasySms\EasySms; |
17
|
|
|
use iBrand\Sms\Http\Middleware\ThrottleRequests; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ServiceProvider. |
21
|
|
|
*/ |
22
|
|
|
class ServiceProvider extends \Illuminate\Support\ServiceProvider |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $namespace = 'iBrand\Sms'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Boot the service provider. |
31
|
|
|
*/ |
32
|
40 |
|
public function boot() |
33
|
|
|
{ |
34
|
40 |
|
if ($this->app->runningInConsole()) { |
35
|
40 |
|
$this->publishes([ |
36
|
40 |
|
__DIR__ . '/../config/config.php' => config_path('ibrand/sms.php'), |
37
|
|
|
]); |
38
|
|
|
|
39
|
40 |
|
$this->loadMigrationsFrom(__DIR__ . '/../migrations'); |
40
|
|
|
} |
41
|
|
|
|
42
|
40 |
|
if (!$this->app->routesAreCached()) { |
43
|
40 |
|
$routeAttr = config('ibrand.sms.route', []); |
44
|
40 |
|
if (config('ibrand.sms.enable_rate_limit')) { |
45
|
40 |
|
$routeAttr['middleware'] = array_merge($routeAttr['middleware'], [config('ibrand.sms.rate_limit_middleware') . ':' . config('ibrand.sms.rate_limit_count') . ',' . config('ibrand.sms.rate_limit_time')]); |
46
|
|
|
} |
47
|
|
|
|
48
|
40 |
|
Route::group(array_merge(['namespace' => $this->namespace], $routeAttr), function ($router) { |
49
|
40 |
|
require __DIR__ . '/route.php'; |
50
|
40 |
|
}); |
51
|
|
|
} |
52
|
40 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Register the service provider. |
56
|
|
|
*/ |
57
|
40 |
|
public function register() |
58
|
|
|
{ |
59
|
40 |
|
$this->mergeConfigFrom( |
60
|
40 |
|
__DIR__ . '/../config/config.php', 'ibrand.sms' |
61
|
|
|
); |
62
|
|
|
|
63
|
40 |
|
$this->app->singleton(Sms::class, function ($app) { |
|
|
|
|
64
|
31 |
|
$storage = config('ibrand.sms.storage', CacheStorage::class); |
65
|
|
|
|
66
|
31 |
|
return new Sms(new EasySms(config('ibrand.sms.easy_sms')), new $storage()); |
67
|
40 |
|
}); |
68
|
40 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function provides() |
74
|
|
|
{ |
75
|
|
|
return [Sms::class]; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.