Skip to content

Instantly share code, notes, and snippets.

@gfreeau
Last active August 29, 2015 14:01
Show Gist options
  • Save gfreeau/9d8df717026c2ddc7dcc to your computer and use it in GitHub Desktop.
Save gfreeau/9d8df717026c2ddc7dcc to your computer and use it in GitHub Desktop.
XML loader for DMS-Filter
<?php
require 'vendor/autoload.php';
use DMS\Filter\Mapping\Loader\YamlFileLoader;
use DMS\Filter\Mapping\Loader\XmlFileLoader;
use DMS\Filter\Filter;
use DMS\Filter\Mapping\ClassMetadataFactory;
use DMS\Filter\Filters\Loader\FilterLoader;
use App\Entity\User;
$loader = new XmlFileLoader('./filter.xml');
//$loader = new YamlFileLoader('./filter.yml');
//Get a MetadataFactory
$metadataFactory = new ClassMetadataFactory($loader);
//Get a Filter
$filter = new Filter($metadataFactory, new FilterLoader());
//Get your Entity
$user = new User("My <b><i>name</i></b>", " email@mail.com");
//Filter you entity
$filter->filterEntity($user);
echo $user->getName(); //"My name"
echo $user->getEmail(); //"email@mail.com"
<?php
//src/App/Entity/User.php
namespace App\Entity;
class User
{
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $email;
public function __construct($name, $email)
{
$this->name = $name;
$this->email = $email;
}
public function getName()
{
return $this->name;
}
public function getEmail()
{
return $this->email;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment