1 | <?php |
||
9 | class JsValidationServiceProvider extends ServiceProvider |
||
10 | { |
||
11 | /** |
||
12 | * Bootstrap the application services. |
||
13 | * |
||
14 | * @return void |
||
15 | */ |
||
16 | 48 | public function boot() |
|
17 | { |
||
18 | 48 | $this->bootstrapConfigs(); |
|
19 | 48 | $this->bootstrapViews(); |
|
20 | 48 | $this->bootstrapValidator(); |
|
21 | 48 | $this->publishAssets(); |
|
22 | |||
23 | 48 | if ($this->app['config']->get('jsvalidation.disable_remote_validation') === false) { |
|
24 | 12 | $this->app[Kernel::class]->pushMiddleware(RemoteValidationMiddleware::class); |
|
25 | } |
||
26 | 48 | } |
|
27 | |||
28 | /** |
||
29 | * Register the application services. |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | 12 | public function register() |
|
34 | { |
||
35 | $this->app->singleton('jsvalidator', function ($app) { |
||
36 | 12 | $config = $app['config']->get('jsvalidation'); |
|
37 | |||
38 | 12 | return new JsValidatorFactory($app, $config); |
|
39 | 12 | }); |
|
40 | 12 | } |
|
41 | |||
42 | /** |
||
43 | * Configure and publish views. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | 48 | protected function bootstrapViews() |
|
48 | { |
||
49 | 48 | $viewPath = realpath(__DIR__.'/../resources/views'); |
|
50 | |||
51 | 48 | $this->loadViewsFrom($viewPath, 'jsvalidation'); |
|
52 | 48 | $this->publishes([ |
|
53 | 48 | $viewPath => $this->app['path.base'].'/resources/views/vendor/jsvalidation', |
|
54 | 48 | ], 'views'); |
|
55 | 48 | } |
|
56 | |||
57 | /** |
||
58 | * Configure Laravel Validator. |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 48 | protected function bootstrapValidator() |
|
63 | { |
||
64 | $callback = function () { |
||
65 | return true; |
||
66 | 48 | }; |
|
67 | 48 | $this->app['validator']->extend(ValidatorHandler::JSVALIDATION_DISABLE, $callback); |
|
68 | 48 | } |
|
69 | |||
70 | /** |
||
71 | * Load and publishes configs. |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | 48 | protected function bootstrapConfigs() |
|
82 | |||
83 | /** |
||
84 | * Publish public assets. |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | 48 | protected function publishAssets() |
|
94 | } |
||
95 |