Last active
December 22, 2015 07:58
-
-
Save Ellrion/97a6c984018034158758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Providers; | |
use Illuminate\Contracts\Validation\Factory; | |
use Illuminate\Validation\ValidationServiceProvider as ServiceProvider; | |
class ValidationServiceProvider extends ServiceProvider | |
{ | |
protected $extendValidators = [ | |
//some validators name there | |
]; | |
/** | |
* Register the service provider. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
parent::register(); | |
$this->extendValidation(); | |
} | |
/** | |
* Extend validator factory. | |
*/ | |
protected function extendValidation() | |
{ | |
$provider = $this; | |
$this->app->extend('validator', function (Factory $validator) use ($provider) { | |
foreach ($provider->extendValidators as $validatorName) { | |
$validator->extend($validatorName, $provider->getValidatorCallback($validatorName)); | |
} | |
return $validator; | |
}); | |
} | |
/** | |
* Get validator function. | |
* | |
* @param string $validatorName | |
* @return callable | |
*/ | |
public function getValidatorCallback(array $validatorName) | |
{ | |
$validator = [$this, camel_case('validate_' . $validatorName)] | |
return function () use ($validator) { | |
return call_user_func_array($validator, func_get_args()); | |
}; | |
} | |
//some validator functions there | |
//public function validateSome($attribute, $values, $parameters){} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment