for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Goetas\Twital\EventSubscriber;
use Goetas\Twital\EventDispatcher\CompilerEvents;
use Goetas\Twital\EventDispatcher\SourceEvent;
/**
*
* @author Asmir Mustafic <[email protected]>
*/
class FixHtmlEntitiesInExpressionSubscriber extends AbstractTwigExpressionSubscriber
{
public static function getSubscribedEvents()
return array(
CompilerEvents::PRE_LOAD => 'addPlaceholder',
CompilerEvents::POST_DUMP => 'removePlaceholder',
);
}
* @param SourceEvent $event
public function addPlaceholder(SourceEvent $event)
$source = $event->getTemplate();
$format = $this->placeholderFormat;
$source = $this->processTwig($source, function ($twig) use ($format) {
return sprintf($format, htmlspecialchars($twig, ENT_COMPAT, 'UTF-8'));
});
$event->setTemplate($source);
public function removePlaceholder(SourceEvent $event)
$source = $this->processPlaceholder($source, function ($matches) {
return html_entity_decode($matches[2], ENT_COMPAT, 'UTF-8');