Maslosoft Mangan API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
<?php
/**
* This software package is licensed under AGPL or Commercial license.
*
* @package maslosoft/mangan
* @licence AGPL or Commercial
* @copyright Copyright (c) Piotr Masełkowski <pmaselkowski@gmail.com>
* @copyright Copyright (c) Maslosoft
* @copyright Copyright (c) Others as mentioned in code
* @link https://maslosoft.com/mangan/
*/
namespace Maslosoft\Mangan\Annotations\Validators;
use Maslosoft\Addendum\Helpers\ParamsExpander;
use Maslosoft\Mangan\Meta\ValidatorMeta;
use Maslosoft\Mangan\Validators\Proxy\CountProxy;
use Maslosoft\Mangan\Validators\Traits\AllowEmpty;
use Maslosoft\Mangan\Validators\Traits\When;
/**
* CountValidator validates that the attribute array elements count is of certain length.
*
* Note, this validator should only be used with array type attributes or
* `Countable` interface instance object.
*
* In addition to the {@link message} property for setting a custom error message,
* CountValidator has a couple custom error messages you can set that correspond to different
* validation scenarios. For defining a custom message when the string is too short,
* you may use the {@link tooShort} property. Similarly with {@link tooLong}. The messages may contain
* placeholders that will be replaced with the actual content. In addition to the "{attribute}"
* placeholder, recognized by all validators (see {@link Validator}), StringValidator allows for the following
* placeholders to be specified:
* <ul>
* <li>{min}: when using {@link tooShort}, replaced with minimum length, {@link min}, if set.</li>
* <li>{max}: when using {@link tooLong}, replaced with the maximum length, {@link max}, if set.</li>
* <li>{length}: when using {@link message}, replaced with the exact required length, {@link is}, if set.</li>
* </ul>
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.validators
* @since 1.0
*/
class CountValidatorAnnotation extends ValidatorAnnotation
{
use AllowEmpty,
When;
/**
* @var integer maximum length. Defaults to null, meaning no maximum limit.
*/
public $max = null;
/**
* @var integer minimum length. Defaults to null, meaning no minimum limit.
*/
public $min = null;
/**
* @var integer exact length. Defaults to null, meaning no exact length limit.
*/
public $is = null;
/**
* @var string user-defined error message used when the value is too short.
*/
public $tooShort = null;
/**
* @var string user-defined error message used when the value is too long.
*/
public $tooLong = null;
/**
* @var string
*/
public $msgInvalid = '';
/**
* @var string
*/
public $msgTooShort = '';
/**
* @var string
*/
public $msgTooLong = '';
/**
* @var string
*/
public $msgLength = '';
public function init()
{
$this->proxy = CountProxy::class;
$this->getEntity()->validators[] = new ValidatorMeta(ParamsExpander::expand($this, [
'max',
'min',
'is',
'when',
'tooShort',
'tooLong',
'msgInvalid',
'msgTooShort',
'msgTooLong',
'msgLength',
'allowEmpty',
'message',
'skipOnError',
'on',
'safe',
'except',
'proxy'
]));
}
}
API documentation generated by ApiGen