Download the PHP package paliari/doctrine-validator without Composer
On this page you can find all versions of the php package paliari/doctrine-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paliari/doctrine-validator
More information about paliari/doctrine-validator
Files in paliari/doctrine-validator
Package doctrine-validator
Short Description Advanced model validator for Doctrine ORM (based on ActiveRecord)
License MIT
Homepage https://github.com/paliari/doctrine-validator
Informations about the package doctrine-validator
doctrine-validator
Installation
composer require paliari/doctrine-validator
Configuration
Include the TraitValidatorModel in your model
Or you can make your model class extends from AbstractValidatorModel:
Initialize validator
Add in your bootstrap:
Usage
Validators
Create a protected static
property inside your model to validate. See the available options and examples:
-
validates_presence_of
- Options:
if
,unless
,on
- Example:
- Options:
-
validates_size_of alias to validates_length_of
- Options:
minimum
,maximum
,in|within
- Example:
the
maximum
option is automatically setted by the field doc block - Options:
-
validates_inclusion_of
- Options:
in|within
,allow_nil
,allow_blank
- Example:
the
boolean
fields are automatically setted astrue|false
- Options:
-
validates_exclusion_of
- Options:
in|within
,allow_nil
,allow_blank
- Example:
- Options:
-
validates_format_of
- Options:
with
,without
- Values:
email
,url
,integer
,boolean
,ip
,/[0-9a-z]/
- Example:
- Options:
-
validates_numericality_of
- Options:
greater_than
,greater_than_or_equal_to
,less_than
,less_than_or_equal_to
,equal_to
,other_than
,only_integer
- Example:
- Options:
-
validates_uniqueness_of
- Options:
scope
- Example:
- Options:
- validates_custom
- Example:
There is also a list of default options supported by every validator: 'if', 'unless', 'on', 'allow_nil' or 'allow_blank'
Callbacks
Create a protected static
property with the callbacks inside your model. See the available options and examples:
-
before_validation Execute before validation
- Example:
-
after_validation Execute after validation
- Example:
-
before_validation_on_create Execute before validation only create
- Example:
-
after_validation_on_create Execute after validation only create
- Example:
-
before_validation_on_update Execute before validation only update
- Example:
-
after_validation_on_update Execute after validation only update
- Example:
-
before_validation_on_remove Execute before validation only remove
- Example:
- after_validation_on_remove
Execute after validation only remove
- Example:
Custom Validators
Para adicionar validator customizado é só uar o método statico no model ModelName::addCustomValidator passando como argumento um callable que recebe como parametro o $model.
To add custom validator just use the static method in model ModelName :: addCustomValidator passing as argument a callable that takes $model as parameter.
Example: