Phalcon filter
NOTE
All classes are prefixed with Phalcon
Filter\Exception¶
Class Source on GitHub
Phalcon\Filter\Exception
Exceptions thrown in Phalcon\Filter will use this class
\ExceptionPhalcon\Filter\Exception
Filter\Exceptions\FilterNotRegistered¶
Class Source on GitHub
\ExceptionPhalcon\Filter\ExceptionPhalcon\Filter\Exceptions\FilterNotRegistered
Uses Phalcon\Filter\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Filter¶
Class Source on GitHub
Lazy 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
Method Summary¶
public __call(string $name,array $args) Magic call to make the helper objects available as methods. public __construct( array $mapper = [] ) Filter constructor. public mixed get( string $name ) Get a service. If it is not in the mapper array, create a new object, public array getDefaultMapper() Returns the default sanitizer name to class map. This is the single public bool has( string $name ) Checks if a service exists in the map array public mixed sanitize(mixed $value,mixed $sanitizers,bool $noRecursive = false) Sanitizes a value with a specified single or set of sanitizers public void set(string $name,mixed $service) Set a new service to the mapper array protected void init( array $mapper ) Loads the objects in the internal mapper array Constants¶
string FILTER_ABSINT = "absint" string FILTER_ALNUM = "alnum" string FILTER_ALPHA = "alpha" string FILTER_BOOL = "bool" string FILTER_EMAIL = "email" string FILTER_FLOAT = "float" string FILTER_INT = "int" string FILTER_IP = "ip" string FILTER_LOWER = "lower" string FILTER_LOWERFIRST = "lowerfirst" string FILTER_REGEX = "regex" string FILTER_REMOVE = "remove" string FILTER_REPLACE = "replace" string FILTER_SPECIAL = "special" string FILTER_SPECIALFULL = "specialfull" string FILTER_STRING = "string" string FILTER_STRING_LEGACY = "stringlegacy" string FILTER_STRIPTAGS = "striptags" string FILTER_TRIM = "trim" string FILTER_UPPER = "upper" string FILTER_UPPERFIRST = "upperfirst" string FILTER_UPPERWORDS = "upperwords" string FILTER_URL = "url" Properties¶
protected array $mapper = [] protected array $services = [] Methods¶
__call()¶
Magic call to make the helper objects available as methods.
__construct()¶
Filter constructor.
get()¶
Get a service. If it is not in the mapper array, create a new object, set it and then return it.
getDefaultMapper()¶
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()¶
Checks if a service exists in the map array
sanitize()¶
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()¶
Set a new service to the mapper array
init()¶
Loads the objects in the internal mapper array
Filter\FilterFactory¶
Class Source on GitHub
Class FilterFactory
@package Phalcon\Filter
Phalcon\Filter\FilterFactory
Uses Phalcon\Filter\Filter
Method Summary¶
public FilterInterface newInstance() Returns a Locator object with all the helpers defined in anonymous protected array getServices() Returns the available adapters Methods¶
newInstance()¶
Returns a Locator object with all the helpers defined in anonymous functions
getServices()¶
Returns the available adapters
Filter\FilterInterface¶
Interface Source on GitHub
Lazy loads, stores and exposes sanitizer objects
Phalcon\Filter\FilterInterface
Method Summary¶
Methods¶
sanitize()¶
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¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Alnum¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Alpha¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\BoolVal¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Email¶
Class Source on GitHub
Phalcon\Filter\Sanitize\Email
Sanitizes an email string
Phalcon\Filter\Sanitize\Email— implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary¶
Methods¶
__invoke()¶
Filter\Sanitize\FloatVal¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\IntVal¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Ip¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Lower¶
Class Source on GitHub
Phalcon\Filter\Sanitize\Lower
Sanitizes a value to lowercase
Phalcon\Filter\Sanitize\Lower— implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary¶
Methods¶
__invoke()¶
Filter\Sanitize\LowerFirst¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Regex¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Remove¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Replace¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Special¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\SpecialFull¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\StringVal¶
Class Source on GitHub
Sanitizes a value to string
Phalcon\Filter\Sanitize\StringVal— implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary¶
Methods¶
__invoke()¶
Filter\Sanitize\StringValLegacy¶
Class Source on GitHub
Sanitizes 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()¶
Filter\Sanitize\Striptags¶
Class Source on GitHub
Phalcon\Filter\Sanitize\Striptags
Sanitizes a value striptags
Phalcon\Filter\Sanitize\Striptags— implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary¶
Methods¶
__invoke()¶
Filter\Sanitize\Trim¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\Upper¶
Class Source on GitHub
Phalcon\Filter\Sanitize\Upper
Sanitizes a value to uppercase
Phalcon\Filter\Sanitize\Upper— implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary¶
Methods¶
__invoke()¶
Filter\Sanitize\UpperFirst¶
Class Source on GitHub
Phalcon\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()¶
Filter\Sanitize\UpperWords¶
Class Source on GitHub
Phalcon\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
Method Summary¶
Methods¶
__invoke()¶
Filter\Sanitize\Url¶
Class Source on GitHub
Phalcon\Filter\Sanitize\Url
Sanitizes a value url
Phalcon\Filter\Sanitize\Url— implementsPhalcon\Contracts\Filter\Sanitizer
Uses Phalcon\Contracts\Filter\Sanitizer
Method Summary¶
Methods¶
__invoke()¶
Filter\Validation¶
Class Source on GitHub
Allows 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 constructor public static add(mixed $field,ValidatorInterface $validator) Adds a validator to a field public static appendMessage( MessageInterface $message ) Appends a message to the messages list public static bind(mixed $entity,mixed $data,array $whitelist = []) Assigns the data to an entity public bool fails() Verify if validation fails by verifying if there are messages in the current validation public mixed getData() public mixed getEntity() Returns the bound entity public mixed|null getFilters( string $field = null ) Returns all the filters or a specific one public string getLabel( mixed $field ) Get label for field public Messages getMessages() Returns the registered validators public array getValidators() Returns the validators added to the validation public mixed|null getValue( string $field ) Gets the a value to validate in the array/object data source public mixed|null getValueByData(mixed $data,string $field) Gets the a value to validate in the array/object data source public mixed|null getValueByEntity(mixed $entity,string $field) Gets the a value to validate in the object entity source public static rule(mixed $field,ValidatorInterface $validator) Alias of add method public static rules(mixed $field,array $validators) Adds the validators to a field public void setEntity( mixed $entity ) Sets the bound entity public static setFilters(mixed $field,mixed $filters) Adds filters to the field public void setLabels( array $labels ) Adds labels for fields public static setValidators( array $validators ) public Messages|bool validate(mixed $data = null,mixed $entity = null,array $whitelist = []) Validate a set of data according to a set of rules protected bool preChecking(mixed $field,ValidatorInterface $validator) Internal validations, if it returns true, then skip the current validator Properties¶
protected array $combinedFieldsValidators = [] protected mixed $data protected object|null $entity = null protected array $filters = [] protected array $labels = [] protected Messages $messages protected array $validators = [] List of validators protected array $values = [] Calculated values protected array $whitelist = [] Methods¶
__construct()¶
Phalcon\Filter\Validation constructor
add()¶
Adds a validator to a field
appendMessage()¶
Appends a message to the messages list
bind()¶
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()¶
Verify if validation fails by verifying if there are messages in the current validation
getData()¶
getEntity()¶
Returns the bound entity
getFilters()¶
Returns all the filters or a specific one
getLabel()¶
Get label for field
getMessages()¶
Returns the registered validators
getValidators()¶
Returns the validators added to the validation
getValue()¶
Gets the a value to validate in the array/object data source
getValueByData()¶
Gets the a value to validate in the array/object data source
getValueByEntity()¶
Gets the a value to validate in the object entity source
rule()¶
Alias of add method
rules()¶
Adds the validators to a field
setEntity()¶
Sets the bound entity
setFilters()¶
Adds filters to the field
setLabels()¶
Adds labels for fields
setValidators()¶
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()¶
Internal validations, if it returns true, then skip the current validator
Filter\Validation\AbstractCombinedFieldsValidator¶
Abstract Source on GitHub
This is a base class for combined fields validators
Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractCombinedFieldsValidator
Filter\Validation\AbstractValidator¶
Abstract Source on GitHub
This 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\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 constructor public mixed getOption(string $key,mixed $defaultValue = null) Returns an option in the validator's options public string getTemplate( string $field = null ) Get the template message public array getTemplates() Get templates collection object public bool hasOption( string $key ) Checks if an option is defined public bool isAllowEmpty(Validation $validation,string $field) Checks whether the field can be considered empty and therefore public Message messageFactory(Validation $validation,mixed $field,array $replacements = []) Create a default message by factory public void setOption(string $key,mixed $value) Sets an option in the validator public ValidatorInterface setTemplate( string $template ) Set a new template message public ValidatorInterface setTemplates( array $templates ) Clear current templates and set new from an array, public bool validate(Validation $validation,mixed $field) Executes the validation protected bool allowEmpty(mixed $field,mixed $value) Checks if field can be empty. protected mixed checkArray(mixed $value,string $field) Checks if a value is an array and returns the element based on the protected int prepareCode( string $field ) Prepares a validation code. protected mixed prepareLabel(Validation $validation,string $field) Prepares a label for the field. Properties¶
protected array $options = [] protected string|null $template = null Message template protected array $templates = [] Message templates Methods¶
__construct()¶
Phalcon\Filter\Validation\Validator constructor
getOption()¶
Returns an option in the validator's options Returns null if the option hasn't set
getTemplate()¶
Get the template message
getTemplates()¶
Get templates collection object
hasOption()¶
Checks if an option is defined
isAllowEmpty()¶
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()¶
Sets an option in the validator
setTemplate()¶
Set a new template message
setTemplates()¶
Clear current templates and set new from an array,
validate()¶
Executes the validation
allowEmpty()¶
Checks if field can be empty.
checkArray()¶
Checks if a value is an array and returns the element based on the passed field name
prepareCode()¶
Prepares a validation code.
prepareLabel()¶
Prepares a label for the field.
Filter\Validation\AbstractValidatorComposite¶
Abstract Source on GitHub
This is a base class for combined fields validators
Phalcon\Filter\Validation\AbstractValidatorPhalcon\Filter\Validation\AbstractValidatorComposite— implementsPhalcon\Filter\Validation\ValidatorCompositeInterface
Uses Phalcon\Filter\Validation · Phalcon\Filter\Validation\Exceptions\NoValidatorsInComposite
Method Summary¶
public array getValidators() public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected array $validators = [] Methods¶
getValidators()¶
validate()¶
Executes the validation
Filter\Validation\Exception¶
Class Source on GitHub
Exceptions 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¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\FieldNotPrintable
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\FilterServiceUnavailable¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\FilterServiceUnavailable
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidAllowedTypes¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidAllowedTypes
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidCallbackReturn¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidCallbackReturn
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidDomainOption¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidDomainOption
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidFieldType¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidFieldType
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidFilterService¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidFilterService
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidStrictOption¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidStrictOption
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidValidationData¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidValidationData
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidValidator¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidValidator
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\InvalidValidatorScope¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\InvalidValidatorScope
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\MissingMbstring¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\MissingMbstring
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\NoDataToValidate¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\NoDataToValidate
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\NoValidators¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\NoValidators
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\NoValidatorsInComposite¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\NoValidatorsInComposite
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\UniquenessConversionMustBeArray¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\UniquenessConversionMustBeArray
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\UniquenessModelRequired¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\UniquenessModelRequired
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\UniquenessOnlyForPhalconModel¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\UniquenessOnlyForPhalconModel
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\Exceptions\ValidationEntityNotObject¶
Class Source on GitHub
\ExceptionPhalcon\Filter\Validation\ExceptionPhalcon\Filter\Validation\Exceptions\ValidationEntityNotObject
Uses Phalcon\Filter\Validation\Exception
Method Summary¶
Methods¶
__construct()¶
Filter\Validation\ValidationInterface¶
Interface Source on GitHub
Interface for the Phalcon\Filter\Validation component
Phalcon\Filter\Validation\ValidationInterface
Uses Phalcon\Di\Injectable · Phalcon\Messages\MessageInterface · Phalcon\Messages\Messages
Method Summary¶
public ValidationInterface add(mixed $field,ValidatorInterface $validator) Adds a validator to a field public ValidationInterface appendMessage( MessageInterface $message ) Appends a message to the messages list public ValidationInterface bind(mixed $entity,mixed $data,array $whitelist = []) Assigns the data to an entity public mixed getEntity() Returns the bound entity public mixed|null getFilters( string $field = null ) Returns all the filters or a specific one public string getLabel( string $field ) Get label for field public Messages getMessages() Returns the registered validators public array getValidators() Returns the validators added to the validation public mixed|null getValue( string $field ) Gets the a value to validate in the array/object data source public ValidationInterface rule(mixed $field,ValidatorInterface $validator) Alias of add method public ValidationInterface rules(string $field,array $validators) Adds the validators to a field public ValidationInterface setFilters(string $field,mixed $filters) Adds filters to the field public void setLabels( array $labels ) Adds labels for fields public Messages|bool validate(mixed $data = null,mixed $entity = null,array $whitelist = []) Validate a set of data according to a set of rules Methods¶
add()¶
Adds a validator to a field
appendMessage()¶
Appends a message to the messages list
bind()¶
Assigns the data to an entity The entity is used to obtain the validation values
getEntity()¶
Returns the bound entity
getFilters()¶
Returns all the filters or a specific one
getLabel()¶
Get label for field
getMessages()¶
Returns the registered validators
getValidators()¶
Returns the validators added to the validation
getValue()¶
Gets the a value to validate in the array/object data source
rule()¶
Alias of add method
rules()¶
Adds the validators to a field
setFilters()¶
Adds filters to the field
setLabels()¶
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¶
Interface Source on GitHub
This is a base class for combined fields validators
Phalcon\Filter\Validation\ValidatorCompositeInterface
Uses Phalcon\Filter\Validation
Method Summary¶
public array getValidators() Executes the validation public bool validate(Validation $validation,mixed $field) Executes the validation Methods¶
getValidators()¶
Executes the validation
validate()¶
Executes the validation
Filter\Validation\ValidatorFactory¶
Class Source on GitHub
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Filter\Validation\ValidatorFactory
Uses Phalcon\Factory\AbstractFactory
Method Summary¶
public __construct( array $services = [] ) TagFactory constructor. public ValidatorInterface newInstance( string $name ) Creates a new instance protected string getExceptionClass() protected array getServices() Returns the available adapters Methods¶
__construct()¶
TagFactory constructor.
newInstance()¶
Creates a new instance
getExceptionClass()¶
getServices()¶
Returns the available adapters
Filter\Validation\ValidatorInterface¶
Interface Source on GitHub
Interface for Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\ValidatorInterface
Uses Phalcon\Filter\Validation
Method Summary¶
public mixed getOption(string $key,mixed $defaultValue = null) Returns an option in the validator's options public string getTemplate( string $field ) Get the template message public array getTemplates() Get message templates public bool hasOption( string $key ) Checks if an option is defined public ValidatorInterface setTemplate( string $template ) Set a new template message public ValidatorInterface setTemplates( array $templates ) Clear current template and set new from an array, public bool validate(Validation $validation,mixed $field) Executes the validation Methods¶
getOption()¶
Returns an option in the validator's options Returns null if the option hasn't set
getTemplate()¶
Get the template message
getTemplates()¶
Get message templates
hasOption()¶
Checks if an option is defined
setTemplate()¶
Set a new template message
setTemplates()¶
Clear current template and set new from an array,
validate()¶
Executes the validation
Filter\Validation\Validator\Alnum¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must contain only letters and numbers" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Alpha¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must contain only letters" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Between¶
Class Source on GitHub
Validates 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must be within the range of :min to :max" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Callback¶
Class Source on GitHub
Calls 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
Method Summary¶
public __construct( array $options = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must match the callback function" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Confirmation¶
Class Source on GitHub
Checks 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
Method Summary¶
public __construct( array $options = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation protected bool compare(string $a,string $b) Compare strings Properties¶
protected string $template = "Field :field must be the same as :with" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
compare()¶
Compare strings
Filter\Validation\Validator\CreditCard¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field is not valid for a credit card number" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Date¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field is not a valid date" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Digit¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must be numeric" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Email¶
Class Source on GitHub
Checks 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äst@example.com",
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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must be an email address" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Exception¶
Class Source on GitHub
Exceptions thrown in Phalcon\Filter\Validation\Validator* classes will use this class
\ExceptionPhalcon\Filter\Validation\Validator\Exception
Filter\Validation\Validator\ExclusionIn¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must not be a part of list: :domain" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\File¶
Class Source on GitHub
Checks 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\Support\Helper\Arr\Get
Method Summary¶
Methods¶
__construct()¶
Constructor
Filter\Validation\Validator\File\AbstractFile¶
Abstract Source on GitHub
Checks 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¶
public bool checkUpload(Validation $validation,string $field) Check upload public bool checkUploadIsEmpty(Validation $validation,string $field) Check if upload is empty public bool checkUploadIsValid(Validation $validation,string $field) Check if upload is valid public bool checkUploadMaxSize(Validation $validation,string $field) Check if uploaded file is larger than PHP allowed size public double getFileSizeInBytes( string $size ) Convert a string like "2.5MB" in bytes public string getMessageFileEmpty() Empty is empty public string getMessageIniSize() File exceeds the file size set in PHP configuration public string getMessageValid() File is not valid public bool isAllowEmpty(Validation $validation,string $field) Check on empty public void setMessageFileEmpty( string $message ) Empty is empty public void setMessageIniSize( string $message ) File exceeds the file size set in PHP configuration public void setMessageValid( string $message ) File is not valid protected bool checkIsUploadedFile( string $name ) Checks if a file has been uploaded; Internal check that can be Properties¶
protected string $messageFileEmpty = "Field :field must not be empty" Empty is empty protected string $messageIniSize = "File :field exceeds the maximum file size" File exceeds the file size set in PHP configuration protected string $messageValid = "Field :field is not valid" File is not valid Methods¶
checkUpload()¶
Check upload
checkUploadIsEmpty()¶
Check if upload is empty
checkUploadIsValid()¶
Check if upload is valid
checkUploadMaxSize()¶
Check if uploaded file is larger than PHP allowed size
getFileSizeInBytes()¶
Convert a string like "2.5MB" in bytes
getMessageFileEmpty()¶
Empty is empty
getMessageIniSize()¶
File exceeds the file size set in PHP configuration
getMessageValid()¶
File is not valid
isAllowEmpty()¶
Check on empty
setMessageFileEmpty()¶
Empty is empty
setMessageIniSize()¶
File exceeds the file size set in PHP configuration
setMessageValid()¶
File is not valid
checkIsUploadedFile()¶
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¶
Class Source on GitHub
Checks 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
Method Summary¶
Properties¶
protected string $template = "File :field must be of type: :types" Methods¶
validate()¶
Executes the validation
Filter\Validation\Validator\File\Resolution\AspectRatio¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "File :field does not have the exact aspect ratio of :ratio" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\File\Resolution\Equal¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "The resolution of the field :field has to be equal :resolution" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\File\Resolution\Max¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "File :field exceeds the maximum resolution of :resolution" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\File\Resolution\Min¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "File :field can not have the minimum resolution of :resolution" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\File\Size\Equal¶
Class Source on GitHub
Checks 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¶
public bool validate(Validation $validation,mixed $field) Executes the validation protected getConditional(double $source,double $target,bool $included = false) Executes the conditional Properties¶
protected string|null $template = "File :field does not have the exact :size file size" Methods¶
validate()¶
Executes the validation
getConditional()¶
Executes the conditional
Filter\Validation\Validator\File\Size\Max¶
Class Source on GitHub
Checks 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¶
protected string|null $template = "File :field exceeds the size of :size" Methods¶
getConditional()¶
Executes the conditional
Filter\Validation\Validator\File\Size\Min¶
Class Source on GitHub
Checks 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¶
protected string|null $template = "File :field can not have the minimum size of :size" Methods¶
getConditional()¶
Executes the conditional
Filter\Validation\Validator\Identical¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field does not have the expected value" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\InclusionIn¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must be a part of list: :domain" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Ip¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Constants¶
int VERSION_4 = FILTER_FLAG_IPV4 int VERSION_6 = FILTER_FLAG_IPV6 Properties¶
protected string $template = "Field :field must be a valid IP address" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Numericality¶
Class Source on GitHub
Check 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field does not have a valid numeric format" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\PresenceOf¶
Class Source on GitHub
Validates 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field is required" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Regex¶
Class Source on GitHub
Allows 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field does not match the required format" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\StringLength¶
Class Source on GitHub
Validates 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
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\AbstractValidator · 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()¶
Constructor
Filter\Validation\Validator\StringLength\Max¶
Class Source on GitHub
Validates 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.
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
Method Summary¶
public __construct( array $options = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must not exceed :max characters long" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\StringLength\Min¶
Class Source on GitHub
Validates 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.
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" => true
]
)
);
$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
Method Summary¶
public __construct( array $options = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must be at least :min characters long" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation
Filter\Validation\Validator\Uniqueness¶
Class Source on GitHub
Check 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:
Combination of fields in model:
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 = [] ) Constructor public mixed getOption(string $key,mixed $defaultValue = null) Returns an option in the validator's options public bool validate(Validation $validation,mixed $field) Executes the validation protected string getColumnNameReal(mixed $record,string $field) The column map is used in the case to get real column name protected bool isUniqueness(Validation $validation,mixed $field) protected isUniquenessModel(mixed $record,array $field,array $values) Uniqueness method used for model Properties¶
protected string $template = "Field :field must be unique" Methods¶
__construct()¶
Constructor
getOption()¶
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()¶
Executes the validation
getColumnNameReal()¶
The column map is used in the case to get real column name
isUniqueness()¶
isUniquenessModel()¶
Uniqueness method used for model
Filter\Validation\Validator\Url¶
Class Source on GitHub
Checks 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 = [] ) Constructor public bool validate(Validation $validation,mixed $field) Executes the validation Properties¶
protected string $template = "Field :field must be a url" Methods¶
__construct()¶
Constructor
validate()¶
Executes the validation