Goetas\Twital\Twital::compile PHP Method

compile() public method

public compile ( Goetas\Twital\SourceAdapter $adapter, string $source ) : string
$adapter Goetas\Twital\SourceAdapter
$source string
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();
    }