respect-validation/library/Exceptions/NotOptionalException.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2015-10-15 15:31:45 +02:00
<?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 file
* that was distributed with this source code.
2015-10-15 15:31:45 +02:00
*/
declare(strict_types=1);
2015-10-15 15:31:45 +02:00
namespace Respect\Validation\Exceptions;
/**
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class NotOptionalException extends ValidationException
2015-10-15 15:31:45 +02:00
{
public const NAMED = 'named';
2015-10-15 15:31:45 +02:00
/**
* {@inheritDoc}
*/
protected $defaultTemplates = [
2015-10-18 03:44:47 +02:00
self::MODE_DEFAULT => [
2015-10-15 15:31:45 +02:00
self::STANDARD => 'The value must not be optional',
self::NAMED => '{{name}} must not be optional',
2015-10-18 03:44:47 +02:00
],
self::MODE_NEGATIVE => [
2015-10-15 15:31:45 +02:00
self::STANDARD => 'The value must be optional',
self::NAMED => '{{name}} must be optional',
2015-10-18 03:44:47 +02:00
],
];
2015-10-15 15:31:45 +02:00
/**
* {@inheritDoc}
*/
protected function chooseTemplate(): string
2015-10-15 15:31:45 +02:00
{
if ($this->getParam('input') || $this->getParam('name')) {
return self::NAMED;
}
return self::STANDARD;
2015-10-15 15:31:45 +02:00
}
}