Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Zend validator adapter for Symfony
PHP Perl
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
src/Zymfony/Component/Validator
tests/Zymfony/Component/Validator Added custom messages example.
.gitignore
.travis.yml
LICENSE
README.md
README.tpl
composer.json
composer.lock
phpunit.xml.dist

README.md

Zymfony Validator Build Status

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.'
                        )
                    )
                ))
            ));
    }
}

See more examples.

Annotations

<?php

use Zymfony\Component\Validator\Constraint;

class ZymfonyModel
{
    /**
     * @Constraint(validator = "creditcard")
     */
    protected $creditCard;
}

See more examples.

Yaml

ZymfonyModel:
    properties:
        creditcard:
            - Zymfony\Component\Validator\Constraint:
                validator: creditcard

Validators Available

Tests

To run the test suite, you need PHPUnit.

$ phpunit

License

Zymfony Validator is licensed under the MIT license.

Something went wrong with that request. Please try again.