Skip to content

Instantly share code, notes, and snippets.

@dwolke
Forked from tomshaw/Purifier.php
Created May 13, 2014 15:11
Show Gist options
  • Save dwolke/a05493557bff31d46dbc to your computer and use it in GitHub Desktop.
Save dwolke/a05493557bff31d46dbc to your computer and use it in GitHub Desktop.
<?php
namespace HTMLPurifier\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
class Purifier extends AbstractPlugin
{
public function __invoke($data)
{
$purifier = $this->getController()->getServiceLocator()->get('HTMLPurifier');
if (is_string($data)) {
$data = $purifier->purify($data);
} else if (is_array($data)) {
array_walk_recursive($data, function(&$value, $key) use ($purifier) {
$value = $purifier->purify($value);
});
}
return $data;
}
}
// Simple usage scenario.
if ($this->request->isPost()) {
$post = $this->purify($request->getPost());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment