1
- Constraints
2
- ===========
1
+ Restrições
2
+ ==========
3
3
4
- The Validator is designed to validate objects against * constraints *.
5
- In real life, a constraint could be : "The cake must not be burned ". In
6
- Symfony2, constraints are similar: They are assertions that a condition is
7
- true .
4
+ O Validator é projetado para validar objetos com as * restrições *.
5
+ Na vida real, uma restrição pode ser : "O bolo não deve estar queimado ". No
6
+ Symfony2, restrições são similares: Elas são afirmações de que a condição
7
+ é verdadeira .
8
8
9
- Supported Constraints
9
+ Restrições Suportadas
10
10
---------------------
11
11
12
- The following constraints are natively available in Symfony2:
12
+ As seguintes restrições são nativamente suportadas pelo Symfony2:
13
13
14
14
.. toctree ::
15
15
:hidden:
@@ -36,20 +36,21 @@ The following constraints are natively available in Symfony2:
36
36
* :doc: `Url <constraints/Url >`
37
37
* :doc: `Valid <constraints/Valid >`
38
38
39
- Constraint Targets
40
- ------------------
39
+ Alvos das Restrições
40
+ --------------------
41
41
42
- Constraints can be put on properties of a class, on public getters and on the
43
- class itself. The benefit of class constraints is that they can validate
44
- the whole state of an object at once, with all of its properties and methods.
42
+ Restrições podem ser colocadas em propriedades de uma classe, em getter publicos
43
+ e na própria classe. Os beneficios de restrições em classes é que elas podem
44
+ valida o estado inteiro de um objeto de uma só vez, com todas as suas propriedades
45
+ e métodos.
45
46
46
- Properties
47
- ~~~~~~~~~~
47
+ Propriedades
48
+ ~~~~~~~~~~~~
48
49
49
- Validating class properties is the most basic validation technique. Symfony2
50
- allows you to validate private, protected or public properties. The next
51
- listing shows how to configure the properties ``$firstName `` and ``$lastName ``
52
- of a class ``Author `` to have at least 3 characters .
50
+ A validação de propriedades de uma classe é a mais básica das técnicas de validação.
51
+ O Symfony2 permite que você valide propriedades privadas, protegidas ou públicas. A
52
+ lista a seguir mostra como configurar as propriedades ``$firstName `` e ``$lastName ``
53
+ da classe ``Author `` para ter no mínimo 3 caracteres .
53
54
54
55
.. configuration-block ::
55
56
@@ -100,17 +101,17 @@ of a class ``Author`` to have at least 3 characters.
100
101
Getters
101
102
~~~~~~~
102
103
103
- The next validation technique is to constrain the return value of a method .
104
- Symfony2 allows you to constrain any public method whose name starts with
105
- "get" or "is". In this guide, this is commonly referred to as "getter".
104
+ A próxima técnica de validação é restringir o valor do retorno de um método .
105
+ O Symfony2 permite que você restrinja qualquer método público em que o nome
106
+ comece com "get" ou "is". Nesse guia, ele é referenciado como "getter".
106
107
107
- The benefit of this technique is that it allows you to validate your object
108
- dynamically. Depending on the state of your object, the method may return
109
- different values which are then validated .
108
+ O beneficio dessa técnica é que ela permite você validar seu objeto dinamicamente.
109
+ Dependendo do estato do seu objeto, o método pode retornar diferentes valores que
110
+ então são validados .
110
111
111
- The next listing shows you how to use the :doc: `AssertTrue
112
- <constraints/AssertTrue>` constraint to validate whether a dynamically
113
- generated token is correct :
112
+ A lista a seguir mostra como usar a restrição :doc: `AssertTrue
113
+ <constraints/AssertTrue>` para validar se um token gerado dinamicamente está
114
+ correto :
114
115
115
116
.. configuration-block ::
116
117
@@ -149,19 +150,18 @@ generated token is correct:
149
150
150
151
.. note ::
151
152
152
- The keen-eyed among you will have noticed that the prefix of the getter
153
- ("get" or "is") is omitted in the mapping. This allows you to move the
154
- constraint to a property with the same name later (or vice versa) without
155
- changing your validation logic .
153
+ Se você tem uma visão aguçada, deve ter percebido que o prefixo do getter
154
+ ("get" ou "is") foi omitido do mapeamento. Isso permite que você mova a
155
+ restrição para uma propriedade com o mesmo nome depois (ou vice- versa)
156
+ sem mudar a lógica de validação .
156
157
157
- Custom Constraints
158
- ------------------
158
+ Restrições Customizadas
159
+ -----------------------
159
160
160
- You can create a custom constraint by extending the base constraint class,
161
- :class: `Symfony\\ Component\\ Validator\\ Constraint `. Options for your
162
- constraint are represented by public properties on the constraint class. For
163
- example, the ``Url `` constraint includes ``message `` and ``protocols ``
164
- properties::
161
+ Você pode criar restrições customizadas estendendo a classe base de restrições
162
+ :class: `Symfony\\ Component\\ Validator\\ Constraint `. As opções das suas restrições
163
+ são representadas como propriedades públicas na classe de restrição. Por exemplo,
164
+ a restrição ``Url `` inclui as propriedades ``message `` e ``protocols ``::
165
165
166
166
namespace Symfony\Component\Validator\Constraints;
167
167
@@ -171,24 +171,24 @@ properties::
171
171
public $protocols = array('http', 'https', 'ftp', 'ftps');
172
172
}
173
173
174
- As you can see, a constraint class is fairly minimal. The actual validation is
175
- performed by a another "constraint validator" class. Which constraint
176
- validator is specified by the constraint's ``validatedBy() `` method, which
177
- includes some simple default logic ::
174
+ Como você pode ver, uma classe de restrição é bem minima. A validação mesmo é
175
+ feita por outra classe "validadora de restrições". Que validador de restrição
176
+ é especificado pelo método ``validatedBy() ``, que inclui alguma lógica simples
177
+ por padrão ::
178
178
179
179
// in the base Symfony\Component\Validator\Constraint class
180
180
public function validatedBy()
181
181
{
182
182
return get_class($this).'Validator';
183
183
}
184
184
185
- Constraint Validators with Dependencies
186
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185
+ Validadores de Restrição com Dependencias
186
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187
187
188
- If your constraint validator has dependencies, such as a database connection ,
189
- it will need to be configured as a service in the dependency injection
190
- container. This service must include the ``validator.constraint_validator ``
191
- tag and an ``alias `` attribute :
188
+ Se o se validador de restrição tiver dependencias, como conexão com o banco ,
189
+ ele precisará ser configurado como um serviço no container de dependency injection.
190
+ Esse serviço deve incluir a tag ``validator.constraint_validator `` e um atributo
191
+ ``alias ``:
192
192
193
193
.. configuration-block ::
194
194
@@ -214,8 +214,7 @@ tag and an ``alias`` attribute:
214
214
->addTag('validator.constraint_validator', array('alias' => 'alias_name'))
215
215
;
216
216
217
- Your constraint class may now use this alias to reference the appropriate
218
- validator::
217
+ Suas classes de restrição podem agora usar alias para referenciar o validador apropriado::
219
218
220
219
public function validatedBy()
221
220
{
0 commit comments