Exemplo n.º 1
0
 /**
  * Compiles the opening tag for a function
  * @param  \Box\Brainy\Compiler\TemplateCompiler $compiler A compiler reference
  * @param  array|null  $args     Arguments
  * @param  array|null  $params   Parameters
  * @return mixed
  */
 public static function compileOpen(\Box\Brainy\Compiler\TemplateCompiler $compiler, $args, $params)
 {
     $var = self::getRequiredArg($args, 'var');
     $value = self::getRequiredArg($args, 'value');
     $scopeRaw = self::getOptionalArg($args, 'scope', self::getDefaultScope());
     switch (\Box\Brainy\Compiler\Decompile::decompileString($scopeRaw)) {
         case 'local':
             $scope = Brainy::SCOPE_LOCAL;
             break;
         case 'parent':
             $scope = Brainy::SCOPE_PARENT;
             break;
         case 'root':
             $scope = Brainy::SCOPE_ROOT;
             break;
         case 'global':
             $scope = Brainy::SCOPE_GLOBAL;
             break;
         default:
             $compiler->trigger_template_error('illegal value for "scope" attribute: ' . $scopeRaw, $compiler->lex->taglineno);
     }
     // implement Smarty2's behaviour of variables assigned by reference
     if ($compiler->template->smarty instanceof SmartyBC && Brainy::$assignment_compat === Brainy::ASSIGN_COMPAT) {
         $output = "if (isset(\$_smarty_tpl->tpl_vars[{$var}])) {\n";
         $output .= "  \$_smarty_tpl->tpl_vars[{$var}] = clone \$_smarty_tpl->tpl_vars[{$var}];\n";
         $output .= "  \$_smarty_tpl->tpl_vars[{$var}]->value = {$value};\n";
         $output .= "  \$_smarty_tpl->tpl_vars[{$var}]->scope = {$scope};\n";
         $output .= "} else {\$_smarty_tpl->assign({$var}, {$value}, {$scope});}\n";
     } else {
         $output = "\$_smarty_tpl->assign({$var}, {$value}, {$scope});\n";
     }
     return $output;
 }
Exemplo n.º 2
0
 /**
  * Pop closing tag
  *
  * Raise an error if this stack-top doesn't match with expected opening tags
  *
  * @param  \Box\Brainy\Compiler\TemplateCompiler $compiler
  * @param  array|string $expectedTag the expected opening tag names
  * @return mixed        any type the opening tag's name or saved data
  */
 public static function closeTag($compiler, $expectedTag)
 {
     if (count($compiler->_tag_stack) === 0) {
         // wrong nesting of tags
         $compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno);
     }
     // get stacked info
     list($openTag, $data) = array_pop($compiler->_tag_stack);
     // open tag must match with the expected ones
     if (!in_array($openTag, (array) $expectedTag)) {
         // wrong nesting of tags
         $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $openTag . "{$compiler->smarty->right_delimiter} tag");
         return;
     }
     return is_null($data) ? $openTag : $data;
 }