Ejemplo n.º 1
0
 private function prepareAttribute(PHPTAL_Php_CodeWriter $codewriter, $qname, $expression)
 {
     $tales_code = $this->extractEchoType($expression);
     $code = $codewriter->evaluateExpression($tales_code);
     // XHTML boolean attribute does not appear when empty or false
     if (PHPTAL_Dom_Defs::getInstance()->isBooleanAttribute($qname)) {
         // I don't want to mix code for boolean with chained executor
         // so compile it again to simple expression
         if (is_array($code)) {
             $code = PHPTAL_Php_TalesInternal::compileToPHPExpression($tales_code);
         }
         return $this->prepareBooleanAttribute($codewriter, $qname, $code);
     }
     // if $code is an array then the attribute value is decided by a
     // tales chained expression
     if (is_array($code)) {
         return $this->prepareChainedAttribute($codewriter, $qname, $code);
     }
     // i18n needs to read replaced value of the attribute, which is not possible if attribute is completely replaced with conditional code
     if ($this->phpelement->hasAttributeNS('http://xml.zope.org/namespaces/i18n', 'attributes')) {
         $this->prepareAttributeUnconditional($codewriter, $qname, $code);
     } else {
         $this->prepareAttributeConditional($codewriter, $qname, $code);
     }
 }
Ejemplo n.º 2
0
 /**
  * compile TALES expression according to current talesMode
  * @return string with PHP code
  */
 private function compileTalesToPHPExpression($expression)
 {
     if ($this->getTalesMode() === 'php') {
         return PHPTAL_Php_TalesInternal::php($expression);
     }
     return PHPTAL_Php_TalesInternal::compileToPHPExpression($expression, false);
 }
Ejemplo n.º 3
0
 /**
  * @param key - unescaped string (not PHP code) for the key
  */
 private function _getTranslationCode(PHPTAL_Php_CodeWriter $codewriter, $key)
 {
     $code = '';
     if (preg_match_all('/\\$\\{(.*?)\\}/', $key, $m)) {
         array_shift($m);
         $m = array_shift($m);
         foreach ($m as $name) {
             $code .= "\n" . '$_translator->setVar(' . $codewriter->str($name) . ',' . PHPTAL_Php_TalesInternal::compileToPHPExpression($name) . ');';
             // allow more complex TAL expressions
         }
         $code .= "\n";
     }
     // notice the false boolean which indicate that the html is escaped
     // elsewhere looks like an hack doesn't it ? :)
     $code .= 'echo ' . $codewriter->escapeCode('$_translator->translate(' . $codewriter->str($key) . ', false)');
     return $code;
 }
Ejemplo n.º 4
0
/**
 * translates TALES expression with alternatives into single PHP expression. 
 * Identical to phptal_tales() for singular expressions.
 * 
 * Please use this function rather than PHPTAL_Php_TalesInternal methods.
 *
 * @see PHPTAL_Php_TalesInternal::compileToPHPStatements()
 * @return string
 */
function phptal_tale($expression, $nothrow = false)
{
    return PHPTAL_Php_TalesInternal::compileToPHPExpression($expression, $nothrow);
}