Formats macro arguments to PHP array. (It advances tokenizer to the end as a side effect.)
public formatArray ( |
||
$tokens | ||
return | string |
/** * {control name[:method] [params]} */ public function macroControl(MacroNode $node, PhpWriter $writer) { $words = $node->tokenizer->fetchWords(); if (!$words) { throw new CompileException('Missing control name in {control}'); } $name = $writer->formatWord($words[0]); $method = isset($words[1]) ? ucfirst($words[1]) : ''; $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}"; $tokens = $node->tokenizer; $pos = $tokens->position; $param = $writer->formatArray(); $tokens->position = $pos; while ($tokens->nextToken()) { if ($tokens->isCurrent('=>') && !$tokens->depth) { $wrap = TRUE; break; } } if (empty($wrap)) { $param = substr($param, 1, -1); // removes array() or [] } return "/* line {$node->startLine} */ " . ($name[0] === '$' ? "if (is_object({$name})) \$_tmp = {$name}; else " : '') . '$_tmp = $this->global->uiControl->getComponent(' . $name . '); ' . 'if ($_tmp instanceof Nette\\Application\\UI\\IRenderable) $_tmp->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_tmp->{$method}({$param});" : $writer->write("ob_start(function () {}); \$_tmp->{$method}({$param}); echo %modify(ob_get_clean());")); }
public function filter(MacroNode $node, PhpWriter $writer) { $files = array(); while ($file = $node->tokenizer->fetchWord()) { $files[] = $this->wwwDir . '/' . ($this->pathResolver ? $this->pathResolver->expandResource($file) : $file); } if (!count($files)) { throw new CompileException('Missing file name in {js}'); } eval('$args = ' . $writer->formatArray() . ';'); return '$_control[\'js\']->render(\'' . join('\', \'', $files) . '\', array(\'config\' => ' . var_export($args, true) . '));'; }
/** * {control name[:method] [params]} */ public function macroControl(MacroNode $node, PhpWriter $writer) { $words = $node->tokenizer->fetchWords(); if (!$words) { throw new CompileException('Missing control name in {control}'); } $name = $writer->formatWord($words[0]); $method = isset($words[1]) ? ucfirst($words[1]) : ''; $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}"; $param = $writer->formatArray(); if (!Strings::contains($node->args, '=>')) { $param = substr($param, $param[0] === '[' ? 1 : 6, -1); // removes array() or [] } return ($name[0] === '$' ? "if (is_object({$name})) \$_l->tmp = {$name}; else " : '') . '$_l->tmp = $_control->getComponent(' . $name . '); ' . 'if ($_l->tmp instanceof Nette\\Application\\UI\\IRenderable) $_l->tmp->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_l->tmp->{$method}({$param})" : $writer->write("ob_start(); \$_l->tmp->{$method}({$param}); echo %modify(ob_get_clean())")); }
/** * @param MacroNode $node * @param PhpWriter $writer * @return string * @throws CompileException */ public function wizardStart(MacroNode $node, PhpWriter $writer) { $words = $node->tokenizer->fetchWords(); if (!$words) { throw new CompileException('Missing control name in {wizard}'); } $name = $writer->formatWord($words[0]); $method = isset($words[1]) ? ucfirst($words[1]) : ''; $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}"; $param = $writer->formatArray(); if (!Strings::contains($node->args, '=>')) { $param = substr($param, $param[0] === '[' ? 1 : 6, -1); // removes array() or [] } return ($name[0] === '$' ? "if (is_object({$name})) \$_l->tmp = {$name}; else " : '') . '$_l->tmp = $_control->getComponent(' . $name . '); ' . 'if (!$_l->tmp instanceof WebChemistry\\Forms\\Controls\\IWizard) throw new \\Exception(\'Wizard must be instance of WebChemistry\\Forms\\Controls\\IWizard\');' . '$wizard = new WebChemistry\\Forms\\Controls\\Wizard\\Facade($_l->tmp);'; }
/** * {js [:renderType] file[, file2]} * * @param \Latte\MacroNode $node * @param \Latte\PhpWriter $writer * @return string * @throws CompileException */ public function macroJs(\Latte\MacroNode $node, \Latte\PhpWriter $writer) { $words = $node->tokenizer->fetchWords(); if (!$words) { throw new CompileException("Missing args in {js}"); } $method = isset($words[1]) ? ucfirst($words[1]) : ''; $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}"; if (isset($words[0]) && !isset($words[1])) { $node->tokenizer->reset(); } $param = $writer->formatArray(); if (!Strings::contains($node->args, '=>')) { $param = substr($param, 6, -1); // removes array() } return 'if (($_ctrl=$_control->getComponent("js")) instanceof Nette\\Application\\UI\\IRenderable) $_ctrl->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_ctrl->{$method}({$param})" : $writer->write("ob_start(); \$_ctrl->{$method}({$param}); echo %modify(ob_get_clean())")); }