|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the EmailChecker package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Matthieu Moquet <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace EmailChecker\Laravel; |
|
13
|
|
|
|
|
14
|
|
|
use EmailChecker\EmailChecker; |
|
15
|
|
|
use Illuminate\Support\ServiceProvider; |
|
16
|
|
|
use Validator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Laravel service provider. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Oliver Green <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class EmailCheckerServiceProvider extends ServiceProvider |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Register the factory in the application container. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function register() |
|
29
|
|
|
{ |
|
30
|
|
|
/* |
|
31
|
|
|
* Register the e-mail checker |
|
32
|
|
|
*/ |
|
33
|
|
|
$this->app->singleton(EmailChecker::class, function ($app) { |
|
|
|
|
|
|
34
|
|
|
return new EmailChecker(); |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
/* |
|
38
|
|
|
* Alias the dependency for ease. |
|
39
|
|
|
*/ |
|
40
|
|
|
$this->app->alias(EmailChecker::class, 'email.checker'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Bootstrap any application services. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function boot(EmailChecker $checker) |
|
47
|
|
|
{ |
|
48
|
|
|
/* |
|
49
|
|
|
* Add a custom validator filter. |
|
50
|
|
|
*/ |
|
51
|
|
|
$check = function ($attr, $value, $param, $validator) use ($checker) { |
|
|
|
|
|
|
52
|
|
|
return $checker->isValid($value); |
|
53
|
|
|
}; |
|
54
|
|
|
|
|
55
|
|
|
Validator::extend( |
|
56
|
|
|
'not_throw_away', $check, 'The :attribute domain is invalid.' |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the services provided by the provider. |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function provides() |
|
66
|
|
|
{ |
|
67
|
|
|
return ['email.checker', EmailChecker::class]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.