PHP code example of umpirsky / zymfony-validator

1. Go to this page and download the library: Download umpirsky/zymfony-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

umpirsky / zymfony-validator example snippets




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



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



use Zymfony\Component\Validator\Constraint;

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