public function testBaseSetter() { $ist = new TemplateEvent($this->twital, $this->template); $template = $this->getTemplateMock(); $ist->setTemplate($template); $this->assertSame($template, $ist->getTemplate()); }
public function addCustomNamespace(TemplateEvent $event) { foreach (iterator_to_array($event->getTemplate()->getDocument()->childNodes) as $child) { if ($child instanceof \DOMElement) { DOMHelper::checkNamespaces($child, $this->customNamespaces); } } }
public function addEscaping(TemplateEvent $event) { $doc = $event->getTemplate()->getDocument(); $xp = new \DOMXPath($doc); $xp->registerNamespace("xh", "http://www.w3.org/1999/xhtml"); $this->esapeScript($doc, $xp); $this->esapeStyle($doc, $xp); $this->esapeUrls($doc, $xp); }
public function removeAttribute(TemplateEvent $event) { $doc = $event->getTemplate()->getDocument(); $xp = new \DOMXPath($doc); $xp->registerNamespace('twital', Twital::NS); $attributes = $xp->query("//@twital:__internal-id__"); foreach ($attributes as $attribute) { $attribute->ownerElement->removeAttributeNode($attribute); } }
public function removeWhitespace(TemplateEvent $event) { $doc = $event->getTemplate()->getDocument(); $xp = new \DOMXPath($doc); $xp->registerNamespace("t", Twital::NS); foreach ($this->performXpathQuery($xp, "//text()[ancestor::*[@t:trans or @t:trans-n]]", $doc) as $text) { if ($this->isAllowedNode($text->parentNode)) { $text->data = preg_replace('/\\s+/', ' ', $text->data); if ($text->parentNode->childNodes->length === 1) { $trimmed = trim($text->data); if (!strlen($trimmed) && strlen($text->data)) { $trimmed = " "; } $text->data = $trimmed; } elseif ($text->parentNode->hasAttributeNs(Twital::NS, 'trans') || $text->parentNode->hasAttributeNs(Twital::NS, 'trans-n')) { if ($text->parentNode->firstChild === $text) { $text->data = ltrim($text->data); } elseif ($text->parentNode->lastChild === $text) { $text->data = rtrim($text->data); } } } } }
/** * * @param SourceAdapter $adapter * @param string $source * @return string */ public function compile(SourceAdapter $adapter, $source) { $this->initExtensions(); $sourceEvent = new SourceEvent($this, $source); $this->dispatcher->dispatch('compiler.pre_load', $sourceEvent); $template = $adapter->load($sourceEvent->getTemplate()); $templateEvent = new TemplateEvent($this, $template); $this->dispatcher->dispatch('compiler.post_load', $templateEvent); $compiler = new Compiler($this, isset($this->options['lexer']) ? $this->options['lexer'] : array()); $compiler->compile($templateEvent->getTemplate()->getDocument()); $templateEvent = new TemplateEvent($this, $templateEvent->getTemplate()); $this->dispatcher->dispatch('compiler.pre_dump', $templateEvent); $source = $adapter->dump($templateEvent->getTemplate()); $sourceEvent = new SourceEvent($this, $source); $this->dispatcher->dispatch('compiler.post_dump', $sourceEvent); return $sourceEvent->getTemplate(); }