예제 #1
0
파일: Attributes.php 프로젝트: jo-m/ecamp3
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     // split attributes to translate
     foreach ($codewriter->splitExpression($this->expression) as $exp) {
         list($qname, $key) = $this->parseSetExpression($exp);
         // if the translation key is specified and not empty (but may be '0')
         if (strlen($key)) {
             // we use it and replace the tag attribute with the result of the translation
             $code = $this->_getTranslationCode($codewriter, $key);
         } else {
             $attr = $this->phpelement->getAttributeNode($qname);
             if (!$attr) {
                 throw new PHPTAL_TemplateException("Unable to translate attribute {$qname}, because there is no translation key specified", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
             }
             if ($attr->getReplacedState() === PHPTAL_Dom_Attr::NOT_REPLACED) {
                 $code = $this->_getTranslationCode($codewriter, $attr->getValue());
             } elseif ($attr->getReplacedState() === PHPTAL_Dom_Attr::VALUE_REPLACED && $attr->getOverwrittenVariableName()) {
                 // sadly variables won't be interpolated in this translation
                 $code = 'echo ' . $codewriter->escapeCode('$_translator->translate(' . $attr->getOverwrittenVariableName() . ', false)');
             } else {
                 throw new PHPTAL_TemplateException("Unable to translate attribute {$qname}, because other TAL attributes are using it", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
             }
         }
         $this->phpelement->getOrCreateAttributeNode($qname)->overwriteValueWithCode($code);
     }
 }
예제 #2
0
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     // split attributes using ; delimiter
     $attrs = $codewriter->splitExpression($this->expression);
     foreach ($attrs as $exp) {
         list($qname, $expression) = $this->parseSetExpression($exp);
         if ($expression) {
             $this->prepareAttribute($codewriter, $qname, $expression);
         }
     }
 }
예제 #3
0
 public function before(PHPTAL_Php_CodeWriter $codewriter)
 {
     $expressions = $codewriter->splitExpression($this->expression);
     $definesAnyNonGlobalVars = false;
     foreach ($expressions as $exp) {
         list($defineScope, $defineVar, $expression) = $this->parseExpression($exp);
         if (!$defineVar) {
             continue;
         }
         $this->_defineScope = $defineScope;
         if ($defineScope != 'global') {
             $definesAnyNonGlobalVars = true;
         }
         // <span tal:define="global foo" /> should be invisible, but <img tal:define="bar baz" /> not
         if ($this->_defineScope != 'global' && !$this->_pushedContext) {
             $codewriter->pushContext();
             $this->_pushedContext = true;
         }
         $this->_defineVar = $defineVar;
         if ($expression === null) {
             // no expression give, use content of tag as value for newly defined
             // var.
             $this->bufferizeContent($codewriter);
             continue;
         }
         $code = $codewriter->evaluateExpression($expression);
         if (is_array($code)) {
             $this->chainedDefine($codewriter, $code);
         } elseif ($code == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) {
             $this->doDefineVarWith($codewriter, 'null');
         } else {
             $this->doDefineVarWith($codewriter, $code);
         }
     }
     // if the content of the tag was buffered or the tag has nothing to tell, we hide it.
     if ($this->_buffered || !$definesAnyNonGlobalVars && !$this->phpelement->hasRealContent() && !$this->phpelement->hasRealAttributes()) {
         $this->phpelement->hidden = true;
     }
 }