Completed
Push — master ( f247e9...842a7b )
by Albert
04:30
created

JsValidationServiceProvider::bootstrapViews()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 1
rs 9.6666
c 3
b 0
f 0
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
        }
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
35 1
        });
36 1
    }
37
38
    /**
39
     * Configure and publish views.
40
     */
41 4
    protected function bootstrapViews()
42
    {
43 4
        $viewPath = realpath(__DIR__.'/../resources/views');
44
45 4
        $this->loadViewsFrom($viewPath, 'jsvalidation');
46 4
        $this->publishes([
47 4
            $viewPath => $this->app['path.base'].'/resources/views/vendor/jsvalidation',
48 4
        ], 'views');
49 4
    }
50
51
    /**
52
     *  Configure Laravel Validator
53
     */
54
    protected function bootstrapValidator()
55
    {
56
        $callback = function () { return true; };
57 4
        $this->app['validator']->extend(ValidatorHandler::JSVALIDATION_DISABLE, $callback);
58 4
    }
59
60
    /**
61
     * Load and publishes configs.
62
     */
63 4
    protected function bootstrapConfigs()
64
    {
65 4
        $configFile = realpath(__DIR__.'/../config/jsvalidation.php');
66
67 4
        $this->mergeConfigFrom($configFile, 'jsvalidation');
68 4
        $this->publishes([$configFile => $this->app['path.config'].'/jsvalidation.php'], 'config');
69 4
    }
70
71
    /**
72
     * Publish public assets.
73
     */
74 4
    protected function publishAssets()
75
    {
76 4
        $this->publishes([
77 4
            realpath(__DIR__.'/../public') => $this->app['path.public'].'/vendor/jsvalidation',
78 4
        ], 'public');
79 4
    }
80
}
81