Compiles the file generating a JSON intermediate representation.

@param Compiler $compiler

@throws ParseException
@throws IllegalStateException if the intermediate representation is not of type 'array'

@return array
499621
public function genIR(Compiler $compiler)
    {
        $normalizedPath = $this->filesystem->normalizePath($this->filePath);

        // TODO: JS => JSON
        $compilePath = "{$normalizedPath}.js";
        $zepRealPath = realpath($this->filePath);

        if ($this->filesystem->exists($compilePath)) {
            $modificationTime = $this->filesystem->modificationTime($compilePath);
            if ($modificationTime < filemtime($zepRealPath)) {
                $this->filesystem->delete($compilePath);
                if (false != $this->filesystem->exists($compilePath.'.php')) {
                    $this->filesystem->delete($compilePath.'.php');
                }
            }
        }

        $ir = null;
        if (false == $this->filesystem->exists($compilePath)) {
            $parser = $compiler->getParserManager()->getParser();
            $ir = $parser->parse($zepRealPath);
            $this->filesystem->write($compilePath, json_encode($ir, JSON_PRETTY_PRINT));
        }

        if (false == $this->filesystem->exists($compilePath.'.php')) {
            if (empty($ir)) {
                $ir = json_decode($this->filesystem->read($compilePath), true);
            }

            $data = '<?php return '.var_export($ir, true).';';
            $this->filesystem->write($compilePath.'.php', $data);
        }

        $contents = $this->filesystem->requireFile($compilePath.'.php');

        if (false == \is_array($contents)) {
            throw new IllegalStateException(
                sprintf(
                    'Generating the intermediate representation for the file "%s" was failed.',
                    realpath($this->filePath)
                )
            );
        }

        return $contents;
    }
98021
public function compile(Twig_Compiler $compiler)
    {
        $compiler
            ->addDebugInfo($this)
            ->write("echo \$this->env->getExtension('Cms\Twig\Extension')->startBlock(")
            ->raw("'".$this->getAttribute('name')."'")
            ->write(");\n")
        ;

        $isOverwrite = strtolower($this->getAttribute('endType')) == 'overwrite';

        $compiler->subcompile($this->getNode('body'));

        $compiler
            ->addDebugInfo($this)
            ->write("echo \$this->env->getExtension('Cms\Twig\Extension')->endBlock(")
            ->raw($isOverwrite ? 'false' : 'true')
            ->write(");\n")
        ;
    }
265472
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
    {
        $tokens = $compiler->getParamTokens($params);
        $params = $compiler->getCompiledParams($params);
        $pre    = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE;

        $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;

        if (isset($params['hasElse'])) {
            $post .= $params['hasElse'];
        }

        return $pre . $content . $post;
    }
394801
public function compile(\Twig_Compiler $compiler)
    {
        $name = $this->getAttribute('name');
        $type = $this->getAttribute('type');
        list($loopKey, $loopId) = $this->buildLoopVariables();

        $compiler
            ->write('public function block_')->raw($name)->raw('($context, array $blocks = array()')->raw($loopKey)->raw(')')->raw("\n")
            ->write('{')->raw("\n")
            ->indent()
            ->addDebugInfo($this)
            ->write('$')->raw($name)->raw(' = ')
        ;

        // checks if the type is an block builder, block, or block view
        if ($type instanceof \Twig_Node_Expression_Name) {
            $compiler
                ->raw('(')
                ->subcompile($type)
                ->raw(' instanceof \Fxp\Component\Block\BlockBuilderInterface || ')
                ->subcompile($type)
                ->raw(' instanceof \Fxp\Component\Block\BlockInterface || ')
                ->subcompile($type)
                ->raw(' instanceof \Fxp\Component\Block\BlockView) ? ')
                ->subcompile($type)
                ->raw(' : ')
            ;
        }

        // create the block
        $compiler
            ->raw('$this->env->getExtension(\'Fxp\Component\Block\Twig\Extension\BlockExtension\')->createNamed(')
            ->subcompile($type)
            ->raw(', ')
        ;
        $this->compileBlockOptions($compiler, $loopId);
        $compiler->raw(');')->raw("\n");

        if ($type instanceof \Twig_Node_Expression_Name) {
            $compiler
                ->write('if ($')->raw($name)->raw(' instanceof \Fxp\Component\Block\BlockBuilderInterface) {')->raw("\n")
                ->indent()
                ->write('$')->raw($name)->raw(' = $')->raw($name)->raw('->getBlock();')->raw("\n")
                ->outdent()
                ->write('}')->raw("\n")
            ;
        }

        // list of children
        $compiler
            ->write('$')->raw($name)->raw('Children = array();')->raw("\n")
        ;

        if ($this->hasNode('sblocks')) {
            $compiler->subcompile($this->getNode('sblocks'));
        }

        $compiler
            ->raw("\n")
            ->write('return array($')->raw($name)->raw(', $')->raw($name)->raw('Children);')->raw("\n")
            ->outdent()
            ->write('}')->raw("\n")->raw("\n")
        ;
    }
