Skip to content

Commit 4894b25

Browse files
WouterJ comments
1 parent efd5b77 commit 4894b25

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. index::
2-
single: Validator; Built In validators
2+
single: Validator; Built In Validators
33

4-
Built In validators
4+
Built In Validators
55
===================
66

77
For each validation rule, the component ships a Constraint class and its associated Validator class.
8-
The Constraint object describes the rule to check and the Validator implementation runs the validation logic.
8+
The Constraint object describes the rule to check and the Validator implementation runs the validation logic.
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.. index::
2-
single: Validator; Custom validation
2+
single: Validator; Custom Validation
33

4-
Custom validation
5-
=================
4+
Custom Validation
5+
=================

components/validator/introduction.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ The Validator Component
1010
* ``Contraints``: a constraint describes a rule that need to be validated
1111
* ``Validators``: a list of classes that implement the validation logic for common usages
1212

13-
14-
1513
Installation
1614
------------
1715

@@ -20,7 +18,7 @@ You can install the component in 2 different ways:
2018
* :doc:`Install it via Composer </components/using_components>` (``symfony/validator`` on `Packagist`_);
2119
* Use the official Git repository (https://github.com/symfony/Validator).
2220

23-
Then, require the vendor/autoload.php file to enable the autoloading mechanism provided by Composer. Otherwise, your application won't be able to find the classes of this Symfony component.
21+
.. include:: /components/require_autoload.rst.inc
2422

2523
Usage
2624
-----
@@ -51,7 +49,7 @@ point of the Validator component. To create a new instance of this class, it
5149
is recommended to use the :class:`Symfony\\Component\\Validator\\Validation`
5250
class.
5351

54-
You can get a very basic ``Validator`` by calling
52+
You can get a very basic ``Validator`` by calling
5553
:method:`Validation::createValidator() <Symfony\\Component\\Validator\\Validation::createValidator>`::
5654

5755
use Symfony\Component\Validator\Validation;
@@ -71,7 +69,7 @@ method::
7169
// ... build a custom instance of the Validator
7270
->getValidator();
7371

74-
What things you can configure will be documented in the following sections.
72+
In the next sections, you'll learn about all things you can configure in the Validator.
7573

7674
Sections
7775
--------
@@ -83,4 +81,4 @@ Sections
8381
* :doc:`/components/validator/custom_validation`
8482

8583
.. _`JSR-303 Bean Validation specification`: http://jcp.org/en/jsr/detail?id=303
86-
.. _Packagist: https://packagist.org/packages/symfony/validator
84+
.. _Packagist: https://packagist.org/packages/symfony/validator

components/validator/resources.rst

+20-14
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,16 @@ Now, the retrieved ``Validator`` tries to find the ``loadValidatorMetadata()``
3737
method of the class to validate to load its metadata::
3838

3939
use Symfony\Component\Validator\Mapping\ClassMetadata;
40-
use Symfony\Component\Validator\Constraints\NotBlank;
41-
use Symfony\Component\Validator\Constraints\Length;
40+
use Symfony\Component\Validator\Constraints as Assert;
4241

4342
class User
4443
{
4544
protected $name;
4645

4746
public static function loadValidatorMatadata(ClassMetadata $metadata)
4847
{
49-
$metadata->addPropertyConstraint('name', new NotBlank());
50-
$metadata->addPropertyConstraint('name', new Length(array(
48+
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
49+
$metadata->addPropertyConstraint('name', new Asert\Length(array(
5150
'min' => 5,
5251
'max' => 20,
5352
)));
@@ -65,7 +64,7 @@ The FileLoaders
6564
---------------
6665

6766
The component also provides 2 file loaders, one to load Yaml files and one to
68-
load XML files. Use
67+
load XML files. Use
6968
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::addYamlMapping` or
7069
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::addXmlMapping` to
7170
configure the locations of these files::
@@ -76,9 +75,14 @@ configure the locations of these files::
7675
->addYamlMapping('config/validation.yml')
7776
->getValidator();
7877

78+
.. note::
79+
80+
If you want to load YAML mapping files then you will also need to install
81+
:doc:`the Yaml component </components/yaml/introduction>`.
82+
7983
.. tip::
8084

81-
Just like with the method mappings, you can also use
85+
Just like with the method mappings, you can also use
8286
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::addYamlMappings` and
8387
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::addXmlMappings`
8488
to configure an array of file paths.
@@ -89,17 +93,17 @@ The AnnotationLoader
8993
At last, the component provides an
9094
:class:`Symfony\\Component\\Validator\\Mapping\\Loader\\AnnotationLoader`.
9195
This loader uses an annotation reader to parse the annotations of a class.
92-
Annotations are placed in doc block comments (`/** ... */`) and start with an
96+
Annotations are placed in doc block comments (``/** ... */``) and start with an
9397
``@``. For instance::
94-
98+
use Symfony\Component\Validator\Constraints as Assert;
9599
// ...
96100

97101
/**
98102
* @Assert\NotBlank()
99103
*/
100104
protected $name;
101105

102-
To enable the annotation loader, call the
106+
To enable the annotation loader, call the
103107
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::enableAnnotationMapping`
104108
method. It takes an optional annotation reader instance, which defaults to
105109
``Doctrine\Common\Annotations\AnnotationReader``::
@@ -116,12 +120,12 @@ To disable the annotation loader after it was enabled, call
116120
.. note::
117121

118122
In order to use the annotation loader, you should have installed the
119-
``doctrine/annotations`` and ``doctrine/cache`` packages from Packagist.
123+
``doctrine/annotations`` and ``doctrine/cache`` packages from _Packagist.
120124

121125
Using Multiple Loaders
122126
----------------------
123127

124-
The component provides a
128+
The component provides a
125129
:class:`Symfony\\Component\\Validator\\Mapping\\Loader\\LoaderChain` class to
126130
chain multiple loaders. This means you can configure as many loaders as you
127131
want at the same time.
@@ -144,10 +148,10 @@ Using many loaders to load metadata from different places is very easy when
144148
creating the metadata, but it can easily slow down your application since each
145149
file needs to be parsed, validated and converted to a
146150
:class:`Symfony\\Component\\Validator\\Mapping\\ClassMetadata` instance. To
147-
solve this problems, you can configure a cacher which will be used to cache
151+
solve this problem, you can configure a cacher which will be used to cache
148152
the ``ClassMetadata`` after it was loaded.
149153

150-
The Validator component comes with a
154+
The Validator component comes with an
151155
:class:`Symfony\\Component\\Validator\\Mapping\\Cache\\ApcCache`
152156
implementation. You can easily create other cachers by creating a class which
153157
implements :class:`Symfony\\Component\\Validator\\Mapping\\Cache\\CacheInterface`.
@@ -183,7 +187,7 @@ configured resources.
183187
You can also use a custom metadata factory implementation by creating a class
184188
which implements
185189
:class:`Symfony\\Component\\Validator\\MetadataFactoryInterface`. You can set
186-
this custom implementation using
190+
this custom implementation using
187191
:method:`Symfony\\Component\\Validator\\ValidatorBuilder::setMetadataFactory`::
188192

189193
use Acme\Validation\CustomMetadataFactory;
@@ -198,3 +202,5 @@ this custom implementation using
198202
Since you are using a custom metadata factory, you can't configure loaders
199203
and cachers using the ``add*Mapping()`` methods anymore. You now have to
200204
inject them into your custom metadata factory yourself.
205+
206+
.. _Packagist: https://packagist.org
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.. index::
2-
single: Validator; Validation groups
2+
single: Validator; Validation Groups
33

4-
Validation groups
5-
=================
4+
Validation Groups
5+
=================

0 commit comments

Comments
 (0)