|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Propaganistas\LaravelDisposableEmail; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Propaganistas\LaravelDisposableEmail\Console\UpdateDisposableDomainsCommand; |
|
7
|
|
|
use Propaganistas\LaravelDisposableEmail\Validation\Indisposable; |
|
8
|
|
|
|
|
9
|
|
|
class DisposableEmailServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The config source path. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $config = __DIR__.'/../config/disposable-email.php'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Bootstrap the application services. |
|
20
|
|
|
* |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
63 |
|
public function boot() |
|
24
|
|
|
{ |
|
25
|
63 |
|
if ($this->app->runningInConsole()) { |
|
26
|
63 |
|
$this->commands(UpdateDisposableDomainsCommand::class); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
63 |
|
$this->publishes([ |
|
30
|
63 |
|
$this->config => config_path('disposable-email.php'), |
|
31
|
63 |
|
], 'laravel-disposable-email'); |
|
32
|
|
|
|
|
33
|
63 |
|
$this->app['validator']->extend('indisposable', Indisposable::class.'@validate', Indisposable::$errorMessage); |
|
34
|
63 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register bindings in the container. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
63 |
|
public function register() |
|
42
|
|
|
{ |
|
43
|
63 |
|
$this->mergeConfigFrom($this->config, 'disposable-email'); |
|
44
|
|
|
|
|
45
|
21 |
|
$this->app->singleton('disposable_email.domains', function ($app) { |
|
46
|
|
|
// Only build and pass the requested cache store if caching is enabled. |
|
47
|
63 |
|
if ($app['config']['disposable-email.cache.enabled']) { |
|
48
|
54 |
|
$store = $app['config']['disposable-email.cache.store']; |
|
49
|
54 |
|
$cache = $app['cache']->store($store == 'default' ? $app['config']['cache.default'] : $store); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
63 |
|
$instance = new DisposableDomains($cache ?? null); |
|
53
|
|
|
|
|
54
|
63 |
|
$instance->setStoragePath($app['config']['disposable-email.storage']); |
|
55
|
63 |
|
$instance->setCacheKey($app['config']['disposable-email.cache.key']); |
|
56
|
|
|
|
|
57
|
63 |
|
return $instance->bootstrap(); |
|
58
|
63 |
|
}); |
|
59
|
|
|
|
|
60
|
63 |
|
$this->app->alias('disposable_email.domains', DisposableDomains::class); |
|
61
|
|
|
} |
|
62
|
|
|
} |