1095657
protected function compileTags(Compiler $compiler): void
    {
        $tagClass = $this->getAttribute('tagClass');
        $assets = $this->getAttribute('assets');
        $attributes = $this->getAttribute('attributes');
        $position = $this->getAttribute('position');

        foreach ($assets as $asset) {
            $compiler
                ->write(sprintf('->addTag(new \%s(', $tagClass))
                ->repr($asset)
                ->raw(', ')->repr($attributes)
                ->raw(', ')->repr($position)
                ->raw(', ')->repr($this->getTemplateLine())
                ->raw(', ')->repr($this->getTemplateName())
                ->raw('))'.PHP_EOL)
            ;
        }
    }
441592
public function compile(Twig_Compiler $compiler)
    {
        $this->compileTemplate($compiler);

        foreach ($this->getAttribute('embedded_templates') as $template) {
            $compiler->subcompile($template);
        }
    }
1004508
public function compile($args, $compiler)
    {
        $_attr = $this->getAttributes($compiler, $args);
        // reset variable filter to previous state
        if (count($compiler->variable_filter_stack)) {
            $compiler->template->variable_filters = array_pop($compiler->variable_filter_stack);
        } else {
            $compiler->template->variable_filters = array();
        }
        // this tag does not return compiled code
        $compiler->has_code = false;

        return true;
    }
