Skip to content

Instantly share code, notes, and snippets.

@rdohms
Created July 21, 2011 22:05
Show Gist options
  • 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 protected]";
//Filter you entity
$filter->filter($user);
echo $user->name; //"My name"
echo $user->email; //"[email protected]"
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment