Created
April 25, 2013 03:19
-
-
Save tomshaw/5457269 to your computer and use it in GitHub Desktop.
ZF2 HTMLPurifier Controller Plugin.
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 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; | |
} | |
} |
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
// 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