Creating custom validation constraint could be tricky for new Symfony2 developers. Based on the idea of validating Twig syntax I’ll show you how to create custom validator with DI dependencies.
Imagine that you want to allow to edit templates through your administration panel – it’s common task in CMS, E-shop engines. To avoid errors while compiling templates (source syntax errors) you have to validate posted template source.
To accomplish that we’ll create our own configurable Validation Constraint.