forked from umpirsky/zymfony-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.tpl
118 lines (91 loc) · 2.86 KB
/
README.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Zymfony Validator [](http://travis-ci.org/umpirsky/zymfony-validator)
=================
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](http://getcomposer.org).
```json
{
"require": {
"umpirsky/zymfony-validator": "1.0.*"
}
}
```
## Examples
### Basic Usage
```php
<?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
<?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.](https://github.com/umpirsky/Silex-Kitchen-Edition/blob/zymfony-validator/src/controllers.php#L68)
### Annotations
```php
<?php
use Zymfony\Component\Validator\Constraint;
class ZymfonyModel
{
/**
* @Constraint(validator = "creditcard")
*/
protected $creditCard;
}
```
[See more examples.](https://github.com/umpirsky/symfony-standard/blob/zymfony-validator/src/Acme/DemoBundle/Model/Contact.php)
### Yaml
```yaml
ZymfonyModel:
properties:
creditcard:
- Zymfony\Component\Validator\Constraint:
validator: creditcard
```
## Validators Available
%ValidatorsAvailable%
## Tests
To run the test suite, you need [PHPUnit](https://github.com/sebastianbergmann/phpunit).
$ phpunit
## License
Zymfony Validator is licensed under the MIT license.