1163043
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
    {
        $params       = $compiler->getCompiledParams($params);
        $parsedParams = array();
        if (!isset($params['*'])) {
            $params['*'] = array();
        }
        foreach ($params['*'] as $param => $defValue) {
            if (is_numeric($param)) {
                $param    = $defValue;
                $defValue = null;
            }
            $param = trim($param, '\'"');
            if (!preg_match('#^[a-z0-9_]+$#i', $param)) {
                throw new CompilationException($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _');
            }
            $parsedParams[$param] = $defValue;
        }
        $params['name'] = substr($params['name'], 1, - 1);
        $params['*']    = $parsedParams;
        $params['uuid'] = uniqid();
        $compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']);
        $currentBlock           = &$compiler->getCurrentBlock();
        $currentBlock['params'] = $params;

        return '';
    }
860044
public function compile(Twig_Compiler $compiler)
    {
        if ($this->getAttribute('output')) {
            $compiler
                ->addDebugInfo($this)
                ->write("\$this->displayParentBlock(")
                ->string($this->getAttribute('name'))
                ->raw(", \$context, \$blocks);\n")
            ;
        } else {
            $compiler
                ->raw("\$this->renderParentBlock(")
                ->string($this->getAttribute('name'))
                ->raw(", \$context, \$blocks)")
            ;
        }
    }
467057
public function compile(Twig_Compiler $compiler)
    {
        $compiler->raw('intval(floor(');
        parent::compile($compiler);
        $compiler->raw('))');
    }
1370068
public function compile($args, $compiler)
    {
        static $_is_stringy = array('string' => true, 'eval' => true);
        $this->_rdl = preg_quote($compiler->smarty->right_delimiter);
        $this->_ldl = preg_quote($compiler->smarty->left_delimiter);
        $filepath = $compiler->template->source->filepath;
        $this->mbstring_overload = ini_get('mbstring.func_overload') & 2;
        // check and get attributes
        $_attr = $this->getAttributes($compiler, $args);
        if ($_attr['nocache'] === true) {
            $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
        }

        $_smarty_tpl = $compiler->template;
        $include_file = null;
        if (strpos($_attr['file'], '$_tmp') !== false) {
            $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
        }
        eval('$include_file = ' . $_attr['file'] . ';');
        // create template object
        $_template = new $compiler->smarty->template_class($include_file, $compiler->smarty, $compiler->template);
        // save file dependency
        if (isset($_is_stringy[$_template->source->type])) {
            $template_sha1 = sha1($include_file);
        } else {
            $template_sha1 = sha1($_template->source->filepath);
        }
        if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
            $compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 1);
        }
        $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
        $_content = ($this->mbstring_overload ? mb_substr($compiler->template->source->content, $compiler->lex->counter - 1, 20000000, 'latin1') : substr($compiler->template->source->content, $compiler->lex->counter - 1));
        if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
        preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
            $compiler->trigger_template_error('unmatched {block} {/block} pairs');
        }
        preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}|{$this->_ldl}\*([\S\s]*?)\*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
        $_result_count = count($_result[0]);
        $_start = 0;
        while ($_start+1 < $_result_count) {
            $_end = 0;
            $_level = 1;
            if (($this->mbstring_overload ? mb_substr($_result[0][$_start][0],0,mb_strlen($compiler->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start][0],0,strlen($compiler->smarty->left_delimiter)+1)) == $compiler->smarty->left_delimiter.'*') {
                $_start++;
                continue;
            }
            while ($_level != 0) {
                $_end++;
                if (($this->mbstring_overload ? mb_substr($_result[0][$_start + $_end][0],0,mb_strlen($compiler->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start + $_end][0],0,strlen($compiler->smarty->left_delimiter)+1)) == $compiler->smarty->left_delimiter.'*') {
                    continue;
                }
                if (!strpos($_result[0][$_start + $_end][0], '/')) {
                    $_level++;
                } else {
                    $_level--;
                }
            }
            $_block_content = str_replace($compiler->smarty->left_delimiter . '$smarty.block.parent' . $compiler->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
            ($this->mbstring_overload ? mb_substr($_content, $_result[0][$_start][1] + mb_strlen($_result[0][$_start][0], 'latin1'), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + mb_strlen($_result[0][$_start][0], 'latin1'), 'latin1') : substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0]))));
            Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
            $_start = $_start + $_end + 1;
        }
        if ($_template->source->type == 'extends') {
            $_template->block_data = $compiler->template->block_data;
        }
        $compiler->template->source->content = $_template->source->content;
        if ($_template->source->type == 'extends') {
            $compiler->template->block_data = $_template->block_data;
            foreach ($_template->source->components as $key => $component) {
                $compiler->template->properties['file_dependency'][$key] = array($component->filepath, $component->timestamp, $component->type);
            }
        }
        $compiler->template->source->filepath = $_template->source->filepath;
        $compiler->abort_and_recompile = true;
        return '';
    }
