Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ node_modules

#bower
bower_components

.idea
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Javascript/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/JsValidatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions src/Remote/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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]);
}
Expand All @@ -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]);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Support/DelegatedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Validation\Validator as BaseValidator;
use Illuminate\Validation\ValidationRuleParser;

class DelegatedValidator
{
Expand Down Expand Up @@ -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]);
}

/**
Expand Down Expand Up @@ -147,7 +148,7 @@ public function getMessage($attribute, $rule)
*/
public function parseRule($rules)
{
return $this->callValidator('parseRule', [$rules]);
return ValidationRuleParser::parse([$rules]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Javascript/MessageParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion tests/Remote/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion tests/Remote/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/DelegatedValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',[]]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/stubs/JsValidatorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -20,12 +20,12 @@ 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([])
->shouldReceive('attributes')->andReturn([]);
return $mockedRequest;
}
}
}
}