mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Move template definitions to the rules
It's easier to identify the reason for choosing a specific message in the rule than in the exception. The same goes for the key we use to determine the templates. This change will simplify the `ValidationException` because it will already receive the template it needs to use. As a consequence, the `Factory` also becomes more straightforward. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
3334529591
commit
dd896bb12d
181 changed files with 1042 additions and 680 deletions
|
|
@ -9,35 +9,19 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use function count;
|
||||
use Respect\Validation\Rules\KeySet;
|
||||
|
||||
final class KeySetException extends GroupedValidationException implements NonOmissibleException
|
||||
{
|
||||
public const STRUCTURE = 'structure';
|
||||
public const STRUCTURE_EXTRA = 'structure_extra';
|
||||
|
||||
/**
|
||||
* @var array<string, array<string, string>>
|
||||
*/
|
||||
protected array $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::NONE => 'All of the required rules must pass for {{name}}',
|
||||
self::SOME => 'These rules must pass for {{name}}',
|
||||
self::STRUCTURE => 'Must have keys {{keys}}',
|
||||
self::STRUCTURE_EXTRA => 'Must not have keys {{extraKeys}}',
|
||||
KeySet::TEMPLATE_NONE => 'All of the required rules must pass for {{name}}',
|
||||
KeySet::TEMPLATE_SOME => 'These rules must pass for {{name}}',
|
||||
KeySet::TEMPLATE_STRUCTURE => 'Must have keys {{keys}}',
|
||||
KeySet::TEMPLATE_STRUCTURE_EXTRA => 'Must not have keys {{extraKeys}}',
|
||||
],
|
||||
];
|
||||
|
||||
protected function chooseTemplate(): string
|
||||
{
|
||||
if (count($this->getParam('extraKeys'))) {
|
||||
return self::STRUCTURE_EXTRA;
|
||||
}
|
||||
|
||||
if (count($this->getChildren()) === 0) {
|
||||
return self::STRUCTURE;
|
||||
}
|
||||
|
||||
return parent::chooseTemplate();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue