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
21 changes: 21 additions & 0 deletions library/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function getId(): string
return $this->id;
}

public function getName(): string
{
return $this->name;
}

/**
* @return mixed[]
*/
Expand Down Expand Up @@ -136,11 +141,27 @@ public function hasCustomTemplate(): bool
return isset($this->defaultTemplates[$this->mode][$this->template]) === false;
}

public function getTemplate(): string
{
if (!empty($this->template)) {
return $this->template;
}

return $this->template = $this->buildTemplate();
}

protected function chooseTemplate(): string
{
return (string) key($this->defaultTemplates[$this->mode]);
}

protected function buildTemplate(): string
{
$templateKey = $this->chooseTemplate();

return $this->defaultTemplates[$this->mode][$templateKey];
}

private function createMessage(): string
{
return $this->formatter->format(
Expand Down
15 changes: 11 additions & 4 deletions library/Rules/AbstractWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Respect\Validation\Rules;

use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Validatable;

/**
Expand All @@ -23,10 +24,7 @@
*/
abstract class AbstractWrapper extends AbstractRule
{
/**
* @var Validatable
*/
private $validatable;
protected Validatable $validatable;

/**
* Initializes the rule.
Expand All @@ -36,6 +34,15 @@ public function __construct(Validatable $validatable)
$this->validatable = $validatable;
}

public function getValidatable(): Validatable
{
if (!isset($this->validatable)) {
throw new ComponentException('There is no defined validatable');
}

return $this->validatable;
}

/**
* {@inheritDoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Alnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Henrique Moody <[email protected]>
* @author Nick Lombard <[email protected]>
*/
final class Alnum extends AbstractFilterRule
class Alnum extends AbstractFilterRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Alpha.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Henrique Moody <[email protected]>
* @author Nick Lombard <[email protected]>
*/
final class Alpha extends AbstractFilterRule
class Alpha extends AbstractFilterRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/AlwaysInvalid.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class AlwaysInvalid extends AbstractRule
class AlwaysInvalid extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/AlwaysValid.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class AlwaysValid extends AbstractRule
class AlwaysValid extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/AnyOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class AnyOf extends AbstractComposite
class AnyOf extends AbstractComposite
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Henrique Moody <[email protected]>
* @author João Torquato <[email protected]>
*/
final class ArrayType extends AbstractRule
class ArrayType extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/ArrayVal.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Emmerson Siqueira <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class ArrayVal extends AbstractRule
class ArrayVal extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Emmerson Siqueira <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class Attribute extends AbstractRelated
class Attribute extends AbstractRelated
{
public function __construct(string $reference, ?Validatable $rule = null, bool $mandatory = true)
{
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Base extends AbstractRule
class Base extends AbstractRule
{
/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Base64.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Jens Segers <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Base64 extends AbstractRule
class Base64 extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class Between extends AbstractEnvelope
class Between extends AbstractEnvelope
{
use CanCompareValues;

Expand Down
2 changes: 1 addition & 1 deletion library/Rules/BoolType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Devin Torres <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class BoolType extends AbstractRule
class BoolType extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/BoolVal.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class BoolVal extends AbstractRule
class BoolVal extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Bsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Ronald Drenth <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Bsn extends AbstractRule
class Bsn extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Emmerson Siqueira <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class Call extends AbstractRule
class Call extends AbstractRule
{
/**
* @var callable
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Henrique Moody <[email protected]>
*/
final class CallableType extends AbstractRule
class CallableType extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Callback extends AbstractRule
class Callback extends AbstractRule
{
/**
* @var callable
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Charset extends AbstractRule
class Charset extends AbstractRule
{
/**
* @var string[]
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Cnh.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Kinn Coelho Julião <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Cnh extends AbstractRule
class Cnh extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Cnpj.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Renato Moura <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Cnpj extends AbstractRule
class Cnpj extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Consonant.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Henrique Moody <[email protected]>
* @author Nick Lombard <[email protected]>
*/
final class Consonant extends AbstractFilterRule
class Consonant extends AbstractFilterRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Marcelo Araujo <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Contains extends AbstractRule
class Contains extends AbstractRule
{
/**
* @var mixed
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/ContainsAny.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Henrique Moody <[email protected]>
* @author Kirill Dlussky <[email protected]>
*/
final class ContainsAny extends AbstractEnvelope
class ContainsAny extends AbstractEnvelope
{
/**
* Initializes the rule.
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Henrique Moody <[email protected]>
* @author Nick Lombard <[email protected]>
*/
final class Control extends AbstractFilterRule
class Control extends AbstractFilterRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Countable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author João Torquato <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Countable extends AbstractRule
class Countable extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/CountryCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class CountryCode extends AbstractSearcher
class CountryCode extends AbstractSearcher
{
/**
* The ISO representation of a country code.
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Cpf.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Jean Pimentel <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Cpf extends AbstractRule
class Cpf extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @author William Espindola <[email protected]>
* @author Rakshit Arora <[email protected]>
*/
final class CreditCard extends AbstractRule
class CreditCard extends AbstractRule
{
public const ANY = 'Any';

Expand Down
2 changes: 1 addition & 1 deletion library/Rules/CurrencyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Tim Strijdhorst <[email protected]>
* @author William Espindola <[email protected]>
*/
final class CurrencyCode extends AbstractSearcher
class CurrencyCode extends AbstractSearcher
{
/**
* @see http://www.currency-iso.org/en/home/tables/table-a1.html
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author Bruno Luiz da Silva <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class Date extends AbstractRule
class Date extends AbstractRule
{
use CanValidateDateTime;

Expand Down
2 changes: 1 addition & 1 deletion library/Rules/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Emmerson Siqueira <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class DateTime extends AbstractRule
class DateTime extends AbstractRule
{
use CanValidateDateTime;

Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Henrique Moody <[email protected]>
*/
final class Decimal extends AbstractRule
class Decimal extends AbstractRule
{
/**
* @var int
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Digit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Henrique Moody <[email protected]>
* @author Nick Lombard <[email protected]>
*/
final class Digit extends AbstractFilterRule
class Digit extends AbstractFilterRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Directory extends AbstractRule
class Directory extends AbstractRule
{
/**
* {@inheritDoc}
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author Nick Lombard <[email protected]>
* @author Róbert Nagy <[email protected]>
*/
final class Domain extends AbstractRule
class Domain extends AbstractRule
{
/**
* @var Validatable
Expand Down
2 changes: 1 addition & 1 deletion library/Rules/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @author Nick Lombard <[email protected]>
* @author William Espindola <[email protected]>
*/
final class Each extends AbstractRule
class Each extends AbstractRule
{
use CanValidateIterable;

Expand Down
Loading