diff --git a/.gitignore b/.gitignore index fc905aea..1feebd00 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ node_modules #bower bower_components + +.idea diff --git a/composer.json b/composer.json index 1b426cf0..eb3c46e5 100644 --- a/composer.json +++ b/composer.json @@ -22,13 +22,13 @@ ], "require": { "php" : ">=5.4.0", - "illuminate/support": "~5.0", - "illuminate/validation": "~5.0", - "illuminate/contracts": "~5.0", - "illuminate/view": "~5.0", - "illuminate/config": "~5.0", - "illuminate/http": "~5.0", - "illuminate/translation": "~5.0" + "illuminate/support": "~5.4", + "illuminate/validation": "~5.4", + "illuminate/contracts": "~5.4", + "illuminate/view": "~5.4", + "illuminate/config": "~5.4", + "illuminate/http": "~5.4", + "illuminate/translation": "~5.4" }, "require-dev": { 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..a226ab97 100644 --- a/src/JsValidatorFactory.php +++ b/src/JsValidatorFactory.php @@ -157,8 +157,9 @@ protected function createFormRequest($class) $formRequest = $this->app->build($class, $params); if ($session = $request->getSession()) { - $formRequest->setSession($session); + $formRequest->setLaravelSession($session); } + $formRequest->setUserResolver($request->getUserResolver()); $formRequest->setRouteResolver($request->getRouteResolver()); $formRequest->setContainer($this->app); diff --git a/src/Remote/Validator.php b/src/Remote/Validator.php index 537163c8..7fd6e35b 100644 --- a/src/Remote/Validator.php +++ b/src/Remote/Validator.php @@ -4,8 +4,9 @@ use Illuminate\Http\JsonResponse; use Proengsoft\JsValidation\Support\RuleListTrait; -use Illuminate\Http\Exception\HttpResponseException; +use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Validation\Validator as BaseValidator; +use Illuminate\Validation\ValidationRuleParser; 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) { @@ -136,7 +137,7 @@ protected function setRemoteValidation($attribute, $validateAll = false) return; } if (! $validateAll) { - $rules = $this->purgeNonRemoteRules($rules, $validator); + $rules = $this->purgeNonRemoteRules($rules); } $validator->setRules([$attribute => $rules]); } @@ -145,15 +146,12 @@ protected function setRemoteValidation($attribute, $validateAll = false) * Remove rules that should not be validated remotely. * * @param $rules - * @param BaseValidator $validator * @return mixed */ - protected function purgeNonRemoteRules($rules, $validator) + protected function purgeNonRemoteRules($rules) { - $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..b121db42 100644 --- a/src/Support/DelegatedValidator.php +++ b/src/Support/DelegatedValidator.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Validation\Validator as BaseValidator; +use Illuminate\Validation\ValidationRuleParser; class DelegatedValidator { @@ -107,9 +108,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 +148,7 @@ public function getMessage($attribute, $rule) */ public function parseRule($rules) { - return $this->callValidator('parseRule', [$rules]); + return ValidationRuleParser::parse([$rules]); } /** diff --git a/tests/Javascript/MessageParserTest.php b/tests/Javascript/MessageParserTest.php index 53743536..2830a9a5 100644 --- a/tests/Javascript/MessageParserTest.php +++ b/tests/Javascript/MessageParserTest.php @@ -36,7 +36,7 @@ public function testGetMessage() { ->willReturn("$attribute $rule"); $delegated->expects($this->once()) - ->method('doReplacements') + ->method('makeReplacements') ->with("$attribute $rule",$attribute,$rule, $params) ->willReturn("$attribute $rule"); @@ -78,7 +78,7 @@ public function testGetMessageRequiredIf() { ->willReturn("$attribute $rule"); $delegated->expects($this->once()) - ->method('doReplacements') + ->method('makeReplacements') ->with("$attribute $rule",$attribute,$rule, $params) ->willReturn("$attribute $rule"); @@ -119,7 +119,7 @@ public function testGetMessageFiles() { ->willReturn("$attribute $rule"); $delegated->expects($this->once()) - ->method('doReplacements') + ->method('makeReplacements') ->with("$attribute $rule",$attribute,$rule, $params) ->willReturn("$attribute $rule"); diff --git a/tests/Remote/ResolverTest.php b/tests/Remote/ResolverTest.php index 60e15060..307e123d 100644 --- a/tests/Remote/ResolverTest.php +++ b/tests/Remote/ResolverTest.php @@ -3,7 +3,7 @@ namespace Proengsoft\JsValidation\Tests\Remote; -use Illuminate\Http\Exception\HttpResponseException; +use Illuminate\Http\Exceptions\HttpResponseException; use Proengsoft\JsValidation\Remote\Resolver; require_once __DIR__.'/../stubs/ResolverTest.php'; diff --git a/tests/Remote/ValidatorTest.php b/tests/Remote/ValidatorTest.php index 6c6f68ac..744e70a2 100644 --- a/tests/Remote/ValidatorTest.php +++ b/tests/Remote/ValidatorTest.php @@ -2,7 +2,7 @@ namespace Proengsoft\JsValidation\Tests\Remote; -use Illuminate\Http\Exception\HttpResponseException; +use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Validation\Validator as LaravelValidator; use Proengsoft\JsValidation\Exceptions\BadRequestHttpException; use Proengsoft\JsValidation\Javascript\ValidatorHandler; diff --git a/tests/Support/DelegatedValidatorTest.php b/tests/Support/DelegatedValidatorTest.php index fa9788f7..4a255b66 100644 --- a/tests/Support/DelegatedValidatorTest.php +++ b/tests/Support/DelegatedValidatorTest.php @@ -173,9 +173,9 @@ public function testIsImplicit() /** * Test Replace all error message place-holders with actual values. */ - public function testDoReplacements() + public function testMakeReplacements() { - $this->callValidatorProtectedMethod('doReplacements', ['message','attribute','rule',[]]); + $this->callValidatorProtectedMethod('makeReplacements', ['message','attribute','rule',[]]); } /** diff --git a/tests/stubs/JsValidatorFactoryTest.php b/tests/stubs/JsValidatorFactoryTest.php index a5c019c4..7829b76b 100644 --- a/tests/stubs/JsValidatorFactoryTest.php +++ b/tests/stubs/JsValidatorFactoryTest.php @@ -3,7 +3,7 @@ if (!class_exists('FormRequest')) { class FormRequest { public function initialize(){} - public function setSession(){} + public function setLaravelSession(){} public function setUserResolver(){} public function setRouteResolver() {} public function setContainer() {} @@ -20,7 +20,7 @@ public function attributes(){return [];} public static function createFromBase() { //$sessionMock = m::mock('Symfony\Component\HttpFoundation\Session\SessionInterface',[]); $mockedRequest = m::mock('\Symfony\Component\HttpFoundation\Request'); - $mockedRequest->shouldReceive('setSession') + $mockedRequest->shouldReceive('setLaravelSession') ->shouldReceive('setUserResolver') ->shouldReceive('setRouteResolver') ->shouldReceive('messages')->andReturn([]) @@ -28,4 +28,4 @@ public static function createFromBase() { return $mockedRequest; } } -} \ No newline at end of file +}