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
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
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
5 changes: 3 additions & 2 deletions src/JsValidatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -157,7 +158,7 @@ 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());
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/Remote/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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 Proengsoft\JsValidation\Support\AccessProtectedTrait;

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

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

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

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Support/ValidationRuleParserProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Proengsoft\JsValidation\Support;
use Illuminate\Validation\ValidationRuleParser;
class ValidationRuleParserProxy
{
/**
* Extract the rule name and parameters from a rule.
*
* @param array|string $rules
* @return array
*/
public function parse($rules)
{
return ValidationRuleParser::parse($rules);
}
}
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