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