These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace Sunspikes\ClamavValidator; |
||
2 | |||
3 | use Illuminate\Support\ServiceProvider; |
||
4 | |||
5 | class ClamavValidatorServiceProvider extends ServiceProvider |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * Indicates if loading of the provider is deferred. |
||
10 | * |
||
11 | * @var bool |
||
12 | */ |
||
13 | protected $defer = false; |
||
14 | |||
15 | /** |
||
16 | * The list of validator rules. |
||
17 | * |
||
18 | * @var bool |
||
19 | */ |
||
20 | protected $rules = [ |
||
21 | 'clamav', |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * Bootstrap the application events. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 1 | public function boot() |
|
30 | { |
||
31 | 1 | $this->loadTranslationsFrom(__DIR__ . '/../lang', 'clamav-validator'); |
|
32 | |||
33 | 1 | $this->app['validator'] |
|
34 | 1 | ->resolver(function ($translator, $data, $rules, $messages) { |
|
35 | 1 | return new ClamavValidator( |
|
36 | 1 | $translator, |
|
37 | 1 | $data, |
|
38 | 1 | $rules, |
|
39 | $messages |
||
40 | 1 | ); |
|
41 | 1 | }); |
|
42 | |||
43 | 1 | $this->addNewRules(); |
|
44 | 1 | } |
|
45 | |||
46 | /** |
||
47 | * Get the list of new rules being added to the validator. |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | 1 | public function getRules() |
|
52 | { |
||
53 | 1 | return $this->rules; |
|
54 | } |
||
55 | |||
56 | |||
57 | /** |
||
58 | * Add new rules to the validator. |
||
59 | */ |
||
60 | 1 | protected function addNewRules() |
|
61 | { |
||
62 | 1 | foreach ($this->getRules() as $rule) { |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
63 | 1 | $this->extendValidator($rule); |
|
64 | 1 | } |
|
65 | 1 | } |
|
66 | |||
67 | |||
68 | /** |
||
69 | * Extend the validator with new rules. |
||
70 | * |
||
71 | * @param string $rule |
||
72 | * @return void |
||
73 | */ |
||
74 | 1 | protected function extendValidator($rule) |
|
75 | { |
||
76 | 1 | $method = studly_case($rule); |
|
77 | 1 | $translation = $this->app['translator']->get('clamav-validator::validation'); |
|
78 | 1 | $this->app['validator']->extend($rule, ClamavValidator::class .'@validate' . $method, |
|
79 | 1 | isset($translation[$rule]) ? $translation[$rule] : []); |
|
80 | 1 | } |
|
81 | |||
82 | |||
83 | /** |
||
84 | * Register the service provider. |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | public function register() |
||
89 | { |
||
90 | } |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Get the services provided by the provider. |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | 1 | public function provides() |
|
99 | { |
||
100 | 1 | return []; |
|
101 | } |
||
102 | } |
||
103 |