
Data Validation
Constraints, custom validators, validation groups, Entity validation, DTO validation
1What is the main role of the Symfony Validator component?
What is the main role of the Symfony Validator component?
Відповідь
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.
2Which constraint should be used to verify that a field is not empty or null?
Which constraint should be used to verify that a field is not empty or null?
Відповідь
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.
3How to apply a validation constraint on an entity property using PHP 8 attributes?
How to apply a validation constraint on an entity property using PHP 8 attributes?
Відповідь
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.
Which constraint validates that a string matches a valid email format?
How to validate the length of a string with minimum and maximum values?
+15 питань зі співбесід
Інші теми співбесід Symfony
Modern PHP (8.1+)
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Dependency Injection & Services
Security & Authentication
Doctrine Advanced
API Platform
Serializer Component
Events & Event Subscribers
Console & Commands
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Опануй Symfony для наступної співбесіди
Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.
Почни безкоштовно