Skip to content

Instantly share code, notes, and snippets.

@abdala
Forked from rdohms/user.php
Created April 29, 2012 18:10
Show Gist options
  • Save abdala/2552346 to your computer and use it in GitHub Desktop.
Save abdala/2552346 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->filterEntity($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