Symfony

Data Validation

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

18 pytań z rozmów·
Junior
1

What is the main role of the Symfony Validator component?

Odpowiedź

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?

Odpowiedź

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?

Odpowiedź

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 pytań z rozmów

Opanuj Symfony na następną rozmowę

Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.

Zacznij za darmo