| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Proengsoft\JsValidation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Contracts\Http\Kernel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\ServiceProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Proengsoft\JsValidation\Javascript\ValidatorHandler; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 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() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 48 |  |         $configFile = realpath(__DIR__.'/../config/jsvalidation.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 48 |  |         $this->mergeConfigFrom($configFile, 'jsvalidation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 48 |  |         $this->publishes([$configFile => $this->app['path.config'].'/jsvalidation.php'], 'config'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 | 48 |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |      * Publish public assets. | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 48 |  |     protected function publishAssets() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 48 |  |         $this->publishes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 48 |  |             realpath(__DIR__.'/../public') => $this->app['path.public'].'/vendor/jsvalidation', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 48 |  |         ], 'public'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 93 | 48 |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 94 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 95 |  |  |  |