Logo

Thoom Technologies

  • Random
  • Archive
  • RSS
[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

    • #doctrine
    • #symfony2
    • #php
    • #annotation
  • 1 year ago
  • 8
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

8 Notes/ Hide

  1. thoomtech posted this

Recent comments

Blog comments powered by Disqus
← Previous • Next →
A web consulting and development company focused on LAMP technologies
  • Developer-Free Tumblr
  • thoom on github
  • RSS
  • Random
  • Archive
  • Mobile

© 2013 Thoom Technologies.

Effector Theme by Pixel Union