fix translator
This commit is contained in:
parent
1ac10ae752
commit
1efd84bdb5
|
@ -3,5 +3,5 @@ services:
|
||||||
class: Bluesquare\ValidatorBundle\Validator
|
class: Bluesquare\ValidatorBundle\Validator
|
||||||
autowire: true
|
autowire: true
|
||||||
public: true
|
public: true
|
||||||
arguments: ['@request_stack', '@translator.data_collector']
|
arguments: ['@request_stack', '@translator']
|
||||||
Bluesquare\ValidatorBundle\Validator: '@bluesquare.validator'
|
Bluesquare\ValidatorBundle\Validator: '@bluesquare.validator'
|
||||||
|
|
|
@ -131,7 +131,7 @@ class Validator
|
||||||
|
|
||||||
public function message()
|
public function message()
|
||||||
{
|
{
|
||||||
$result = $this->failed() ? 'form-error' : 'form-success';
|
$result = $this->failed() ? 'form_error' : 'form_success';
|
||||||
$message = null;
|
$message = null;
|
||||||
if (!is_null($this->context)) {
|
if (!is_null($this->context)) {
|
||||||
$message = $this->translator->trans("$this->context.$result", [], "validator");
|
$message = $this->translator->trans("$this->context.$result", [], "validator");
|
||||||
|
@ -241,10 +241,10 @@ class Validator
|
||||||
|
|
||||||
switch ($name)
|
switch ($name)
|
||||||
{
|
{
|
||||||
case 'required-file':
|
case 'required_file':
|
||||||
$success = $this->hasFile($field);
|
$success = $this->hasFile($field);
|
||||||
break;
|
break;
|
||||||
case 'required-files':
|
case 'required_files':
|
||||||
$success = $this->hasFiles($field);
|
$success = $this->hasFiles($field);
|
||||||
break;
|
break;
|
||||||
case 'required':
|
case 'required':
|
||||||
|
@ -283,7 +283,7 @@ class Validator
|
||||||
$_pattern = "%^((?:(?:https?|ftp)://))?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$%iuS";
|
$_pattern = "%^((?:(?:https?|ftp)://))?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]-*)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$%iuS";
|
||||||
$success = preg_match($_pattern, $value);
|
$success = preg_match($_pattern, $value);
|
||||||
break;
|
break;
|
||||||
case 'inArray':
|
case 'in_array':
|
||||||
$success = in_array($value, $data['values']);
|
$success = in_array($value, $data['values']);
|
||||||
break;
|
break;
|
||||||
case 'min':
|
case 'min':
|
||||||
|
@ -292,11 +292,14 @@ class Validator
|
||||||
case 'max':
|
case 'max':
|
||||||
$success = max($value, $data['length']) == $value ? true : false;
|
$success = max($value, $data['length']) == $value ? true : false;
|
||||||
break;
|
break;
|
||||||
case 'minLength':
|
case 'min_length':
|
||||||
$success = strlen($value) < $data['min-length'] ? true : false;
|
$success = strlen($value) >= $data['length'] ? true : false;
|
||||||
break;
|
break;
|
||||||
case 'maxLength':
|
case 'max_length':
|
||||||
$success = strlen($value) > $data['min-length'] ? true : false;
|
$success = strlen($value) <= $data['length'] ? true : false;
|
||||||
|
break;
|
||||||
|
case 'identical':
|
||||||
|
$success = $value == $this->get($data['target']);
|
||||||
break;
|
break;
|
||||||
// (éwé c'est un switch)
|
// (éwé c'est un switch)
|
||||||
}
|
}
|
||||||
|
@ -390,13 +393,13 @@ class Validator
|
||||||
|
|
||||||
public function requiredFile($name)
|
public function requiredFile($name)
|
||||||
{
|
{
|
||||||
$this->rule($name, 'required-file');
|
$this->rule($name, 'required_file');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiredFiles($name)
|
public function requiredFiles($name)
|
||||||
{
|
{
|
||||||
$this->rule($name, 'required-files');
|
$this->rule($name, 'required_files');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,19 +417,25 @@ class Validator
|
||||||
|
|
||||||
public function minLength($field, $length)
|
public function minLength($field, $length)
|
||||||
{
|
{
|
||||||
$this->rule($field, 'min-length', ['length' => $length]);
|
$this->rule($field, 'min_length', ['length' => $length]);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function maxLength($field, $length)
|
public function maxLength($field, $length)
|
||||||
{
|
{
|
||||||
$this->rule($field, 'max-length', ['length' => $length]);
|
$this->rule($field, 'max_length', ['length' => $length]);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function inArray($field, $values)
|
public function inArray($field, $values)
|
||||||
{
|
{
|
||||||
$this->rule($field, 'inArray', ['values' => $values]);
|
$this->rule($field, 'in_array', ['values' => $values]);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function identical($field, $field_confirm)
|
||||||
|
{
|
||||||
|
$this->rule($field_confirm, 'identical', ['target' => $field]);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue