-
-
Save abdala/2552346 to your computer and use it in GitHub Desktop.
DMS\Filter Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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->filterEntity($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