2010-12-07 20:17:43 +01:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Respect/Validation.
|
|
|
|
*
|
|
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
*
|
2019-05-23 16:21:34 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
|
|
* that was distributed with this source code.
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-12-07 20:17:43 +01:00
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
2018-09-04 13:31:58 +02:00
|
|
|
/**
|
|
|
|
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
2018-11-25 17:20:02 +01:00
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
2018-09-04 13:31:58 +02:00
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2019-03-27 15:27:46 +01:00
|
|
|
* @author Mazen Touati <mazen_touati@hotmail.com>
|
2018-09-04 13:31:58 +02:00
|
|
|
*/
|
|
|
|
final class LengthException extends ValidationException
|
2010-12-07 20:17:43 +01:00
|
|
|
{
|
2018-05-23 10:07:41 +02:00
|
|
|
public const BOTH = 'both';
|
|
|
|
public const LOWER = 'lower';
|
2019-03-27 15:27:46 +01:00
|
|
|
public const LOWER_INCLUSIVE = 'lower_inclusive';
|
2018-05-23 10:07:41 +02:00
|
|
|
public const GREATER = 'greater';
|
2019-03-27 15:27:46 +01:00
|
|
|
public const GREATER_INCLUSIVE = 'greater_inclusive';
|
2018-05-23 10:07:41 +02:00
|
|
|
public const EXACT = 'exact';
|
2011-02-19 20:47:34 +01:00
|
|
|
|
2018-09-04 13:31:58 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-09-04 13:31:58 +02:00
|
|
|
*/
|
2019-05-12 01:30:36 +02:00
|
|
|
protected $defaultTemplates = [
|
2015-10-18 03:44:47 +02:00
|
|
|
self::MODE_DEFAULT => [
|
2011-04-10 01:34:21 +02:00
|
|
|
self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}',
|
|
|
|
self::LOWER => '{{name}} must have a length greater than {{minValue}}',
|
2019-03-27 15:27:46 +01:00
|
|
|
self::LOWER_INCLUSIVE => '{{name}} must have a length greater than or equal to {{minValue}}',
|
2011-04-10 01:34:21 +02:00
|
|
|
self::GREATER => '{{name}} must have a length lower than {{maxValue}}',
|
2019-03-27 15:27:46 +01:00
|
|
|
self::GREATER_INCLUSIVE => '{{name}} must have a length lower than or equal to {{maxValue}}',
|
2017-02-12 18:14:38 +01:00
|
|
|
self::EXACT => '{{name}} must have a length of {{maxValue}}',
|
2015-10-18 03:44:47 +02:00
|
|
|
],
|
|
|
|
self::MODE_NEGATIVE => [
|
2011-04-10 01:34:21 +02:00
|
|
|
self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}',
|
|
|
|
self::LOWER => '{{name}} must not have a length greater than {{minValue}}',
|
2019-03-27 15:27:46 +01:00
|
|
|
self::LOWER_INCLUSIVE => '{{name}} must not have a length greater than or equal to {{minValue}}',
|
2011-04-10 01:34:21 +02:00
|
|
|
self::GREATER => '{{name}} must not have a length lower than {{maxValue}}',
|
2019-03-27 15:27:46 +01:00
|
|
|
self::GREATER_INCLUSIVE => '{{name}} must not have a length lower than or equal to {{maxValue}}',
|
2017-02-12 18:14:38 +01:00
|
|
|
self::EXACT => '{{name}} must not have a length of {{maxValue}}',
|
2015-10-18 03:44:47 +02:00
|
|
|
],
|
|
|
|
];
|
2011-04-10 01:34:21 +02:00
|
|
|
|
2018-09-04 13:31:58 +02:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-09-04 13:31:58 +02:00
|
|
|
*/
|
2018-05-24 07:47:09 +02:00
|
|
|
protected function chooseTemplate(): string
|
2011-02-19 20:47:34 +01:00
|
|
|
{
|
2019-03-27 15:27:46 +01:00
|
|
|
$isInclusive = $this->getParam('inclusive');
|
|
|
|
|
2013-01-14 22:55:03 +01:00
|
|
|
if (!$this->getParam('minValue')) {
|
2019-03-27 15:27:46 +01:00
|
|
|
return $isInclusive === true ? self::GREATER_INCLUSIVE : self::GREATER;
|
2017-02-12 18:14:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->getParam('maxValue')) {
|
2019-03-27 15:27:46 +01:00
|
|
|
return $isInclusive === true ? self::LOWER_INCLUSIVE : self::LOWER;
|
2013-01-14 22:55:03 +01:00
|
|
|
}
|
2016-10-30 10:39:23 +01:00
|
|
|
|
2017-02-12 18:14:38 +01:00
|
|
|
if ($this->getParam('minValue') == $this->getParam('maxValue')) {
|
|
|
|
return self::EXACT;
|
|
|
|
}
|
|
|
|
|
2019-02-09 12:07:38 +01:00
|
|
|
return self::BOTH;
|
2011-02-19 20:47:34 +01:00
|
|
|
}
|
2011-02-10 21:49:48 +01:00
|
|
|
}
|