69204
public static function compile(Compiler $compiler, $file)
    {
        preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
        $resource   = $m[1];
        $identifier = $m[2];

        $tpl = $compiler->getCore()->templateFactory($resource, $identifier);

        if ($tpl === null) {
            throw new CompilationException($compiler,
                'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
        } elseif ($tpl === false) {
            throw new CompilationException($compiler,
                'Load Templates : Resource "' . $resource . '" does not support includes.');
        }

        $out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";

        $modCheck = $tpl->getIsModifiedCode();

        if ($modCheck) {
            $out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
        } else {
            $out .= 'try {
	$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (Dwoo\Exception $e) {
	$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
	$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
	$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
        }

        return $out;
    }
740780
public function compile(\Twig_Compiler $compiler) {

        $duration = $this->getAttribute('duration');
        $key = $this->getAttribute('key');

        $until = $this->getNode('until');
        $if = $this->getNode('if');
        $unless = $this->getNode('unless');

        if($duration === null){
            //10 minutes for default
            $duration = 600;
        }//if
        else {
            $duration = $this->duration($duration);
        }//el

        if($key !== null){
            $key = md5($key);
        } else {
            $key = md5($this->getNode('body'));
        }//el

        $compiler->addDebugInfo($this);

        $compiler
            ->write("if(");

        if($if){

            $compiler
                ->subcompile($if);

        }//if
        else if($unless){

            $compiler
                ->write('!')
                ->subcompile($unless);

        }//elif
        else {

            $compiler
                ->write('true');

        }//el

            $compiler
                ->write("){\n")
                ->write("\$cache = \Cache::get('{$key}');\n")
                ->write("if(\$cache === null){\n")
                    ->write("ob_start();\n")
                    ->subcompile($this->getNode('body'))
                    ->write("\$cache = ob_get_clean();\n");

            if($until){

                $until = $this->duration($until);

                $compiler
                    ->write("\$duration = {$until};\n");

            } else {

                $compiler
                    ->write("\$duration = {$duration};\n");

            }//el

            $compiler
                ->write("\Cache::set('{$key}',\$cache,\$duration);\n")
                ->write("}\n")
                ->write("echo \$cache;\n");

        $compiler
            ->write("} else {\n")
                ->subcompile($this->getNode('body'))
            ->write("}\n");

    }
882287
protected function _compile($source)
    {
        $result = false;
        if(is_callable($this->_compiler)) {
            $result = call_user_func($this->_compiler, $source);
        }

        return $result;
    }
534800
public function compile(Compiler $compiler)
    {
        $compiler
            ->addDebugInfo($this)
            ->write('switch (')
            ->subcompile($this->getNode('value'))
            ->raw(") {\n")
            ->indent();

        foreach ($this->getNode('cases') as $case) {
            if (!$case->hasNode('body')) {
                continue;
            }

            foreach ($case->getNode('values') as $value) {
                $compiler
                    ->write('case ')
                    ->subcompile($value)
                    ->raw(":\n");
            }

            $compiler
                ->write("{\n")
                ->indent()
                ->subcompile($case->getNode('body'))
                ->write("break;\n")
                ->outdent()
                ->write("}\n");
        }

        if ($this->hasNode('default') && $this->getNode('default') !== null) {
            $compiler
                ->write("default:\n")
                ->write("{\n")
                ->indent()
                ->subcompile($this->getNode('default'))
                ->outdent()
                ->write("}\n");
        }

        $compiler
            ->outdent()
            ->write("}\n");
    }
872810
public function compile(Twig_Compiler $compiler)
    {
        $compiler->addDebugInfo($this);

        $getExtension = sprintf('$this->env->getExtension(\'%s\')', ZichtFrameworkExtraExtension::class);

        $compiler
            ->write('$parent = $context;')
            ->write(sprintf('foreach (%s->getAnnotationRegistry()->getAnnotations() as $annotation) {', $getExtension))
            ->indent()
            ->write('$context[\'name\'] = $annotation[\'name\'];')
            ->write('$context[\'value\'] = $annotation[\'value\'];')
            ->subcompile($this->getNode('body'))
            ->outdent()
            ->write('}');
        $compiler->write('$context = $parent;');
    }
1066555
public function compile(Twig_Compiler $compiler)
    {
        $compiler
            ->addDebugInfo($this)
            ->write('if(!isset($withStack)) {' . "\n")
            ->indent()
            ->write('$withStack = array();' . "\n")
            ->outdent()
            ->write('}' . "\n")
            ->write("\n")
            ->write('array_push($withStack, $context);' . "\n");

        $compiler->write('$values = array_merge(' . "\n")->indent();
        $i = 0;
        foreach ($this->getAttribute('items') as $argument) {
            if ($i ++ > 0) {
                $compiler->raw(',' . "\n");
            }
            $this->compileArgument($compiler, $argument);
        }
        $compiler->raw("\n")->outdent()->write(");\n");

        if (!$this->hasOption('always')) {
            $compiler->write(
                'if (count(array_filter($values, function($o) {
                    if ($o instanceof \Countable) {
                        return count($o) > 0;
                    } else {
                        return !empty($o);
                    }
                }))) {'
            );
        }

        if ($this->hasOption('merged')) {
            $compiler->write('$values += $context;' . "\n");
        } else {
            $compiler->write('$values += array(\'_parent\' => $context);');
        }

        $compiler
            ->write('$context = $values;')
            ->subcompile($this->getNode('body'));

        if (!$this->hasOption('always')) {
            $compiler->write('}');
        }
        $compiler->write('$context = array_pop($withStack);' . "\n");
    }