Skip to content

Instantly share code, notes, and snippets.

@rdohms
Created July 21, 2011 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rdohms/1098352 to your computer and use it in GitHub Desktop.
Save rdohms/1098352 to your computer and use it in GitHub Desktop.
DMS\Filter Example
<?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;
}
<?php
//Get Doctrine Reader
$reader = new Annotations\AnnotationReader();
$reader->setEnableParsePhpImports(true);
//Load AnnotationLoader
$loader = new Mapping\Loader\AnnotationLoader($reader);
$this->loader = $loader;
//Get a MetadataFactory
$metadataFactory = new Mapping\ClassMetadataFactory($loader);
//Get a Filter
$filter = new DMS\Filter\Filter($metadataFactory);
//Get your Entity
$user = new App\Entity\User();
$user->name = "My <b>name</b>";
$user->email = " email@mail.com";
//Filter you entity
$filter->filter($user);
echo $user->name; //"My name"
echo $user->email; //"email@mail.com"
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment