Symfony

Data Validation

Constraints, custom validators, validation groups, Entity validation, DTO validation

18 perguntas de entrevistaยท
Junior
1

What is the main role of the Symfony Validator component?

Resposta

The Symfony Validator component validates data according to defined rules called constraints. It can validate objects, scalar values and arrays, returning a list of violations if rules are not met. This component is integrated with forms but can also be used independently.

2

Which constraint should be used to verify that a field is not empty or null?

Resposta

The NotBlank constraint checks that a value is not empty (empty string, null, or empty array). It differs from NotNull which accepts an empty string. NotBlank is most commonly used for required form fields as it also rejects strings containing only whitespace.

3

How to apply a validation constraint on an entity property using PHP 8 attributes?

Resposta

Since PHP 8, validation constraints are applied via attributes directly above properties. The syntax uses the Assert prefix with the Symfony\Component\Validator\Constraints namespace. This approach is more concise than DocBlock annotations and benefits from native PHP support.

4

Which constraint validates that a string matches a valid email format?

5

How to validate the length of a string with minimum and maximum values?

+15 perguntas de entrevista

Domine Symfony para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis