Skip to content

Commit fbe3402

Browse files
committed
Moving things around for the new structure
1 parent 49a20e8 commit fbe3402

File tree

3 files changed

+55
-87
lines changed

3 files changed

+55
-87
lines changed

components/validator.rst

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,72 @@
55
The Validator Component
66
=======================
77

8-
The Validator component provides tools to validate values.
8+
The Validator component provides tools to validate values following the
9+
`JSR-303 Bean Validation specification`_.
910

1011
Installation
1112
------------
1213

13-
You can install the component in 2 different ways:
14+
You can install the component in two different ways:
1415

1516
* :doc:`Install it via Composer </components/using_components>` (``symfony/validator`` on `Packagist`_);
16-
* Use the official Git repository (https://github.com/symfony/validator).
17+
* Use the official Git repository (https://github.com/symfony/Validator).
1718

18-
For more information, see the code in the Git Repository.
19+
.. include:: /components/require_autoload.rst.inc
1920

20-
Learn more
21+
Usage
22+
-----
23+
24+
The Validator component behavior is based on two concepts:
25+
26+
* Contraints, which define the rules to be validated;
27+
* Validators, which are the classes that contain the actual validation logic.
28+
29+
The following example shows how to validate that a string is at least 10
30+
characters long::
31+
32+
use Symfony\Component\Validator\Validation;
33+
use Symfony\Component\Validator\Constraints\Length;
34+
use Symfony\Component\Validator\Constraints\NotBlank;
35+
36+
$validator = Validation::createValidator();
37+
$violations = $validator->validate('Bernhard', array(
38+
new Length(array('min' => 10)),
39+
new NotBlank(),
40+
));
41+
42+
if (0 !== count($violations)) {
43+
// there are errors, now you can show them
44+
foreach ($violations as $violation) {
45+
echo $violation->getMessage().'<br>';
46+
}
47+
}
48+
49+
Retrieving a Validator Instance
50+
-------------------------------
51+
52+
The :class:`Symfony\\Component\\Validator\\Validator` class is the main access
53+
point of the Validator component. To create a new instance of this class, it's
54+
recommended to use the :class:`Symfony\\Component\\Validator\\Validation` class::
55+
56+
use Symfony\Component\Validator\Validation;
57+
58+
$validator = Validation::createValidator();
59+
60+
This ``$validator`` object can validate simple variables such as strings, numbers
61+
and arrays, but it can't validate objects. To do so, configure the
62+
``Validator`` class as explained in the next sections.
63+
64+
Learn More
2165
----------
2266

2367
.. toctree::
24-
:maxdepth: 1
25-
:glob:
68+
:maxdepth: 1
69+
:glob:
2670

27-
/validation
28-
/validation/*
29-
/reference/constraints/*
71+
/components/validator/*
72+
/validator
73+
/validator/*
3074

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

components/validator/index.rst

Lines changed: 0 additions & 9 deletions
This file was deleted.

components/validator/introduction.rst

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)