Coder Social home page Coder Social logo

zymfony-validator's Introduction

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 interfaece for Zend validators.

Installation

The recommended way to install Zymfony Validator is through composer.

{
    "require": {
        "umpirsky/zymfony-validator": "1.0.*"
    }
}

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.

zymfony-validator's People

Contributors

umpirsky avatar jorns avatar

Watchers

James Cloos avatar Ivan Yakovlev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.