diff --git a/src/Javascript/MessageParser.php b/src/Javascript/MessageParser.php index cb5c1c53..5bab9102 100644 --- a/src/Javascript/MessageParser.php +++ b/src/Javascript/MessageParser.php @@ -34,7 +34,7 @@ public function getMessage($attribute, $rule, $parameters) $data = $this->fakeValidationData($attribute, $rule, $parameters); $message = $this->validator->getMessage($attribute, $rule); - $message = $this->validator->doReplacements($message, $attribute, $rule, $parameters); + $message = $this->validator->makeReplacements($message, $attribute, $rule, $parameters); $this->validator->setData($data); diff --git a/src/JsValidatorFactory.php b/src/JsValidatorFactory.php index 7d44e1f2..2ff8587f 100644 --- a/src/JsValidatorFactory.php +++ b/src/JsValidatorFactory.php @@ -10,6 +10,7 @@ use Proengsoft\JsValidation\Support\DelegatedValidator; use Proengsoft\JsValidation\Javascript\ValidatorHandler; use Proengsoft\JsValidation\Javascript\JavascriptValidator; +use Proengsoft\JsValidation\Support\ValidationRuleParserProxy; class JsValidatorFactory { @@ -154,10 +155,10 @@ protected function createFormRequest($class) list($class, $params) = $this->parseFormRequestName($class); $request = $this->app->__get('request'); - $formRequest = $this->app->build($class, $params); + $formRequest = new $class; if ($session = $request->getSession()) { - $formRequest->setSession($session); + $formRequest->setLaravelSession($session); } $formRequest->setUserResolver($request->getUserResolver()); $formRequest->setRouteResolver($request->getRouteResolver()); @@ -194,7 +195,7 @@ protected function jsValidator(Validator $validator, $selector = null) $view = $this->options['view']; $selector = is_null($selector) ? $this->options['form_selector'] : $selector; - $delegated = new DelegatedValidator($validator); + $delegated = new DelegatedValidator($validator, new ValidationRuleParserProxy()); $rules = new RuleParser($delegated, $this->getSessionToken()); $messages = new MessageParser($delegated); diff --git a/src/Remote/Validator.php b/src/Remote/Validator.php index 537163c8..6be1901f 100644 --- a/src/Remote/Validator.php +++ b/src/Remote/Validator.php @@ -3,8 +3,9 @@ namespace Proengsoft\JsValidation\Remote; use Illuminate\Http\JsonResponse; +use Illuminate\Validation\ValidationRuleParser; use Proengsoft\JsValidation\Support\RuleListTrait; -use Illuminate\Http\Exception\HttpResponseException; +use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Validation\Validator as BaseValidator; use Proengsoft\JsValidation\Support\AccessProtectedTrait; @@ -57,7 +58,7 @@ public function validate($field, $parameters = []) * @param \Illuminate\Validation\Validator $validator * @return void * - * @throws \Illuminate\Validation\ValidationException|\Illuminate\Http\Exception\HttpResponseException + * @throws \Illuminate\Validation\ValidationException|\Illuminate\Http\Exceptions\HttpResponseException */ protected function throwValidationException($result, $validator) { @@ -153,7 +154,7 @@ protected function purgeNonRemoteRules($rules, $validator) $protectedValidator = $this->createProtectedCaller($validator); foreach ($rules as $i => $rule) { - $parsedRule = call_user_func($protectedValidator, 'parseRule', [$rule]); + $parsedRule = ValidationRuleParser::parse([$rule]); if (! $this->isRemoteRule($parsedRule[0])) { unset($rules[$i]); } diff --git a/src/Support/DelegatedValidator.php b/src/Support/DelegatedValidator.php index 1fa260e8..17fb2fb2 100644 --- a/src/Support/DelegatedValidator.php +++ b/src/Support/DelegatedValidator.php @@ -15,6 +15,13 @@ class DelegatedValidator */ protected $validator; + /** + * Validation rule parser instance. + * + * @var \Proengsoft\JsValidation\Support\ValidationRuleParserProxy + */ + protected $ruleParser; + /** * Closure to invoke non accessible Validator methods. * @@ -26,10 +33,12 @@ class DelegatedValidator * DelegatedValidator constructor. * * @param \Illuminate\Validation\Validator $validator + * @param \Proengsoft\JsValidation\Support\ValidationRuleParserProxy $ruleParser */ - public function __construct(BaseValidator $validator) + public function __construct(BaseValidator $validator, ValidationRuleParserProxy $ruleParser) { $this->validator = $validator; + $this->ruleParser = $ruleParser; $this->validatorMethod = $this->createProtectedCaller($validator); } @@ -107,9 +116,9 @@ public function isImplicit($rule) * * @return string */ - public function doReplacements($message, $attribute, $rule, $parameters) + public function makeReplacements($message, $attribute, $rule, $parameters) { - return $this->callValidator('doReplacements', [$message, $attribute, $rule, $parameters]); + return $this->callValidator('makeReplacements', [$message, $attribute, $rule, $parameters]); } /** @@ -147,7 +156,7 @@ public function getMessage($attribute, $rule) */ public function parseRule($rules) { - return $this->callValidator('parseRule', [$rules]); + return $this->ruleParser->parse($rules); } /** diff --git a/src/Support/ValidationRuleParserProxy.php b/src/Support/ValidationRuleParserProxy.php new file mode 100644 index 00000000..fe86f7a6 --- /dev/null +++ b/src/Support/ValidationRuleParserProxy.php @@ -0,0 +1,19 @@ +