Merge branch '1.1'

This commit is contained in:
Henrique Moody 2018-01-02 22:57:58 +01:00
commit b10206bd28
No known key found for this signature in database
GPG key ID: 221E9281655813A6
4 changed files with 29 additions and 11 deletions

View file

@ -305,6 +305,9 @@ class ValidationException extends InvalidArgumentException implements ExceptionI
public function setTemplate($template)
{
$this->customTemplate = true;
if (isset(static::$defaultTemplates[$this->mode][$template])) {
$template = static::$defaultTemplates[$this->mode][$template];
}
$this->template = $template;
$this->buildMessage();

View file

@ -29,16 +29,12 @@ class Domain extends AbstractComposite
new Alnum('-'),
new Not(new StartsWith('-')),
new AnyOf(
new Not(
new Contains('--')
),
new AllOf(
new StartsWith('xn--'),
new Callback(function ($str) {
return mb_substr_count($str, '--') == 1;
})
)
)
new Not(new Contains('--')),
new Callback(function ($str) {
return substr_count($str, '--') == 1;
})
),
new Not(new EndsWith('-'))
);
}

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validator as v;
try {
v::when(v::alwaysInvalid(), v::alwaysValid())->check('foo');
} catch (ValidationException $exception) {
echo $exception->getMainMessage();
}
?>
--EXPECT--
"foo" is not valid

View file

@ -68,6 +68,9 @@ class DomainTest extends TestCase
['xn--bcher-kva.ch'],
['mail.xn--bcher-kva.ch'],
['example-hyphen.com'],
['example--valid.com'],
['std--a.com'],
['r--w.com'],
];
}
@ -77,10 +80,10 @@ class DomainTest extends TestCase
[null],
[''],
['2222222domain.local'],
['example--invalid.com'],
['-example-invalid.com'],
['example.invalid.-com'],
['xn--bcher--kva.ch'],
['example.invalid-.com'],
['1.2.3.256'],
['1.2.3.4'],
];