public
Last active

DMS\Filter Example

  • Download Gist
user.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?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;
 
}
yourapp.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?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"
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.