umpirsky / zymfony-validator
Zend validator adapter for Symfony.
2.2.0
2013-04-28 20:17 UTC
Requires
- php: >=5.3.3
- symfony/validator: 2.2.*
- zendframework/zend-validator: 2.1.*
This package is not auto-updated.
Last update: 2024-10-26 14:03:22 UTC
README
Zend validator adapter for Symfony.
Zend Framework comes with a nice set of validation classes. Symfony provides nice validator component as well, but lacks some validators Zend already have like credit card, post code, hostname, iban...
Zymfony Validator is a bridge between this two validators, and provides Symfonic interface for Zend validators.
Installation
The recommended way to install Zymfony Validator is through composer.
{ "require": { "umpirsky/zymfony-validator": "2.2.*" } }
Examples
Basic Usage
<?php use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Zymfony\Component\Validator\Constraint; class ZymfonyType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('credit_card_number', 'text', array( 'constraints' => new Constraint(array( 'validator' => 'creditcard', )) )); } }
Custom Options and Messages
<?php use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Zend\Validator\StringLength; use Zymfony\Component\Validator\Constraint; class ZymfonyType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('my_cool_string', 'text', array( 'constraints' => new Constraint(array( 'validator' => 'stringlength', 'options' => array( 'min' => 2, 'max' => 8, 'messages' => array( StringLength::TOO_LONG => 'My cool string is more than %max% characters long.' ) ) )) )); } }
Annotations
<?php use Zymfony\Component\Validator\Constraint; class ZymfonyModel { /** * @Constraint(validator = "creditcard") */ protected $creditCard; }
Yaml
ZymfonyModel: properties: creditcard: - Zymfony\Component\Validator\Constraint: validator: creditcard
Validators Available
- alnum
- alpha
- barcodecode25interleaved
- barcodecode25
- barcodecode39ext
- barcodecode39
- barcodecode93ext
- barcodecode93
- barcodeean12
- barcodeean13
- barcodeean14
- barcodeean18
- barcodeean2
- barcodeean5
- barcodeean8
- barcodegtin12
- barcodegtin13
- barcodegtin14
- barcodeidentcode
- barcodeintelligentmail
- barcodeissn
- barcodeitf14
- barcodeleitcode
- barcodeplanet
- barcodepostnet
- barcoderoyalmail
- barcodesscc
- barcodeupca
- barcodeupce
- barcode
- between
- callback
- creditcard
- csrf
- date
- datestep
- dbnorecordexists
- dbrecordexists
- digits
- emailaddress
- explode
- filecount
- filecrc32
- fileexcludeextension
- fileexcludemimetype
- fileexists
- fileextension
- filefilessize
- filehash
- fileimagesize
- fileiscompressed
- fileisimage
- filemd5
- filemimetype
- filenotexists
- filesha1
- filesize
- fileupload
- filewordcount
- float
- greaterthan
- hex
- hostname
- iban
- identical
- inarray
- int
- ip
- isbn
- lessthan
- notempty
- postcode
- regex
- sitemapchangefreq
- sitemaplastmod
- sitemaploc
- sitemappriority
- stringlength
- step
- uri
Tests
To run the test suite, you need PHPUnit.
$ phpunit
License
Zymfony Validator is licensed under the MIT license.