Filter\Exception
ClassSource on GitHubPhalcon\Filter\Exception
Exceptions thrown in Phalcon\Filter will use this class
\ExceptionPhalcon\Filter\Exception
Filter\Exceptions\FilterNotRegistered
ClassSource on GitHub\ExceptionPhalcon\Filter\ExceptionPhalcon\Filter\Exceptions\FilterNotRegistered
Uses Phalcon\Filter\Exception
Method Summary
Methods
__construct()
public function __construct( string $name );Filter\Filter
ClassSource on GitHubLazy loads, stores and exposes sanitizer objects
@method int absint(mixed $input) @method string alnum(mixed $input) @method string alpha(mixed $input) @method bool bool(mixed $input) @method string email(string $input) @method float float(mixed $input) @method int int(string $input) @method string|false ip(string $input, int $filter = FILTER_FLAG_NONE) @method string lower(string $input) @method string lowerfirst(string $input) @method mixed regex(mixed $input, mixed $pattern, mixed $replace) @method mixed remove(mixed $input, mixed $replace) @method mixed replace(mixed $input, mixed $source, mixed $target) @method string special(string $input) @method string specialfull(string $input) @method string string(string $input) @method string stringlegacy(mixed $input) @method string striptags(string $input) @method string trim(string $input) @method string upper(string $input) @method string upperFirst(string $input) @method string|null upperWords(string $input) @method string|null url(string $input)
@property array $mapper @property array $services
Phalcon\Filter\Filter- implementsPhalcon\Filter\FilterInterface
Uses Phalcon\Filter\Exceptions\FilterNotRegistered · Phalcon\Filter\Sanitize\AbsInt · Phalcon\Filter\Sanitize\Alnum · Phalcon\Filter\Sanitize\Alpha · Phalcon\Filter\Sanitize\BoolVal · Phalcon\Filter\Sanitize\Email · Phalcon\Filter\Sanitize\FloatVal · Phalcon\Filter\Sanitize\IntVal · Phalcon\Filter\Sanitize\Ip · Phalcon\Filter\Sanitize\Lower · Phalcon\Filter\Sanitize\LowerFirst · Phalcon\Filter\Sanitize\Regex · Phalcon\Filter\Sanitize\Remove · Phalcon\Filter\Sanitize\Replace · Phalcon\Filter\Sanitize\Special · Phalcon\Filter\Sanitize\SpecialFull · Phalcon\Filter\Sanitize\StringVal · Phalcon\Filter\Sanitize\StringValLegacy · Phalcon\Filter\Sanitize\Striptags · Phalcon\Filter\Sanitize\Trim · Phalcon\Filter\Sanitize\Upper · Phalcon\Filter\Sanitize\UpperFirst · Phalcon\Filter\Sanitize\UpperWords · Phalcon\Filter\Sanitize\Url
Method Summary
public__call(string$name,array$args)Magic call to make the helper objects available as methods.public__construct( array$mapper = [] )Filter constructor.publicmixedget( string$name )Get a service. If it is not in the mapper array, create a new object,publicarraygetDefaultMapper()Returns the default sanitizer name to class map. This is the singlepublicboolhas( string$name )Checks if a service exists in the map arraypublicmixedsanitize(mixed$value,mixed$sanitizers,bool$noRecursive = false)Sanitizes a value with a specified single or set of sanitizerspublicvoidset(string$name,mixed$service)Set a new service to the mapper arrayprotectedvoidinit( array$mapper )Loads the objects in the internal mapper arrayConstants
stringFILTER_ABSINT = "absint"stringFILTER_ALNUM = "alnum"stringFILTER_ALPHA = "alpha"stringFILTER_BOOL = "bool"stringFILTER_EMAIL = "email"stringFILTER_FLOAT = "float"stringFILTER_INT = "int"stringFILTER_IP = "ip"stringFILTER_LOWER = "lower"stringFILTER_LOWERFIRST = "lowerfirst"stringFILTER_REGEX = "regex"stringFILTER_REMOVE = "remove"stringFILTER_REPLACE = "replace"stringFILTER_SPECIAL = "special"stringFILTER_SPECIALFULL = "specialfull"stringFILTER_STRING = "string"stringFILTER_STRING_LEGACY = "stringlegacy"stringFILTER_STRIPTAGS = "striptags"stringFILTER_TRIM = "trim"stringFILTER_UPPER = "upper"stringFILTER_UPPERFIRST = "upperfirst"stringFILTER_UPPERWORDS = "upperwords"stringFILTER_URL = "url"Properties
protectedarray$mapper = []protectedarray$services = []Methods
__call()
public function __call(
string $name,
array $args
);Magic call to make the helper objects available as methods.
__construct()
public function __construct( array $mapper = [] );Filter constructor.
get()
public function get( string $name ): mixed;Get a service. If it is not in the mapper array, create a new object, set it and then return it.
getDefaultMapper()
public static function getDefaultMapper(): array;Returns the default sanitizer name to class map. This is the single
source for the built-in sanitizer registry: when adding a sanitizer,
add its FILTER_* constant and its entry here.
has()
public function has( string $name ): bool;Checks if a service exists in the map array
sanitize()
public function sanitize(
mixed $value,
mixed $sanitizers,
bool $noRecursive = false
): mixed;Sanitizes a value with a specified single or set of sanitizers
Array policy: when $value is an array and $noRecursive is false
(the default), each element is passed to the sanitizer individually
and an array is returned - recursion is one level deep only. Elements
that are themselves arrays are passed to the sanitizer as-is, which
raises a TypeError for sanitizers that type their value parameter
(e.g. trim). When $noRecursive is true, the whole array is
passed to the sanitizer as a single value.
set()
public function set(
string $name,
mixed $service
): void;Set a new service to the mapper array
init()
protected function init( array $mapper ): void;Loads the objects in the internal mapper array
Filter\FilterFactory
ClassSource on GitHubClass FilterFactory
@package Phalcon\Filter
Phalcon\Filter\FilterFactory
Uses Phalcon\Filter\Filter
Method Summary
publicFilterInterfacenewInstance()Returns a Locator object with all the helpers defined in anonymousprotectedarraygetServices()Returns the available adaptersMethods
newInstance()
public function newInstance(): FilterInterface;Returns a Locator object with all the helpers defined in anonymous functions
getServices()
protected function getServices(): array;Returns the available adapters
Filter\FilterInterface
InterfaceSource on GitHubLazy loads, stores and exposes sanitizer objects
Phalcon\Filter\FilterInterface
Method Summary
Methods
sanitize()
public function sanitize(
mixed $value,
mixed $sanitizers,
bool $noRecursive = false
): mixed;Sanitizes a value with a specified single or set of sanitizers
Array policy: when $value is an array and $noRecursive is false
(the default), each element is sanitized individually and an array is
returned - recursion is one level deep only. When $noRecursive is
true, the whole array is passed to the sanitizer as a single value.
Filter\Sanitize\AbsInt
ClassSource on GitHubPhalcon\Filter\Sanitize\AbsInt
Sanitizes a value to absolute integer
Phalcon\Filter\Sanitize\AbsInt- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\Alnum
ClassSource on GitHubPhalcon\Filter\Sanitize\Alnum
Sanitizes a value to an alphanumeric value
Phalcon\Filter\Sanitize\Alnum- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\Alpha
ClassSource on GitHubPhalcon\Filter\Sanitize\Alpha
Sanitizes a value to an alpha value
Phalcon\Filter\Sanitize\Alpha- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\BoolVal
ClassSource on GitHubPhalcon\Filter\Sanitize\BoolVal
Sanitizes a value to boolean
Phalcon\Filter\Sanitize\BoolVal- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\Email
ClassSource on GitHubPhalcon\Filter\Sanitize\Email
Sanitizes an email string
Phalcon\Filter\Sanitize\Email- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\FloatVal
ClassSource on GitHubPhalcon\Filter\Sanitize\FloatVal
Sanitizes a value to float
Phalcon\Filter\Sanitize\FloatVal- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\IntVal
ClassSource on GitHubPhalcon\Filter\Sanitize\IntVal
Sanitizes a value to integer
Phalcon\Filter\Sanitize\IntVal- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\Ip
ClassSource on GitHubPhalcon\Filter\Sanitize\IP
Sanitizes a value to an ip address or CIDR range
Phalcon\Filter\Sanitize\Ip- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke(
string $input,
int $filter = 0
): string|false;Filter\Sanitize\Lower
ClassSource on GitHubPhalcon\Filter\Sanitize\Lower
Sanitizes a value to lowercase
Phalcon\Filter\Sanitize\Lower- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer · Phalcon\Traits\Php\MbCaseTrait
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\LowerFirst
ClassSource on GitHubPhalcon\Filter\Sanitize\LowerFirst
Sanitizes a value to lcfirst
Phalcon\Filter\Sanitize\LowerFirst- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\Regex
ClassSource on GitHubPhalcon\Filter\Sanitize\Regex
Sanitizes a value performing preg_replace
Phalcon\Filter\Sanitize\Regex- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke(
mixed $input,
mixed $pattern,
mixed $replace
);Filter\Sanitize\Remove
ClassSource on GitHubPhalcon\Filter\Sanitize\Remove
Sanitizes a value removing parts of a string
Phalcon\Filter\Sanitize\Remove- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke(
mixed $input,
mixed $replace
);Filter\Sanitize\Replace
ClassSource on GitHubPhalcon\Filter\Sanitize\Replace
Sanitizes a value replacing parts of a string
Phalcon\Filter\Sanitize\Replace- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke(
mixed $input,
mixed $from,
mixed $to
);Filter\Sanitize\Special
ClassSource on GitHubPhalcon\Filter\Sanitize\Special
Sanitizes a value special characters
Phalcon\Filter\Sanitize\Special- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\SpecialFull
ClassSource on GitHubPhalcon\Filter\Sanitize\SpecialFull
Sanitizes a value special characters (htmlspecialchars() and ENT_QUOTES)
Phalcon\Filter\Sanitize\SpecialFull- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\StringVal
ClassSource on GitHubSanitizes a value to string
Phalcon\Filter\Sanitize\StringVal- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke(
string $input,
int $flags = 11
): string;Filter\Sanitize\StringValLegacy
ClassSource on GitHubSanitizes a value to string using filter_var(). The filter provides
backwards compatibility with versions prior to v5. For PHP higher or equal to
8.1, the filter will remain the string unchanged. If anything other than a
string is passed, the method will return false
Phalcon\Filter\Sanitize\StringValLegacy- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Sanitize\Striptags
ClassSource on GitHubPhalcon\Filter\Sanitize\Striptags
Sanitizes a value striptags
Phalcon\Filter\Sanitize\Striptags- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\Trim
ClassSource on GitHubPhalcon\Filter\Sanitize\Trim
Sanitizes a value removing leading and trailing spaces
Phalcon\Filter\Sanitize\Trim- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\Upper
ClassSource on GitHubPhalcon\Filter\Sanitize\Upper
Sanitizes a value to uppercase
Phalcon\Filter\Sanitize\Upper- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer · Phalcon\Traits\Php\MbCaseTrait
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\UpperFirst
ClassSource on GitHubPhalcon\Filter\Sanitize\UpperFirst
Sanitizes a value to ucfirst
Phalcon\Filter\Sanitize\UpperFirst- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\UpperWords
ClassSource on GitHubPhalcon\Filter\Sanitize\UpperWords
Sanitizes a value to uppercase the first character of each word
Phalcon\Filter\Sanitize\UpperWords- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer · Phalcon\Traits\Php\MbCaseTrait
Method Summary
Methods
__invoke()
public function __invoke( string $input );Filter\Sanitize\Url
ClassSource on GitHubPhalcon\Filter\Sanitize\Url
Sanitizes a value url
Phalcon\Filter\Sanitize\Url- implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary
Methods
__invoke()
public function __invoke( mixed $input );Filter\Validation
ClassSource on GitHubAllows to validate data using custom or built-in validators
\stdClassPhalcon\Di\InjectablePhalcon\Filter\Validation- implementsPhalcon\Filter\Validation\ValidationInterface
Uses Phalcon\Di\Di · Phalcon\Di\DiInterface · Phalcon\Di\Injectable · Phalcon\Filter\FilterInterface · Phalcon\Filter\Validation\AbstractCombinedFieldsValidator · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Exceptions\FilterServiceUnavailable · Phalcon\Filter\Validation\Exceptions\InvalidFieldType · Phalcon\Filter\Validation\Exceptions\InvalidFilterService · Phalcon\Filter\Validation\Exceptions\InvalidValidationData · Phalcon\Filter\Validation\Exceptions\InvalidValidator · Phalcon\Filter\Validation\Exceptions\InvalidValidatorScope · Phalcon\Filter\Validation\Exceptions\NoDataToValidate · Phalcon\Filter\Validation\Exceptions\NoValidators · Phalcon\Filter\Validation\Exceptions\ValidationEntityNotObject · Phalcon\Filter\Validation\ValidationInterface · Phalcon\Filter\Validation\ValidatorInterface · Phalcon\Messages\MessageInterface · Phalcon\Messages\Messages
Method Summary
public__construct( array$validators = [] )Phalcon\Filter\Validation constructorpublicstaticadd(mixed$field,ValidatorInterface$validator)Adds a validator to a fieldpublicstaticappendMessage( MessageInterface$message )Appends a message to the messages listpublicstaticbind(mixed$entity,mixed$data,array$whitelist = [])Assigns the data to an entitypublicboolfails()Verify if validation fails by verifying if there are messages in the current validationpublicmixedgetData()publicstringgetDefaultMessage( string$validatorClassName )Returns the default message registered for a validator class, or anpublicmixedgetEntity()Returns the bound entitypublicmixed|nullgetFilters( string|null$field = null )Returns all the filters or a specific onepublicstringgetLabel( mixed$field )Get label for fieldpublicMessagesgetMessages()Returns the registered validatorspublicarraygetValidators()Returns the validators added to the validationpublicmixed|nullgetValue( string$field )Gets the a value to validate in the array/object data sourcepublicmixed|nullgetValueByData(mixed$data,string$field)Gets the a value to validate in the array/object data sourcepublicmixed|nullgetValueByEntity(mixed$entity,string$field)Gets the a value to validate in the object entity sourcepublicstaticrule(mixed$field,ValidatorInterface$validator)Alias of add methodpublicstaticrules(mixed$field,array$validators)Adds the validators to a fieldpublicarraysetDefaultMessages( array$messages = [] )Registers default messages for validators, keyed by validator classpublicvoidsetEntity( mixed$entity )Sets the bound entitypublicstaticsetFilters(mixed$field,mixed$filters)Adds filters to the fieldpublicvoidsetLabels( array$labels )Adds labels for fieldspublicstaticsetValidators( array$validators )Sets the validator arraypublicMessages|boolvalidate(mixed$data = null,mixed$entity = null,array$whitelist = [])Validate a set of data according to a set of rulesprotectedboolpreChecking(mixed$field,ValidatorInterface$validator)Internal validations, if it returns true, then skip the current validatorProperties
protectedarray$combinedFieldsValidators = []protectedmixed$dataprotectedarray$defaultMessages = []Default messages for validators, keyed by validator class name Declared without an array initializer on purpose: an initialized static array makes Zephir emit a zephir_init_static_properties() function that fails to compile in the single-file build. It is null until first set and treated as an empty array by the accessors below.protectedobject|null$entity = nullprotectedarray$filters = []protectedarray$labels = []protectedMessages$messagesprotectedarray$validators = []List of validatorsprotectedarray$values = []Calculated valuesprotectedarray$whitelist = []Methods
__construct()
public function __construct( array $validators = [] );Phalcon\Filter\Validation constructor
add()
public function add(
mixed $field,
ValidatorInterface $validator
): static;Adds a validator to a field
appendMessage()
public function appendMessage( MessageInterface $message ): static;Appends a message to the messages list
bind()
public function bind(
mixed $entity,
mixed $data,
array $whitelist = []
): static;Assigns the data to an entity The entity is used to obtain the validation values
$entity = new Author();
$fields = ['name', 'email', 'imageUrl'];
$validation = new AuthorValidation();
$validation->bind($entity, $_POST, $fields);
$validation->validate();fails()
public function fails(): bool;Verify if validation fails by verifying if there are messages in the current validation
getData()
public function getData(): mixed;getDefaultMessage()
public static function getDefaultMessage( string $validatorClassName ): string;Returns the default message registered for a validator class, or an empty string when none has been registered.
getEntity()
public function getEntity(): mixed;Returns the bound entity
getFilters()
public function getFilters( string|null $field = null ): mixed|null;Returns all the filters or a specific one
getLabel()
public function getLabel( mixed $field ): string;Get label for field
getMessages()
public function getMessages(): Messages;Returns the registered validators
getValidators()
public function getValidators(): array;Returns the validators added to the validation
getValue()
public function getValue( string $field ): mixed|null;Gets the a value to validate in the array/object data source
getValueByData()
public function getValueByData(
mixed $data,
string $field
): mixed|null;Gets the a value to validate in the array/object data source
getValueByEntity()
public function getValueByEntity(
mixed $entity,
string $field
): mixed|null;Gets the a value to validate in the object entity source
rule()
public function rule(
mixed $field,
ValidatorInterface $validator
): static;Alias of add method
rules()
public function rules(
mixed $field,
array $validators
): static;Adds the validators to a field
setDefaultMessages()
public static function setDefaultMessages( array $messages = [] ): array;Registers default messages for validators, keyed by validator class name. A registered default is used when a validator does not define its own message; a message set on the validator instance still wins. Calls are merged, so defaults can be registered incrementally.
setEntity()
public function setEntity( mixed $entity ): void;Sets the bound entity
setFilters()
public function setFilters(
mixed $field,
mixed $filters
): static;Adds filters to the field
setLabels()
public function setLabels( array $labels ): void;Adds labels for fields
setValidators()
public function setValidators( array $validators ): static;Sets the validator array
validate()
public function validate(
mixed $data = null,
mixed $entity = null,
array $whitelist = []
): Messages|bool;Validate a set of data according to a set of rules
You can use $validation->bind(entity, data, whitelist)->validate() When you use bind(), the this->data is already set, so you can reuse it here
// using bind() with $whitelist fields
$entity = new Author();
$fields = ['name', 'email', 'imageUrl'];
$validation = new AuthorValidation();
$validation->bind($entity, $_POST, $fields);
$validation->validate();
// directly using validate
$validation = new AuthorValidation();
$validation->validate($_POST, $entity, $fields);preChecking()
protected function preChecking(
mixed $field,
ValidatorInterface $validator
): bool;Internal validations, if it returns true, then skip the current validator
Filter\Validation\AbstractCombinedFieldsValidator
AbstractSource on GitHubThis is a base class for combined fields validators
Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractCombinedFieldsValidator
Filter\Validation\AbstractValidator
AbstractSource on GitHubThis is a base class for validators
Phalcon\Filter\Validation\AbstractValidator- implementsPhalcon\Filter\Validation\ValidatorInterfacePhalcon\Filter\Validation\AbstractCombinedFieldsValidatorPhalcon\Filter\Validation\AbstractValidatorCompositePhalcon\Filter\Validation\Validator\AlnumPhalcon\Filter\Validation\Validator\AlphaPhalcon\Filter\Validation\Validator\BetweenPhalcon\Filter\Validation\Validator\CallbackPhalcon\Filter\Validation\Validator\ConfirmationPhalcon\Filter\Validation\Validator\CreditCardPhalcon\Filter\Validation\Validator\DatePhalcon\Filter\Validation\Validator\DigitPhalcon\Filter\Validation\Validator\EmailPhalcon\Filter\Validation\Validator\ExclusionInPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\FilesPhalcon\Filter\Validation\Validator\IdenticalPhalcon\Filter\Validation\Validator\InclusionInPhalcon\Filter\Validation\Validator\IpPhalcon\Filter\Validation\Validator\NumericalityPhalcon\Filter\Validation\Validator\PresenceOfPhalcon\Filter\Validation\Validator\RegexPhalcon\Filter\Validation\Validator\StringLength\MaxPhalcon\Filter\Validation\Validator\StringLength\MinPhalcon\Filter\Validation\Validator\Url
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Exceptions\FieldNotPrintable · Phalcon\Messages\Message · Phalcon\Support\Helper\Arr\Whitelist
Method Summary
public__construct( array$options = [] )Phalcon\Filter\Validation\Validator constructorpublicmixedgetOption(string$key,mixed$defaultValue = null)Returns an option in the validator's optionspublicstringgetTemplate( string|null$field = null )Get the template messagepublicarraygetTemplates()Get templates collection objectpublicboolhasOption( string$key )Checks if an option is definedpublicboolisAllowEmpty(Validation$validation,string$field)Checks whether the field can be considered empty and thereforepublicMessagemessageFactory(Validation$validation,mixed$field,array$replacements = [])Create a default message by factorypublicvoidsetOption(string$key,mixed$value)Sets an option in the validatorpublicValidatorInterfacesetTemplate( string$template )Set a new template messagepublicValidatorInterfacesetTemplates( array$templates )Clear current templates and set new from an array,publicboolvalidate(Validation$validation,mixed$field)Executes the validationprotectedboolallowEmpty(mixed$field,mixed$value)Checks if field can be empty.protectedmixedcheckArray(mixed$value,string$field)Checks if a value is an array and returns the element based on theprotectedintprepareCode( string$field )Prepares a validation code.protectedmixedprepareLabel(Validation$validation,string$field)Prepares a label for the field.Properties
protectedarray$options = []protectedstring|null$template = nullMessage templateprotectedbool$templateChanged = falseWhether the template/message has been explicitly assigned on the instance (constructor message/template option or setTemplate()). While false, template still holds the validator's class default and a global default registered via Validation::setDefaultMessages() applies.protectedarray$templates = []Message templatesMethods
__construct()
public function __construct( array $options = [] );Phalcon\Filter\Validation\Validator constructor
getOption()
public function getOption(
string $key,
mixed $defaultValue = null
): mixed;Returns an option in the validator’s options Returns null if the option hasn’t set
getTemplate()
public function getTemplate( string|null $field = null ): string;Get the template message
getTemplates()
public function getTemplates(): array;Get templates collection object
hasOption()
public function hasOption( string $key ): bool;Checks if an option is defined
isAllowEmpty()
public function isAllowEmpty(
Validation $validation,
string $field
): bool;Checks whether the field can be considered empty and therefore
skipped, honoring the allowEmpty option (boolean flag, list of
empty values, or per-field map).
messageFactory()
public function messageFactory(
Validation $validation,
mixed $field,
array $replacements = []
): Message;Create a default message by factory
setOption()
public function setOption(
string $key,
mixed $value
): void;Sets an option in the validator
setTemplate()
public function setTemplate( string $template ): ValidatorInterface;Set a new template message
setTemplates()
public function setTemplates( array $templates ): ValidatorInterface;Clear current templates and set new from an array,
validate()
abstract public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
allowEmpty()
protected function allowEmpty(
mixed $field,
mixed $value
): bool;Checks if field can be empty.
checkArray()
protected function checkArray(
mixed $value,
string $field
): mixed;Checks if a value is an array and returns the element based on the passed field name
prepareCode()
protected function prepareCode( string $field ): int;Prepares a validation code.
prepareLabel()
protected function prepareLabel(
Validation $validation,
string $field
): mixed;Prepares a label for the field.
Filter\Validation\AbstractValidatorComposite
AbstractSource on GitHubThis is a base class for combined fields validators
@todo Remove in v7. Kept only for backwards compatibility; compose Phalcon\Filter\Validation\Traits\ValidatorCompositeTrait directly (with extends AbstractValidator implements ValidatorCompositeInterface) instead of extending this.
Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractValidatorComposite- implementsPhalcon\Filter\Validation\ValidatorCompositeInterface
Uses Phalcon\Filter\Validation\Traits\ValidatorCompositeTrait
Filter\Validation\Exception
ClassSource on GitHubExceptions thrown in Phalcon\Filter\Validation* classes will use this class
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\FieldNotPrintablePhalcon\Filter\Validation\Exceptions\FilterServiceUnavailablePhalcon\Filter\Validation\Exceptions\InvalidAllowedTypesPhalcon\Filter\Validation\Exceptions\InvalidCallbackReturnPhalcon\Filter\Validation\Exceptions\InvalidDomainOptionPhalcon\Filter\Validation\Exceptions\InvalidFieldTypePhalcon\Filter\Validation\Exceptions\InvalidFilterServicePhalcon\Filter\Validation\Exceptions\InvalidStrictOptionPhalcon\Filter\Validation\Exceptions\InvalidValidationDataPhalcon\Filter\Validation\Exceptions\InvalidValidatorPhalcon\Filter\Validation\Exceptions\InvalidValidatorScopePhalcon\Filter\Validation\Exceptions\MissingMbstringPhalcon\Filter\Validation\Exceptions\NoDataToValidatePhalcon\Filter\Validation\Exceptions\NoValidatorsPhalcon\Filter\Validation\Exceptions\NoValidatorsInCompositePhalcon\Filter\Validation\Exceptions\UniquenessConversionMustBeArrayPhalcon\Filter\Validation\Exceptions\UniquenessModelRequiredPhalcon\Filter\Validation\Exceptions\UniquenessOnlyForPhalconModelPhalcon\Filter\Validation\Exceptions\ValidationEntityNotObject
Filter\Validation\Exceptions\FieldNotPrintable
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\FieldNotPrintable
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\FilterServiceUnavailable
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\FilterServiceUnavailable
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidAllowedTypes
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidAllowedTypes
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidCallbackReturn
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidCallbackReturn
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidDomainOption
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidDomainOption
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidFieldType
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidFieldType
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidFilterService
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidFilterService
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidStrictOption
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidStrictOption
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidValidationData
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidValidationData
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidValidator
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidValidator
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\InvalidValidatorScope
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidValidatorScope
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\MissingMbstring
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\MissingMbstring
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\NoDataToValidate
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\NoDataToValidate
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\NoValidators
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\NoValidators
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\NoValidatorsInComposite
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\NoValidatorsInComposite
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct( string $className );Filter\Validation\Exceptions\UniquenessConversionMustBeArray
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\UniquenessConversionMustBeArray
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\UniquenessModelRequired
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\UniquenessModelRequired
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\UniquenessOnlyForPhalconModel
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\UniquenessOnlyForPhalconModel
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Exceptions\ValidationEntityNotObject
ClassSource on GitHub\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\ValidationEntityNotObject
Uses Phalcon\Filter\Validation\Exception
Method Summary
Methods
__construct()
public function __construct();Filter\Validation\Traits\ValidatorCompositeTrait
TraitSource on GitHubShared validator collection state and combined validation for composite validators.
Phalcon\Filter\Validation\Traits\ValidatorCompositeTrait
Used by Phalcon\Filter\Validation\AbstractValidatorComposite
Method Summary
publicarraygetValidators()publicboolvalidate(\Phalcon\Filter\Validation$validation,mixed$field)Executes the validationProperties
protectedarray$validators = null@todo Use a default [] once Zephir supports array trait defaultsMethods
getValidators()
public function getValidators(): array;validate()
public function validate(
\Phalcon\Filter\Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\ValidationInterface
InterfaceSource on GitHubInterface for the Phalcon\Filter\Validation component
Phalcon\Filter\Validation\ValidationInterface
Uses Phalcon\Di\Injectable · Phalcon\Messages\MessageInterface · Phalcon\Messages\Messages
Method Summary
publicValidationInterfaceadd(mixed$field,ValidatorInterface$validator)Adds a validator to a fieldpublicValidationInterfaceappendMessage( MessageInterface$message )Appends a message to the messages listpublicValidationInterfacebind(mixed$entity,mixed$data,array$whitelist = [])Assigns the data to an entitypublicmixedgetEntity()Returns the bound entitypublicmixed|nullgetFilters( string|null$field = null )Returns all the filters or a specific onepublicstringgetLabel( string$field )Get label for fieldpublicMessagesgetMessages()Returns the registered validatorspublicarraygetValidators()Returns the validators added to the validationpublicmixed|nullgetValue( string$field )Gets the a value to validate in the array/object data sourcepublicValidationInterfacerule(mixed$field,ValidatorInterface$validator)Alias of add methodpublicValidationInterfacerules(string$field,array$validators)Adds the validators to a fieldpublicValidationInterfacesetFilters(string$field,mixed$filters)Adds filters to the fieldpublicvoidsetLabels( array$labels )Adds labels for fieldspublicMessages|boolvalidate(mixed$data = null,mixed$entity = null,array$whitelist = [])Validate a set of data according to a set of rulesMethods
add()
public function add(
mixed $field,
ValidatorInterface $validator
): ValidationInterface;Adds a validator to a field
appendMessage()
public function appendMessage( MessageInterface $message ): ValidationInterface;Appends a message to the messages list
bind()
public function bind(
mixed $entity,
mixed $data,
array $whitelist = []
): ValidationInterface;Assigns the data to an entity The entity is used to obtain the validation values
getEntity()
public function getEntity(): mixed;Returns the bound entity
getFilters()
public function getFilters( string|null $field = null ): mixed|null;Returns all the filters or a specific one
getLabel()
public function getLabel( string $field ): string;Get label for field
getMessages()
public function getMessages(): Messages;Returns the registered validators
getValidators()
public function getValidators(): array;Returns the validators added to the validation
getValue()
public function getValue( string $field ): mixed|null;Gets the a value to validate in the array/object data source
rule()
public function rule(
mixed $field,
ValidatorInterface $validator
): ValidationInterface;Alias of add method
rules()
public function rules(
string $field,
array $validators
): ValidationInterface;Adds the validators to a field
setFilters()
public function setFilters(
string $field,
mixed $filters
): ValidationInterface;Adds filters to the field
setLabels()
public function setLabels( array $labels ): void;Adds labels for fields
validate()
public function validate(
mixed $data = null,
mixed $entity = null,
array $whitelist = []
): Messages|bool;Validate a set of data according to a set of rules
Filter\Validation\ValidatorCompositeInterface
InterfaceSource on GitHubThis is a base class for combined fields validators
Phalcon\Filter\Validation\ValidatorCompositeInterface
Uses Phalcon\Filter\Validation
Method Summary
publicarraygetValidators()Executes the validationpublicboolvalidate(Validation$validation,mixed$field)Executes the validationMethods
getValidators()
public function getValidators(): array;Executes the validation
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\ValidatorFactory
ClassSource on GitHubPhalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Filter\Validation\ValidatorFactory
Uses Phalcon\Factory\AbstractFactory · Phalcon\Filter\Validation\Validator\Alnum · Phalcon\Filter\Validation\Validator\Alpha · Phalcon\Filter\Validation\Validator\Between · Phalcon\Filter\Validation\Validator\Callback · Phalcon\Filter\Validation\Validator\Confirmation · Phalcon\Filter\Validation\Validator\CreditCard · Phalcon\Filter\Validation\Validator\Date · Phalcon\Filter\Validation\Validator\Digit · Phalcon\Filter\Validation\Validator\Email · Phalcon\Filter\Validation\Validator\Exception · Phalcon\Filter\Validation\Validator\ExclusionIn · Phalcon\Filter\Validation\Validator\File · Phalcon\Filter\Validation\Validator\Identical · Phalcon\Filter\Validation\Validator\InclusionIn · Phalcon\Filter\Validation\Validator\Ip · Phalcon\Filter\Validation\Validator\Numericality · Phalcon\Filter\Validation\Validator\PresenceOf · Phalcon\Filter\Validation\Validator\Regex · Phalcon\Filter\Validation\Validator\StringLength · Phalcon\Filter\Validation\Validator\Uniqueness · Phalcon\Filter\Validation\Validator\Url
Method Summary
public__construct( array$services = [] )TagFactory constructor.publicValidatorInterfacenewInstance( string$name )Creates a new instanceprotectedstringgetExceptionClass()protectedarraygetServices()Returns the available adaptersMethods
__construct()
public function __construct( array $services = [] );TagFactory constructor.
newInstance()
public function newInstance( string $name ): ValidatorInterface;Creates a new instance
getExceptionClass()
protected function getExceptionClass(): string;getServices()
protected function getServices(): array;Returns the available adapters
Filter\Validation\ValidatorInterface
InterfaceSource on GitHubInterface for Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\ValidatorInterface
Uses Phalcon\Filter\Validation
Method Summary
publicmixedgetOption(string$key,mixed$defaultValue = null)Returns an option in the validator's optionspublicstringgetTemplate( string$field )Get the template messagepublicarraygetTemplates()Get message templatespublicboolhasOption( string$key )Checks if an option is definedpublicValidatorInterfacesetTemplate( string$template )Set a new template messagepublicValidatorInterfacesetTemplates( array$templates )Clear current template and set new from an array,publicboolvalidate(Validation$validation,mixed$field)Executes the validationMethods
getOption()
public function getOption(
string $key,
mixed $defaultValue = null
): mixed;Returns an option in the validator’s options Returns null if the option hasn’t set
getTemplate()
public function getTemplate( string $field ): string;Get the template message
getTemplates()
public function getTemplates(): array;Get message templates
hasOption()
public function hasOption( string $key ): bool;Checks if an option is defined
setTemplate()
public function setTemplate( string $template ): ValidatorInterface;Set a new template message
setTemplates()
public function setTemplates( array $templates ): ValidatorInterface;Clear current template and set new from an array,
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Alnum
ClassSource on GitHubCheck for alphanumeric character(s)
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Alnum as AlnumValidator;
$validator = new Validation();
$validator->add(
"username",
new AlnumValidator(
[
"message" => ":field must contain only alphanumeric characters",
]
)
);
$validator->add(
[
"username",
"name",
],
new AlnumValidator(
[
"message" => [
"username" => "username must contain only alphanumeric characters",
"name" => "name must contain only alphanumeric characters",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Alnum
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must contain only letters and numbers"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Alpha
ClassSource on GitHubCheck for alphabetic character(s)
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Alpha as AlphaValidator;
$validator = new Validation();
$validator->add(
"username",
new AlphaValidator(
[
"message" => ":field must contain only letters",
]
)
);
$validator->add(
[
"username",
"name",
],
new AlphaValidator(
[
"message" => [
"username" => "username must contain only letters",
"name" => "name must contain only letters",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Alpha
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must contain only letters"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Between
ClassSource on GitHubValidates that a value is between an inclusive range of two values. For a value x, the test is passed if minimum<=x<=maximum.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Between;
$validator = new Validation();
$validator->add(
"price",
new Between(
[
"minimum" => 0,
"maximum" => 100,
"message" => "The price must be between 0 and 100",
]
)
);
$validator->add(
[
"price",
"amount",
],
new Between(
[
"minimum" => [
"price" => 0,
"amount" => 0,
],
"maximum" => [
"price" => 100,
"amount" => 50,
],
"message" => [
"price" => "The price must be between 0 and 100",
"amount" => "The amount must be between 0 and 50",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Between
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must be within the range of :min to :max"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Callback
ClassSource on GitHubCalls user function for validation
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Callback as CallbackValidator;
use Phalcon\Filter\Validation\Validator\Numericality as NumericalityValidator;
$validator = new Validation();
$validator->add(
["user", "admin"],
new CallbackValidator(
[
"message" => "There must be only an user or admin set",
"callback" => function($data) {
if (!empty($data->getUser()) && !empty($data->getAdmin())) {
return false;
}
return true;
}
]
)
);
$validator->add(
"amount",
new CallbackValidator(
[
"callback" => function($data) {
if (!empty($data->getProduct())) {
return new NumericalityValidator(
[
"message" => "Amount must be a number."
]
);
}
}
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Callback
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Filter\Validation\Exceptions\InvalidCallbackReturn · Phalcon\Filter\Validation\ValidatorInterface · Phalcon\Messages\Message · ReflectionFunction
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must match the callback function"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Confirmation
ClassSource on GitHubChecks that two values have the same value
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Confirmation;
$validator = new Validation();
$validator->add(
"password",
new Confirmation(
[
"message" => "Password does not match confirmation",
"with" => "confirmPassword",
]
)
);
$validator->add(
[
"password",
"email",
],
new Confirmation(
[
"message" => [
"password" => "Password does not match confirmation",
"email" => "Email does not match confirmation",
],
"with" => [
"password" => "confirmPassword",
"email" => "confirmEmail",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Confirmation
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Exceptions\MissingMbstring · Phalcon\Messages\Message · Phalcon\Traits\Php\InfoTrait
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationprotectedboolcompare(string$a,string$b)Compare stringsProperties
protectedstring$template = "Field :field must be the same as :with"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
compare()
final protected function compare(
string $a,
string $b
): bool;Compare strings
Filter\Validation\Validator\CreditCard
ClassSource on GitHubChecks if a value has a valid credit card number
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\CreditCard as CreditCardValidator;
$validator = new Validation();
$validator->add(
"creditCard",
new CreditCardValidator(
[
"message" => "The credit card number is not valid",
]
)
);
$validator->add(
[
"creditCard",
"secondCreditCard",
],
new CreditCardValidator(
[
"message" => [
"creditCard" => "The credit card number is not valid",
"secondCreditCard" => "The second credit card number is not valid",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\CreditCard
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field is not valid for a credit card number"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Date
ClassSource on GitHubChecks if a value is a valid date
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Date as DateValidator;
$validator = new Validation();
$validator->add(
"date",
new DateValidator(
[
"format" => "d-m-Y",
"message" => "The date is invalid",
]
)
);
$validator->add(
[
"date",
"anotherDate",
],
new DateValidator(
[
"format" => [
"date" => "d-m-Y",
"anotherDate" => "Y-m-d",
],
"message" => [
"date" => "The date is invalid",
"anotherDate" => "The another date is invalid",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Date
Uses DateTime · Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field is not a valid date"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Digit
ClassSource on GitHubCheck for numeric character(s)
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Digit as DigitValidator;
$validator = new Validation();
$validator->add(
"height",
new DigitValidator(
[
"message" => ":field must be numeric",
]
)
);
$validator->add(
[
"height",
"width",
],
new DigitValidator(
[
"message" => [
"height" => "height must be numeric",
"width" => "width must be numeric",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Digit
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must be numeric"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Email
ClassSource on GitHubChecks if a value has a correct e-mail format
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Email as EmailValidator;
$validator = new Validation();
$validator->add(
"email",
new EmailValidator(
[
"message" => "The e-mail is not valid",
]
)
);
$validator->add(
[
"email",
"anotherEmail",
],
new EmailValidator(
[
"message" => [
"email" => "The e-mail is not valid",
"anotherEmail" => "The another e-mail is not valid",
],
]
)
);
$validator->add(
"tä[email protected]",
new EmailValidator(
[
"message" => "The e-mail is not valid",
"allowUTF8" => true,
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Email
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must be an email address"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Exception
ClassSource on GitHubExceptions thrown in Phalcon\Filter\Validation\Validator* classes will use this class
\ExceptionPhalcon\Filter\Validation\Validator\Exception
Filter\Validation\Validator\ExclusionIn
ClassSource on GitHubCheck if a value is not included into a list of values
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\ExclusionIn;
$validator = new Validation();
$validator->add(
"status",
new ExclusionIn(
[
"message" => "The status must not be A or B",
"domain" => [
"A",
"B",
],
]
)
);
$validator->add(
[
"status",
"type",
],
new ExclusionIn(
[
"message" => [
"status" => "The status must not be A or B",
"type" => "The type must not be 1 or "
],
"domain" => [
"status" => [
"A",
"B",
],
"type" => [1, 2],
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\ExclusionIn
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Exceptions\InvalidDomainOption · Phalcon\Filter\Validation\Exceptions\InvalidStrictOption · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must not be a part of list: :domain"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\File
ClassSource on GitHubChecks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File as FileValidator;
$validator = new Validation();
$validator->add(
"file",
new FileValidator(
[
"maxSize" => "2M",
"messageSize" => ":field exceeds the max file size (:size)",
"allowedTypes" => [
"image/jpeg",
"image/png",
],
"messageType" => "Allowed file types are :types",
"maxResolution" => "800x600",
"messageMaxResolution" => "Max resolution of :field is :resolution",
"messageFileEmpty" => "File is empty",
"messageIniSize" => "Ini size is not valid",
"messageValid" => "File is not valid",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new FileValidator(
[
"maxSize" => [
"file" => "2M",
"anotherFile" => "4M",
],
"messageSize" => [
"file" => "file exceeds the max file size 2M",
"anotherFile" => "anotherFile exceeds the max file size 4M",
"allowedTypes" => [
"file" => [
"image/jpeg",
"image/png",
],
"anotherFile" => [
"image/gif",
"image/bmp",
],
],
"messageType" => [
"file" => "Allowed file types are image/jpeg and image/png",
"anotherFile" => "Allowed file types are image/gif and image/bmp",
],
"maxResolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"messageMaxResolution" => [
"file" => "Max resolution of file is 800x600",
"anotherFile" => "Max resolution of file is 1024x768",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractValidatorCompositePhalcon\Filter\Validation\Validator\File
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidatorComposite · Phalcon\Filter\Validation\Validator\File\MimeType · Phalcon\Filter\Validation\Validator\File\Resolution\AspectRatio · Phalcon\Filter\Validation\Validator\File\Resolution\Equal · Phalcon\Filter\Validation\Validator\File\Resolution\Max · Phalcon\Filter\Validation\Validator\File\Resolution\Min · Phalcon\Filter\Validation\Validator\File\Size\Equal · Phalcon\Filter\Validation\Validator\File\Size\Max · Phalcon\Filter\Validation\Validator\File\Size\Min · Phalcon\Messages\Message · Phalcon\Traits\Support\Helper\Arr\GetTrait
Method Summary
Methods
__construct()
public function __construct( array $options = [] );Constructor
Filter\Validation\Validator\File\AbstractFile
AbstractSource on GitHubChecks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Size(
[
"maxSize" => "2M",
"messageSize" => ":field exceeds the max file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new FileValidator(
[
"maxSize" => [
"file" => "2M",
"anotherFile" => "4M",
],
"messageSize" => [
"file" => "file exceeds the max file size 2M",
"anotherFile" => "anotherFile exceeds the max file size 4M",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\MimeTypePhalcon\Filter\Validation\Validator\File\Resolution\AspectRatioPhalcon\Filter\Validation\Validator\File\Resolution\EqualPhalcon\Filter\Validation\Validator\File\Resolution\MaxPhalcon\Filter\Validation\Validator\File\Resolution\MinPhalcon\Filter\Validation\Validator\File\Size\Equal
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
publicboolcheckUpload(Validation$validation,string$field)Check uploadpublicboolcheckUploadIsEmpty(Validation$validation,string$field)Check if upload is emptypublicboolcheckUploadIsValid(Validation$validation,string$field)Check if upload is validpublicboolcheckUploadMaxSize(Validation$validation,string$field)Check if uploaded file is larger than PHP allowed sizepublicfloatgetFileSizeInBytes( string$size )Convert a string like "2.5MB" in bytespublicstringgetMessageFileEmpty()Empty is emptypublicstringgetMessageIniSize()File exceeds the file size set in PHP configurationpublicstringgetMessageValid()File is not validpublicboolisAllowEmpty(Validation$validation,string$field)Check on emptypublicvoidsetMessageFileEmpty( string$message )Empty is emptypublicvoidsetMessageIniSize( string$message )File exceeds the file size set in PHP configurationpublicvoidsetMessageValid( string$message )File is not validprotectedboolcheckIsUploadedFile( string$name )Checks if a file has been uploaded; Internal check that can beProperties
protectedstring$messageFileEmpty = "Field :field must not be empty"Empty is emptyprotectedstring$messageIniSize = "File :field exceeds the maximum file size"File exceeds the file size set in PHP configurationprotectedstring$messageValid = "Field :field is not valid"File is not validMethods
checkUpload()
public function checkUpload(
Validation $validation,
string $field
): bool;Check upload
checkUploadIsEmpty()
public function checkUploadIsEmpty(
Validation $validation,
string $field
): bool;Check if upload is empty
checkUploadIsValid()
public function checkUploadIsValid(
Validation $validation,
string $field
): bool;Check if upload is valid
checkUploadMaxSize()
public function checkUploadMaxSize(
Validation $validation,
string $field
): bool;Check if uploaded file is larger than PHP allowed size
getFileSizeInBytes()
public function getFileSizeInBytes( string $size ): float;Convert a string like “2.5MB” in bytes
getMessageFileEmpty()
public function getMessageFileEmpty(): string;Empty is empty
getMessageIniSize()
public function getMessageIniSize(): string;File exceeds the file size set in PHP configuration
getMessageValid()
public function getMessageValid(): string;File is not valid
isAllowEmpty()
public function isAllowEmpty(
Validation $validation,
string $field
): bool;Check on empty
setMessageFileEmpty()
public function setMessageFileEmpty( string $message ): void;Empty is empty
setMessageIniSize()
public function setMessageIniSize( string $message ): void;File exceeds the file size set in PHP configuration
setMessageValid()
public function setMessageValid( string $message ): void;File is not valid
checkIsUploadedFile()
protected function checkIsUploadedFile( string $name ): bool;Checks if a file has been uploaded; Internal check that can be overridden in a subclass if you do not want to check uploaded files
Filter\Validation\Validator\File\MimeType
ClassSource on GitHubChecks if a value has a correct file mime type
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\MimeType;
$validator = new Validation();
$validator->add(
"file",
new MimeType(
[
"types" => [
"image/jpeg",
"image/png",
],
"message" => "Allowed file types are :types"
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new MimeType(
[
"types" => [
"file" => [
"image/jpeg",
"image/png",
],
"anotherFile" => [
"image/gif",
"image/bmp",
],
],
"message" => [
"file" => "Allowed file types are image/jpeg and image/png",
"anotherFile" => "Allowed file types are image/gif and image/bmp",
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\MimeType
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Exceptions\InvalidAllowedTypes · Phalcon\Messages\Message · Phalcon\Traits\Php\InfoTrait
Method Summary
Properties
protectedstring$template = "File :field must be of type: :types"Methods
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\File\Resolution\AspectRatio
ClassSource on GitHubChecks if a file has the exact aspect ratio
The ratio is compared with integer cross-multiplication, so the image dimensions must match the ratio exactly: 1920x1080 matches “16x9”, 1366x768 does not.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Resolution\AspectRatio;
$validator = new Validation();
$validator->add(
"file",
new AspectRatio(
[
"ratio" => "16x9",
"message" => "The aspect ratio of the field :field has to be :ratio",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new AspectRatio(
[
"ratio" => [
"file" => "16x9",
"anotherFile" => "4x3",
],
"message" => [
"file" => "Aspect ratio of file has to be 16x9",
"anotherFile" => "Aspect ratio of anotherFile has to be 4x3",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Resolution\AspectRatio
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Validator\File\AbstractFile
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "File :field does not have the exact aspect ratio of :ratio"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\File\Resolution\Equal
ClassSource on GitHubChecks if a file has the right resolution
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Resolution\Equal;
$validator = new Validation();
$validator->add(
"file",
new Equal(
[
"resolution" => "800x600",
"message" => "The resolution of the field :field has to be equal :resolution",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Equal(
[
"resolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"message" => [
"file" => "Equal resolution of file has to be 800x600",
"anotherFile" => "Equal resolution of file has to be 1024x768",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Resolution\Equal
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Validator\File\AbstractFile · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "The resolution of the field :field has to be equal :resolution"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\File\Resolution\Max
ClassSource on GitHubChecks if a file has the right resolution
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Resolution\Max;
$validator = new Validation();
$validator->add(
"file",
new Max(
[
"resolution" => "800x600",
"message" => "Max resolution of :field is :resolution",
"included" => true,
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Max(
[
"resolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "Max resolution of file is 800x600",
"anotherFile" => "Max resolution of file is 1024x768",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Resolution\Max
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Validator\File\AbstractFile · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "File :field exceeds the maximum resolution of :resolution"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\File\Resolution\Min
ClassSource on GitHubChecks if a file has the right resolution
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Resolution\Min;
$validator = new Validation();
$validator->add(
"file",
new Min(
[
"resolution" => "800x600",
"message" => "Min resolution of :field is :resolution",
"included" => true,
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Min(
[
"resolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "Min resolution of file is 800x600",
"anotherFile" => "Min resolution of file is 1024x768",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Resolution\Min
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Validator\File\AbstractFile · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "File :field can not have the minimum resolution of :resolution"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\File\Size\Equal
ClassSource on GitHubChecks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Equal(
[
"size" => "2M",
"included" => true,
"message" => ":field exceeds the equal file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Equal(
[
"size" => [
"file" => "2M",
"anotherFile" => "4M",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "file does not have the right file size",
"anotherFile" => "anotherFile wrong file size (4MB)",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Size\Equal
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Validator\File\AbstractFile
Method Summary
publicboolvalidate(Validation$validation,mixed$field)Executes the validationprotectedgetConditional(float$source,float$target,bool$included = false)Executes the conditionalProperties
protectedstring|null$template = "File :field does not have the exact :size file size"Methods
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
getConditional()
protected function getConditional(
float $source,
float $target,
bool $included = false
);Executes the conditional
Filter\Validation\Validator\File\Size\Max
ClassSource on GitHubChecks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Max(
[
"size" => "2M",
"included" => true,
"message" => ":field exceeds the max file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Max(
[
"size" => [
"file" => "2M",
"anotherFile" => "4M",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "file exceeds the max file size 2M",
"anotherFile" => "anotherFile exceeds the max file size 4M",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Size\EqualPhalcon\Filter\Validation\Validator\File\Size\Max
Method Summary
Properties
protectedstring|null$template = "File :field exceeds the size of :size"Methods
getConditional()
protected function getConditional(
float $source,
float $target,
bool $included = false
);Executes the conditional
Filter\Validation\Validator\File\Size\Min
ClassSource on GitHubChecks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Min(
[
"size" => "2M",
"included" => true,
"message" => ":field exceeds the min file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Min(
[
"size" => [
"file" => "2M",
"anotherFile" => "4M",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "file exceeds the min file size 2M",
"anotherFile" => "anotherFile exceeds the min file size 4M",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\File\AbstractFilePhalcon\Filter\Validation\Validator\File\Size\EqualPhalcon\Filter\Validation\Validator\File\Size\Min
Method Summary
Properties
protectedstring|null$template = "File :field can not have the minimum size of :size"Methods
getConditional()
protected function getConditional(
float $source,
float $target,
bool $included = false
);Executes the conditional
Filter\Validation\Validator\Files
ClassSource on GitHubValidates an array of uploaded files by delegating each file to the File
validator. Accepts the same options as Phalcon\Filter\Validation\Validator\File
and forwards them to each delegated file. A standard multiple-file upload
(<input name="files[]" type="file" multiple>) arrives as a transposed
$_FILES node; this validator normalizes it into individual files and fails
on the first file that violates a rule.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Files as FilesValidator;
$validation = new Validation();
$validation->add(
"photos",
new FilesValidator(
[
"maxSize" => "2M",
"messageSize" => ":field exceeds the max file size (:size)",
"allowedTypes" => ["image/jpeg", "image/png"],
"messageType" => "Allowed file types are :types",
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Files
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Messages · Phalcon\Messages\Messages
Method Summary
publicboolisAllowEmpty(Validation$validation,string$field)Whole-field empty check: true when the field carries no uploaded files.publicboolvalidate(Validation$validation,mixed$field)Executes the validation, delegating each file to a File validator.protectedarraynormalizeFiles( mixed$value )Normalizes a single file or a transposed multi-file $_FILES node into aMethods
isAllowEmpty()
public function isAllowEmpty(
Validation $validation,
string $field
): bool;Whole-field empty check: true when the field carries no uploaded files.
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation, delegating each file to a File validator.
normalizeFiles()
protected function normalizeFiles( mixed $value ): array;Normalizes a single file or a transposed multi-file $_FILES node into a
list of single-file structures.
Filter\Validation\Validator\Identical
ClassSource on GitHubChecks if a value is identical to other
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Identical;
$validator = new Validation();
$validator->add(
"terms",
new Identical(
[
"accepted" => "yes",
"message" => "Terms and conditions must be accepted",
]
)
);
$validator->add(
[
"terms",
"anotherTerms",
],
new Identical(
[
"accepted" => [
"terms" => "yes",
"anotherTerms" => "yes",
],
"message" => [
"terms" => "Terms and conditions must be accepted",
"anotherTerms" => "Another terms must be accepted",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Identical
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field does not have the expected value"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\InclusionIn
ClassSource on GitHubCheck if a value is included into a list of values
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\InclusionIn;
$validator = new Validation();
$validator->add(
"status",
new InclusionIn(
[
"message" => "The status must be A or B",
"domain" => ["A", "B"],
]
)
);
$validator->add(
[
"status",
"type",
],
new InclusionIn(
[
"message" => [
"status" => "The status must be A or B",
"type" => "The status must be 1 or 2",
],
"domain" => [
"status" => ["A", "B"],
"type" => [1, 2],
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\InclusionIn
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Exceptions\InvalidDomainOption · Phalcon\Filter\Validation\Exceptions\InvalidStrictOption · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must be a part of list: :domain"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Ip
ClassSource on GitHubCheck for IP addresses
use Phalcon\Filter\Validation\Validator\Ip as IpValidator;
$validator->add(
"ip_address",
new IpValidator(
[
"message" => ":field must contain only ip addresses",
"version" => IP::VERSION_4 | IP::VERSION_6, // v6 and v4. The same if not specified
"allowReserved" => false, // False if not specified. Ignored for v6
"allowPrivate" => false, // False if not specified
"allowEmpty" => false,
]
)
);
$validator->add(
[
"source_address",
"destination_address",
],
new IpValidator(
[
"message" => [
"source_address" => "source_address must be a valid IP address",
"destination_address" => "destination_address must be a valid IP address",
],
"version" => [
"source_address" => Ip::VERSION_4 | IP::VERSION_6,
"destination_address" => Ip::VERSION_4,
],
"allowReserved" => [
"source_address" => false,
"destination_address" => true,
],
"allowPrivate" => [
"source_address" => false,
"destination_address" => true,
],
"allowEmpty" => [
"source_address" => false,
"destination_address" => true,
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Ip
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationConstants
intVERSION_4 = FILTER_FLAG_IPV4intVERSION_6 = FILTER_FLAG_IPV6Properties
protectedstring$template = "Field :field must be a valid IP address"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Numericality
ClassSource on GitHubCheck for a valid numeric value
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Numericality;
$validator = new Validation();
$validator->add(
"price",
new Numericality(
[
"message" => ":field is not numeric",
]
)
);
$validator->add(
[
"price",
"amount",
],
new Numericality(
[
"message" => [
"price" => "price is not numeric",
"amount" => "amount is not numeric",
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Numericality
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field does not have a valid numeric format"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\PresenceOf
ClassSource on GitHubValidates that a value is not null or empty string
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\PresenceOf;
$validator = new Validation();
$validator->add(
"name",
new PresenceOf(
[
"message" => "The name is required",
]
)
);
$validator->add(
[
"name",
"email",
],
new PresenceOf(
[
"message" => [
"name" => "The name is required",
"email" => "The email is required",
],
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\PresenceOf
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field is required"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Regex
ClassSource on GitHubAllows validate if the value of a field matches a regular expression
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Regex as RegexValidator;
$validator = new Validation();
$validator->add(
"created_at",
new RegexValidator(
[
"pattern" => "/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])$/",
"message" => "The creation date is invalid",
]
)
);
$validator->add(
[
"created_at",
"name",
],
new RegexValidator(
[
"pattern" => [
"created_at" => "/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])$/",
"name" => "/^[a-z]$/",
],
"message" => [
"created_at" => "The creation date is invalid",
"name" => "The name is invalid",
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Regex
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field does not match the required format"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\StringLength
ClassSource on GitHubValidates that a string has the specified maximum and minimum constraints The test is passed if for a string’s length L, min<=L<=max, i.e. L must be at least min, and at most max. Since Phalcon v4.0 this validator works like a container
The “includedMinimum” and “includedMaximum” options are true by default. Set an option to false to exclude that boundary. The two options are independent of each other. The “included” option sets the two boundaries together and has precedence.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\StringLength as StringLength;
$validator = new Validation();
$validation->add(
"name_last",
new StringLength(
[
"max" => 50,
"min" => 2,
"messageMaximum" => "We don't like really long names",
"messageMinimum" => "We want more than just their initials",
"includedMaximum" => true,
"includedMinimum" => false,
]
)
);
$validation->add(
[
"name_last",
"name_first",
],
new StringLength(
[
"max" => [
"name_last" => 50,
"name_first" => 40,
],
"min" => [
"name_last" => 2,
"name_first" => 4,
],
"messageMaximum" => [
"name_last" => "We don't like really long last names",
"name_first" => "We don't like really long first names",
],
"messageMinimum" => [
"name_last" => "We don't like too short last names",
"name_first" => "We don't like too short first names",
],
"includedMaximum" => [
"name_last" => false,
"name_first" => true,
],
"includedMinimum" => [
"name_last" => false,
"name_first" => true,
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractValidatorCompositePhalcon\Filter\Validation\Validator\StringLength
Uses Phalcon\Filter\Validation\AbstractValidatorComposite · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Validator\StringLength\Max · Phalcon\Filter\Validation\Validator\StringLength\Min · Phalcon\Messages\Message
Method Summary
Methods
__construct()
public function __construct( array $options = [] );Constructor
Filter\Validation\Validator\StringLength\Max
ClassSource on GitHubValidates that a string has the specified maximum constraints The test is passed if for a string’s length L, L<=max, i.e. L must be at most max.
The “included” option is true by default. Set the option to false for L<max, i.e. L must be less than max. The “includedMaximum” option is an alias of “included”. If you set the two options, “included” has precedence.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\StringLength\Max;
$validator = new Validation();
$validation->add(
"name_last",
new Max(
[
"max" => 50,
"message" => "We don't like really long names",
"included" => true
]
)
);
$validation->add(
[
"name_last",
"name_first",
],
new Max(
[
"max" => [
"name_last" => 50,
"name_first" => 40,
],
"message" => [
"name_last" => "We don't like really long last names",
"name_first" => "We don't like really long first names",
],
"included" => [
"name_last" => false,
"name_first" => true,
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\StringLength\Max
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Filter\Validation\Exception · Phalcon\Messages\Message · Phalcon\Traits\Php\InfoTrait
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must not exceed :max characters long"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\StringLength\Min
ClassSource on GitHubValidates that a string has the specified minimum constraints The test is passed if for a string’s length L, min<=L, i.e. L must be at least min.
The “included” option is true by default. Set the option to false for min<L, i.e. L must be more than min. The “includedMinimum” option is an alias of “included”. If you set the two options, “included” has precedence.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\StringLength\Min;
$validator = new Validation();
$validation->add(
"name_last",
new Min(
[
"min" => 2,
"message" => "We want more than just their initials",
"included" => false
]
)
);
$validation->add(
[
"name_last",
"name_first",
],
new Min(
[
"min" => [
"name_last" => 2,
"name_first" => 4,
],
"message" => [
"name_last" => "We don't like too short last names",
"name_first" => "We don't like too short first names",
],
"included" => [
"name_last" => false,
"name_first" => true,
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\StringLength\Min
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Filter\Validation\Exception · Phalcon\Messages\Message · Phalcon\Traits\Php\InfoTrait
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must be at least :min characters long"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
Filter\Validation\Validator\Uniqueness
ClassSource on GitHubCheck that a field is unique in the related table
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Uniqueness as UniquenessValidator;
$validator = new Validation();
$validator->add(
"username",
new UniquenessValidator(
[
"model" => new Users(),
"message" => ":field must be unique",
]
)
);Different attribute from the field:
$validator->add(
"username",
new UniquenessValidator(
[
"model" => new Users(),
"attribute" => "nick",
]
)
);In model:
$validator->add(
"username",
new UniquenessValidator()
);Combination of fields in model:
$validator->add(
[
"firstName",
"lastName",
],
new UniquenessValidator()
);It is possible to convert values before validation. This is useful in situations where values need to be converted to do the database lookup:
$validator->add(
"username",
new UniquenessValidator(
[
"convert" => function (array $values) {
$values["username"] = strtolower($values["username"]);
return $values;
}
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractCombinedFieldsValidatorPhalcon\Filter\Validation\Validator\Uniqueness
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractCombinedFieldsValidator · Phalcon\Filter\Validation\Exception · Phalcon\Filter\Validation\Exceptions\UniquenessConversionMustBeArray · Phalcon\Filter\Validation\Exceptions\UniquenessModelRequired · Phalcon\Filter\Validation\Exceptions\UniquenessOnlyForPhalconModel · Phalcon\Messages\Message · Phalcon\Mvc\Model · Phalcon\Mvc\ModelInterface · Phalcon\Support\Settings
Method Summary
public__construct( array$options = [] )ConstructorpublicmixedgetOption(string$key,mixed$defaultValue = null)Returns an option in the validator's optionspublicboolvalidate(Validation$validation,mixed$field)Executes the validationprotectedstringgetColumnNameReal(mixed$record,string$field)The column map is used in the case to get real column nameprotectedboolisUniqueness(Validation$validation,mixed$field)protectedisUniquenessModel(mixed$record,array$field,array$values)Uniqueness method used for modelProperties
protectedstring$template = "Field :field must be unique"Methods
__construct()
public function __construct( array $options = [] );Constructor
getOption()
public function getOption(
string $key,
mixed $defaultValue = null
): mixed;Returns an option in the validator’s options Returns null if the option hasn’t set
The attribute option can be defined as an array when validating a
combination of fields; in that case resolve it to the mapped value.
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation
getColumnNameReal()
protected function getColumnNameReal(
mixed $record,
string $field
): string;The column map is used in the case to get real column name
isUniqueness()
protected function isUniqueness(
Validation $validation,
mixed $field
): bool;isUniquenessModel()
protected function isUniquenessModel(
mixed $record,
array $field,
array $values
);Uniqueness method used for model
Filter\Validation\Validator\Url
ClassSource on GitHubChecks if a value has a url format
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Url as UrlValidator;
$validator = new Validation();
$validator->add(
"url",
new UrlValidator(
[
"message" => ":field must be a url",
]
)
);
$validator->add(
[
"url",
"homepage",
],
new UrlValidator(
[
"message" => [
"url" => "url must be a url",
"homepage" => "homepage must be a url",
]
]
)
);Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\Validator\Url
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\AbstractValidator · Phalcon\Messages\Message
Method Summary
public__construct( array$options = [] )Constructorpublicboolvalidate(Validation$validation,mixed$field)Executes the validationProperties
protectedstring$template = "Field :field must be a url"Methods
__construct()
public function __construct( array $options = [] );Constructor
validate()
public function validate(
Validation $validation,
mixed $field
): bool;Executes the validation