mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
8c529c433e
Make the ValidationException a little bit less mutable than before. All its dependencies are now passed into the constructor. This commit also make the Factory pass the translator to the exceptions allowing to define the translator before the exception gets created. This change is not the ideal one, later I would like to not need the Singleton from the Factory to do that, but for now it seems like a good approach. One more thing that this commit does is to introduce the "id" for Exceptions. Key can be either the defined "name" or the name of the rule that throwed the exception. This method will be handy to identify exceptions better. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
class GroupedValidationException extends NestedValidationException
|
|
{
|
|
public const NONE = 'none';
|
|
public const SOME = 'some';
|
|
|
|
public static $defaultTemplates = [
|
|
self::MODE_DEFAULT => [
|
|
self::NONE => 'All of the required rules must pass for {{name}}',
|
|
self::SOME => 'These rules must pass for {{name}}',
|
|
],
|
|
self::MODE_NEGATIVE => [
|
|
self::NONE => 'None of there rules must pass for {{name}}',
|
|
self::SOME => 'These rules must not pass for {{name}}',
|
|
],
|
|
];
|
|
|
|
protected function chooseTemplate(): string
|
|
{
|
|
$numRules = $this->getParam('passed');
|
|
$numFailed = $this->getRelated()->count();
|
|
|
|
return $numRules === $numFailed ? static::NONE : static::SOME;
|
|
}
|
|
}
|