public function before(PHPTAL_Php_CodeWriter $codewriter) { $this->tmp_var = $codewriter->createTempVariable(); $codewriter->doSetVar($this->tmp_var, $codewriter->interpolateTalesVarsInString($this->expression)); $codewriter->doIf('$ctx->hasSlot(' . $this->tmp_var . ')'); $codewriter->pushCode('$ctx->echoSlot(' . $this->tmp_var . ')'); $codewriter->doElse(); }
public function before(PHPTAL_Php_CodeWriter $codewriter) { // ensure that a sources stack exists or create it $codewriter->doIf('!isset($_i18n_sources)'); $codewriter->pushCode('$_i18n_sources = array()'); $codewriter->end(); // push current source and use new one $codewriter->pushCode('$_i18n_sources[] = ' . $codewriter->getTranslatorReference() . '->setSource(' . $codewriter->str($this->expression) . ')'); }
public function after(PHPTAL_Php_CodeWriter $codewriter) { // end of if PROCEED $codewriter->doEnd(); // if trigger found, notify the end of the node $codewriter->doIf($this->var); $codewriter->pushCode($this->var . '->end(' . $codewriter->str($this->expression) . ', $tpl)'); $codewriter->doEnd(); $codewriter->recycleTempVariable($this->var); }
public function before(PHPTAL_Php_CodeWriter $codewriter) { // ensure a domain stack exists or create it $codewriter->doIf('!isset($_i18n_domains)'); $codewriter->pushCode('$_i18n_domains = array()'); $codewriter->doEnd('if'); $expression = $codewriter->interpolateTalesVarsInString($this->expression); // push current domain and use new domain $code = '$_i18n_domains[] = ' . $codewriter->getTranslatorReference() . '->useDomain(' . $expression . ')'; $codewriter->pushCode($code); }
public function before(PHPTAL_Php_CodeWriter $codewriter) { $code = $codewriter->evaluateExpression($this->expression); // If it's a chained expression build a new code path if (is_array($code)) { $this->expressions = array(); $executor = new PHPTAL_Php_TalesChainExecutor($codewriter, $code, $this); return; } // Force a falsy condition if the nothing keyword is active if ($code == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) { $code = 'false'; } $codewriter->doIf($code); }
public function before(PHPTAL_Php_CodeWriter $codewriter) { // number or variable name followed by time unit // optional per expression if (!preg_match('/^\\s*([0-9]+\\s*|[a-zA-Z][\\/a-zA-Z0-9_]*\\s+)([dhms])\\s*(?:\\;?\\s*per\\s+([^;]+)|)\\s*$/', $this->expression, $matches)) { throw new PHPTAL_ParserException("Cache attribute syntax error: " . $this->expression, $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); } $cache_len = $matches[1]; if (!is_numeric($cache_len)) { $cache_len = $codewriter->evaluateExpression($cache_len); if (is_array($cache_len)) { throw new PHPTAL_ParserException("Chained expressions in cache length are not supported", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); } } switch ($matches[2]) { case 'd': $cache_len .= '*24'; /* no break */ /* no break */ case 'h': $cache_len .= '*60'; /* no break */ /* no break */ case 'm': $cache_len .= '*60'; /* no break */ } $cache_tag = '"' . addslashes($this->phpelement->getQualifiedName() . ':' . $this->phpelement->getSourceLine()) . '"'; $cache_per_expression = isset($matches[3]) ? trim($matches[3]) : null; if ($cache_per_expression == 'url') { $cache_tag .= '.$_SERVER["REQUEST_URI"]'; } elseif ($cache_per_expression == 'nothing') { /* do nothing */ } elseif ($cache_per_expression) { $code = $codewriter->evaluateExpression($cache_per_expression); if (is_array($code)) { throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); } $cache_tag = '(' . $code . ')."@".' . $cache_tag; } $this->cache_filename_var = $codewriter->createTempVariable(); $codewriter->doSetVar($this->cache_filename_var, $codewriter->str($codewriter->getCacheFilesBaseName()) . '.md5(' . $cache_tag . ')'); $cond = '!file_exists(' . $this->cache_filename_var . ') || time() - ' . $cache_len . ' >= filemtime(' . $this->cache_filename_var . ')'; $codewriter->doIf($cond); $codewriter->doEval('ob_start()'); }
public function generateFoot(PHPTAL_Php_CodeWriter $codewriter) { if ($this->headFootDisabled) { return; } if ($this->isEmptyNode($codewriter->getOutputMode())) { return; } if ($this->footPrintCondition) { $codewriter->doIf($this->footPrintCondition); } if ($codewriter->getOutputMode() === PHPTAL::HTML5) { $codewriter->pushHTML('</' . $this->getLocalName() . '>'); } else { $codewriter->pushHTML('</' . $this->getQualifiedName() . '>'); } if ($this->footPrintCondition) { $codewriter->doEnd('if'); } }
public function before(PHPTAL_Php_CodeWriter $codewriter) { $codewriter->doIf('$ctx->hasSlot(' . $codewriter->str($this->expression) . ')'); $codewriter->pushCode('echo $ctx->getSlot(' . $codewriter->str($this->expression) . ')'); $codewriter->doElse(); }