mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
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>
36 lines
1,008 B
PHP
36 lines
1,008 B
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 KeyValueException extends ValidationException
|
|
{
|
|
public const COMPONENT = 'component';
|
|
|
|
public static $defaultTemplates = [
|
|
self::MODE_DEFAULT => [
|
|
self::STANDARD => 'Key {{name}} must be present',
|
|
self::COMPONENT => '{{baseKey}} must be valid to validate {{comparedKey}}',
|
|
],
|
|
self::MODE_NEGATIVE => [
|
|
self::STANDARD => 'Key {{name}} must not be present',
|
|
self::COMPONENT => '{{baseKey}} must not be valid to validate {{comparedKey}}',
|
|
],
|
|
];
|
|
|
|
protected function chooseTemplate(): string
|
|
{
|
|
return $this->getParam('component') ? static::COMPONENT : static::STANDARD;
|
|
}
|
|
}
|