[Using annotations] is a very nice and clean way of handling validation, it allows all rules to be centered on the entities, making maintenance easy. A nice complement is that constraints can be added to the class so they use more then one variable, as well as allowing you to create your own contraints.
Filtering objects using annotations « Rafael Dohms
» Doctrine and Symfony has opened my eyes to the power of annotations. Check out Rafael’s example of his filter class. I love how easy it is to understand how each element of the user object should be filtered.
<?php
namespace App\Entity;
//Import Annotations
use DMS\Filter\Rules as Filter;
class User
{
/**
* @Filter\StripTags()
* @Filter\Trim()
* @Filter\StripNewlines()
*
* @var string
*/
public $name;
/**
* @Filter\StripTags()
* @Filter\Trim()
* @Filter\StripNewlines()
*
* @var string
*/
public $email;
}
Source: blog.rafaeldohms.com.br
