Symfony

Data Validation

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

18 câu hỏi phỏng vấn·
Junior
1

What is the main role of the Symfony Validator component?

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Symfony cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí