@@ -37,20 +37,20 @@ discard block |
||
| 37 | 37 | class PHPTAL_Php_Transformer |
| 38 | 38 | { |
| 39 | 39 | const ST_WHITE = -1; // start of string or whitespace |
| 40 | - const ST_NONE = 0; // pass through (operators, parens, etc.) |
|
| 41 | - const ST_STR = 1; // 'foo' |
|
| 42 | - const ST_ESTR = 2; // "foo ${x} bar" |
|
| 43 | - const ST_VAR = 3; // abcd |
|
| 44 | - const ST_NUM = 4; // 123.02 |
|
| 45 | - const ST_EVAL = 5; // $somevar |
|
| 46 | - const ST_MEMBER = 6; // abcd.x |
|
| 47 | - const ST_STATIC = 7; // class::[$]static|const |
|
| 48 | - const ST_DEFINE = 8; // @MY_DEFINE |
|
| 40 | + const ST_NONE = 0; // pass through (operators, parens, etc.) |
|
| 41 | + const ST_STR = 1; // 'foo' |
|
| 42 | + const ST_ESTR = 2; // "foo ${x} bar" |
|
| 43 | + const ST_VAR = 3; // abcd |
|
| 44 | + const ST_NUM = 4; // 123.02 |
|
| 45 | + const ST_EVAL = 5; // $somevar |
|
| 46 | + const ST_MEMBER = 6; // abcd.x |
|
| 47 | + const ST_STATIC = 7; // class::[$]static|const |
|
| 48 | + const ST_DEFINE = 8; // @MY_DEFINE |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * transform PHPTAL's php-like syntax into real PHP |
| 52 | 52 | */ |
| 53 | - public static function transform($str, $prefix='$') |
|
| 53 | + public static function transform($str, $prefix = '$') |
|
| 54 | 54 | { |
| 55 | 55 | $len = strlen($str); |
| 56 | 56 | $state = self::ST_WHITE; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $result .= '->'; |
| 120 | 120 | $state = self::ST_MEMBER; |
| 121 | 121 | $mark = $i+2; |
| 122 | - $i+=2; |
|
| 122 | + $i += 2; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | // @ is an access to some defined variable |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | // $xxx |
| 141 | 141 | case self::ST_EVAL: |
| 142 | 142 | if (!self::isVarNameChar($c)) { |
| 143 | - $result .= $prefix . substr($str, $mark, $i-$mark); |
|
| 143 | + $result .= $prefix.substr($str, $mark, $i-$mark); |
|
| 144 | 144 | $result .= '}'; |
| 145 | 145 | $state = self::ST_NONE; |
| 146 | 146 | } |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | // instring interpolation, search } and transform the |
| 178 | 178 | // interpollation to insert it into the string |
| 179 | 179 | elseif ($c === '$' && $i+1 < $len && $str[$i+1] === '{') { |
| 180 | - $result .= substr($str, $mark, $i-$mark) . '{'; |
|
| 180 | + $result .= substr($str, $mark, $i-$mark).'{'; |
|
| 181 | 181 | |
| 182 | 182 | $sub = 0; |
| 183 | - for ($j = $i; $j<$len; $j++) { |
|
| 183 | + for ($j = $i; $j < $len; $j++) { |
|
| 184 | 184 | if ($str[$j] === '{') { |
| 185 | 185 | $sub++; |
| 186 | 186 | } elseif ($str[$j] === '}' && (--$sub) == 0) { |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | // end of var, begin of member (method or var) |
| 201 | 201 | elseif ($c === '.') { |
| 202 | - $result .= $prefix . substr($str, $mark, $i-$mark); |
|
| 202 | + $result .= $prefix.substr($str, $mark, $i-$mark); |
|
| 203 | 203 | $result .= '->'; |
| 204 | 204 | $state = self::ST_MEMBER; |
| 205 | 205 | $mark = $i+1; |
@@ -219,10 +219,10 @@ discard block |
||
| 219 | 219 | } |
| 220 | 220 | // array index, the var is done |
| 221 | 221 | elseif ($c === '[') { |
| 222 | - if ($str[$mark]==='_') { // superglobal? |
|
| 223 | - $result .= '$' . substr($str, $mark, $i-$mark+1); |
|
| 222 | + if ($str[$mark] === '_') { // superglobal? |
|
| 223 | + $result .= '$'.substr($str, $mark, $i-$mark+1); |
|
| 224 | 224 | } else { |
| 225 | - $result .= $prefix . substr($str, $mark, $i-$mark+1); |
|
| 225 | + $result .= $prefix.substr($str, $mark, $i-$mark+1); |
|
| 226 | 226 | } |
| 227 | 227 | $state = self::ST_NONE; |
| 228 | 228 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | // regular variable |
| 254 | 254 | else { |
| 255 | - $result .= $prefix . $var; |
|
| 255 | + $result .= $prefix.$var; |
|
| 256 | 256 | } |
| 257 | 257 | $i--; |
| 258 | 258 | $state = self::ST_NONE; |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | } |
| 266 | 266 | // eval mode ${foo} |
| 267 | 267 | elseif ($c === '$' && ($i >= $len-2 || $str[$i+1] !== '{')) { |
| 268 | - $result .= '{' . $prefix; |
|
| 268 | + $result .= '{'.$prefix; |
|
| 269 | 269 | $mark++; |
| 270 | 270 | $eval = true; |
| 271 | 271 | } |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | // end of var member var, begin of new member |
| 277 | 277 | elseif ($c === '.') { |
| 278 | 278 | $result .= substr($str, $mark, $i-$mark); |
| 279 | - if ($eval) { $result .='}'; $eval = false; } |
|
| 279 | + if ($eval) { $result .= '}'; $eval = false; } |
|
| 280 | 280 | $result .= '->'; |
| 281 | 281 | $mark = $i+1; |
| 282 | 282 | $state = self::ST_MEMBER; |
@@ -284,24 +284,24 @@ discard block |
||
| 284 | 284 | // begin of static access |
| 285 | 285 | elseif ($c === ':') { |
| 286 | 286 | $result .= substr($str, $mark, $i-$mark+1); |
| 287 | - if ($eval) { $result .='}'; $eval = false; } |
|
| 287 | + if ($eval) { $result .= '}'; $eval = false; } |
|
| 288 | 288 | $state = self::ST_STATIC; |
| 289 | 289 | break; |
| 290 | 290 | } |
| 291 | 291 | // the member is a method or an array |
| 292 | 292 | elseif ($c === '(' || $c === '[') { |
| 293 | 293 | $result .= substr($str, $mark, $i-$mark+1); |
| 294 | - if ($eval) { $result .='}'; $eval = false; } |
|
| 294 | + if ($eval) { $result .= '}'; $eval = false; } |
|
| 295 | 295 | $state = self::ST_NONE; |
| 296 | 296 | } |
| 297 | 297 | // regular end of member, it is a var |
| 298 | 298 | else { |
| 299 | 299 | $var = substr($str, $mark, $i-$mark); |
| 300 | - if ($var !== '' && !preg_match('/^[a-z][a-z0-9_\x7f-\xff]*$/i',$var)) { |
|
| 300 | + if ($var !== '' && !preg_match('/^[a-z][a-z0-9_\x7f-\xff]*$/i', $var)) { |
|
| 301 | 301 | throw new PHPTAL_ParserException("Invalid field name '$var' in expression php:$str"); |
| 302 | 302 | } |
| 303 | 303 | $result .= $var; |
| 304 | - if ($eval) { $result .='}'; $eval = false; } |
|
| 304 | + if ($eval) { $result .= '}'; $eval = false; } |
|
| 305 | 305 | $state = self::ST_NONE; |
| 306 | 306 | $i--; |
| 307 | 307 | } |
@@ -63,8 +63,11 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | for ($i = 0; $i <= $len; $i++) { |
| 66 | - if ($i == $len) $c = "\0"; |
|
| 67 | - else $c = $str[$i]; |
|
| 66 | + if ($i == $len) { |
|
| 67 | + $c = "\0"; |
|
| 68 | + } else { |
|
| 69 | + $c = $str[$i]; |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | switch ($state) { |
| 70 | 73 | |
@@ -85,8 +88,7 @@ discard block |
||
| 85 | 88 | $state = self::ST_EVAL; |
| 86 | 89 | $mark = $i+1; |
| 87 | 90 | $result .= $prefix.'{'; |
| 88 | - } |
|
| 89 | - elseif (self::isDigit($c)) |
|
| 91 | + } elseif (self::isDigit($c)) |
|
| 90 | 92 | { |
| 91 | 93 | $state = self::ST_NUM; |
| 92 | 94 | $mark = $i; |
@@ -126,8 +128,7 @@ discard block |
||
| 126 | 128 | elseif ($c === '@') { |
| 127 | 129 | $state = self::ST_DEFINE; |
| 128 | 130 | $mark = $i+1; |
| 129 | - } |
|
| 130 | - elseif (ctype_space($c)) { |
|
| 131 | + } elseif (ctype_space($c)) { |
|
| 131 | 132 | $state = self::ST_WHITE; |
| 132 | 133 | $result .= $c; |
| 133 | 134 | } |
@@ -377,7 +378,9 @@ discard block |
||
| 377 | 378 | $result = trim($result); |
| 378 | 379 | |
| 379 | 380 | // CodeWriter doesn't like expressions that look like blocks |
| 380 | - if ($result[strlen($result)-1] === '}') return '('.$result.')'; |
|
| 381 | + if ($result[strlen($result)-1] === '}') { |
|
| 382 | + return '('.$result.')'; |
|
| 383 | + } |
|
| 381 | 384 | |
| 382 | 385 | return $result; |
| 383 | 386 | } |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | $code = $codewriter->evaluateExpression($expression); |
| 81 | 81 | |
| 82 | 82 | // instantiate controller using expression |
| 83 | - $codewriter->doSetVar( $this->var.'->'.$varName, 'new PHPTAL_RepeatController('.$code.')'."\n" ); |
|
| 83 | + $codewriter->doSetVar($this->var.'->'.$varName, 'new PHPTAL_RepeatController('.$code.')'."\n"); |
|
| 84 | 84 | |
| 85 | 85 | $codewriter->pushContext(); |
| 86 | 86 | |
@@ -186,7 +186,7 @@ |
||
| 186 | 186 | $executor->doElse(); |
| 187 | 187 | $attr_str = ($this->_default_escaped !== false) |
| 188 | 188 | ? ' '.$this->_attribute.'='.$codewriter->quoteAttributeValue($this->_default_escaped) // default value |
| 189 | - : ''; // do not print attribute |
|
| 189 | + : ''; // do not print attribute |
|
| 190 | 190 | $codewriter->doSetVar($this->_attkey, $codewriter->str($attr_str)); |
| 191 | 191 | $executor->breakChain(); |
| 192 | 192 | } |
@@ -115,10 +115,11 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | $codewriter->doIf("null !== ($attkey = ($code))"); |
| 117 | 117 | |
| 118 | - if ($this->_echoType !== PHPTAL_Php_Attribute::ECHO_STRUCTURE) |
|
| 119 | - $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->escapeCode($attkey).".'\"'"); |
|
| 120 | - else |
|
| 121 | - $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->stringifyCode($attkey).".'\"'"); |
|
| 118 | + if ($this->_echoType !== PHPTAL_Php_Attribute::ECHO_STRUCTURE) { |
|
| 119 | + $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->escapeCode($attkey).".'\"'"); |
|
| 120 | + } else { |
|
| 121 | + $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->stringifyCode($attkey).".'\"'"); |
|
| 122 | + } |
|
| 122 | 123 | |
| 123 | 124 | $codewriter->doElse(); |
| 124 | 125 | $codewriter->doSetVar($attkey, "''"); |
@@ -166,7 +167,9 @@ discard block |
||
| 166 | 167 | |
| 167 | 168 | public function after(PHPTAL_Php_CodeWriter $codewriter) |
| 168 | 169 | { |
| 169 | - foreach ($this->vars_to_recycle as $var) $codewriter->recycleTempVariable($var); |
|
| 170 | + foreach ($this->vars_to_recycle as $var) { |
|
| 171 | + $codewriter->recycleTempVariable($var); |
|
| 172 | + } |
|
| 170 | 173 | } |
| 171 | 174 | |
| 172 | 175 | public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor) |
@@ -202,10 +205,11 @@ discard block |
||
| 202 | 205 | } |
| 203 | 206 | $executor->doIf($condition); |
| 204 | 207 | |
| 205 | - if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE) |
|
| 206 | - $value = $codewriter->stringifyCode($this->_attkey); |
|
| 207 | - else |
|
| 208 | - $value = $codewriter->escapeCode($this->_attkey); |
|
| 208 | + if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE) { |
|
| 209 | + $value = $codewriter->stringifyCode($this->_attkey); |
|
| 210 | + } else { |
|
| 211 | + $value = $codewriter->escapeCode($this->_attkey); |
|
| 212 | + } |
|
| 209 | 213 | |
| 210 | 214 | $codewriter->doSetVar($this->_attkey, $codewriter->str(" {$this->_attribute}=\"").".$value.'\"'"); |
| 211 | 215 | } |
@@ -64,7 +64,9 @@ |
||
| 64 | 64 | |
| 65 | 65 | public function after(PHPTAL_Php_CodeWriter $codewriter) |
| 66 | 66 | { |
| 67 | - if ($this->varname) $codewriter->recycleTempVariable($this->varname); |
|
| 67 | + if ($this->varname) { |
|
| 68 | + $codewriter->recycleTempVariable($this->varname); |
|
| 69 | + } |
|
| 68 | 70 | } |
| 69 | 71 | } |
| 70 | 72 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $code = 'false'; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $codewriter->doIf('phptal_true(' . $code . ')'); |
|
| 55 | + $codewriter->doIf('phptal_true('.$code.')'); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | public function after(PHPTAL_Php_CodeWriter $codewriter) |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | { |
| 66 | 66 | // check if the expression is empty |
| 67 | 67 | if ($exp !== 'false') { |
| 68 | - $this->expressions[] = '!phptal_isempty(' . $exp . ')'; |
|
| 68 | + $this->expressions[] = '!phptal_isempty('.$exp.')'; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | if ($islast) { |
| 72 | 72 | // for the last one in the chain build a ORed condition |
| 73 | - $executor->getCodeWriter()->doIf( implode(' || ', $this->expressions ) ); |
|
| 73 | + $executor->getCodeWriter()->doIf(implode(' || ', $this->expressions)); |
|
| 74 | 74 | // The executor will always end an if so we output a dummy if |
| 75 | 75 | $executor->doIf('false'); |
| 76 | 76 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * Prevents generation of invalid PHP code when given invalid TALES |
| 48 | 48 | */ |
| 49 | - private $_chainPartGenerated=false; |
|
| 49 | + private $_chainPartGenerated = false; |
|
| 50 | 50 | |
| 51 | 51 | public function before(PHPTAL_Php_CodeWriter $codewriter) |
| 52 | 52 | { |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $code = $codewriter->evaluateExpression($expression); |
| 80 | 80 | if (is_array($code)) { |
| 81 | 81 | $this->chainedDefine($codewriter, $code); |
| 82 | - } elseif ( $code == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) { |
|
| 82 | + } elseif ($code == PHPTAL_Php_TalesInternal::NOTHING_KEYWORD) { |
|
| 83 | 83 | $this->doDefineVarWith($codewriter, 'null'); |
| 84 | 84 | } else { |
| 85 | 85 | $this->doDefineVarWith($codewriter, $code); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast) |
| 129 | 129 | { |
| 130 | - $this->_chainPartGenerated=true; |
|
| 130 | + $this->_chainPartGenerated = true; |
|
| 131 | 131 | |
| 132 | 132 | if ($this->_defineScope == 'global') { |
| 133 | 133 | $var = '$tpl->getGlobalContext()->'.$this->_defineVar; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | { |
| 174 | 174 | if (!$this->_buffered) { |
| 175 | 175 | $this->tmp_content_var = $codewriter->createTempVariable(); |
| 176 | - $codewriter->pushCode( 'ob_start()' ); |
|
| 176 | + $codewriter->pushCode('ob_start()'); |
|
| 177 | 177 | $this->phpelement->generateContent($codewriter); |
| 178 | 178 | $codewriter->doSetVar($this->tmp_content_var, 'ob_get_clean()'); |
| 179 | 179 | $this->_buffered = true; |
@@ -62,7 +62,9 @@ discard block |
||
| 62 | 62 | $this->_defineScope = $defineScope; |
| 63 | 63 | |
| 64 | 64 | // <span tal:define="global foo" /> should be invisible, but <img tal:define="bar baz" /> not |
| 65 | - if ($defineScope != 'global') $definesAnyNonGlobalVars = true; |
|
| 65 | + if ($defineScope != 'global') { |
|
| 66 | + $definesAnyNonGlobalVars = true; |
|
| 67 | + } |
|
| 66 | 68 | |
| 67 | 69 | if ($this->_defineScope != 'global' && !$this->_pushedContext) { |
| 68 | 70 | $codewriter->pushContext(); |
@@ -94,7 +96,9 @@ discard block |
||
| 94 | 96 | |
| 95 | 97 | public function after(PHPTAL_Php_CodeWriter $codewriter) |
| 96 | 98 | { |
| 97 | - if ($this->tmp_content_var) $codewriter->recycleTempVariable($this->tmp_content_var); |
|
| 99 | + if ($this->tmp_content_var) { |
|
| 100 | + $codewriter->recycleTempVariable($this->tmp_content_var); |
|
| 101 | + } |
|
| 98 | 102 | if ($this->_pushedContext) { |
| 99 | 103 | $codewriter->popContext(); |
| 100 | 104 | } |
@@ -109,7 +113,9 @@ discard block |
||
| 109 | 113 | |
| 110 | 114 | public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor) |
| 111 | 115 | { |
| 112 | - if (!$this->_chainPartGenerated) throw new PHPTAL_TemplateException("Invalid expression in tal:define", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 116 | + if (!$this->_chainPartGenerated) { |
|
| 117 | + throw new PHPTAL_TemplateException("Invalid expression in tal:define", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 118 | + } |
|
| 113 | 119 | |
| 114 | 120 | $executor->doElse(); |
| 115 | 121 | $this->doDefineVarWith($executor->getCodeWriter(), 'null'); |
@@ -118,7 +124,9 @@ discard block |
||
| 118 | 124 | |
| 119 | 125 | public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor) |
| 120 | 126 | { |
| 121 | - if (!$this->_chainPartGenerated) throw new PHPTAL_TemplateException("Invalid expression in tal:define", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 127 | + if (!$this->_chainPartGenerated) { |
|
| 128 | + throw new PHPTAL_TemplateException("Invalid expression in tal:define", $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 129 | + } |
|
| 122 | 130 | |
| 123 | 131 | $executor->doElse(); |
| 124 | 132 | $this->bufferizeContent($executor->getCodeWriter()); |
@@ -165,7 +173,9 @@ discard block |
||
| 165 | 173 | |
| 166 | 174 | // extract varname and expression from remaining of expression |
| 167 | 175 | list($defineVar, $exp) = $this->parseSetExpression($exp); |
| 168 | - if ($exp !== null) $exp = trim($exp); |
|
| 176 | + if ($exp !== null) { |
|
| 177 | + $exp = trim($exp); |
|
| 178 | + } |
|
| 169 | 179 | return array($defineScope, $defineVar, $exp); |
| 170 | 180 | } |
| 171 | 181 | |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class PHPTAL_Php_Attribute_I18N_Target extends PHPTAL_Php_Attribute |
| 39 | 39 | { |
| 40 | - public function before(PHPTAL_Php_CodeWriter $codewriter){} |
|
| 41 | - public function after(PHPTAL_Php_CodeWriter $codewriter){} |
|
| 40 | + public function before(PHPTAL_Php_CodeWriter $codewriter) {} |
|
| 41 | + public function after(PHPTAL_Php_CodeWriter $codewriter) {} |
|
| 42 | 42 | } |
| 43 | 43 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $code = $this->_getTranslationCode($codewriter, $attr->getValue()); |
| 81 | 81 | } elseif ($attr->getReplacedState() === PHPTAL_Dom_Attr::VALUE_REPLACED && $attr->getOverwrittenVariableName()) { |
| 82 | 82 | // sadly variables won't be interpolated in this translation |
| 83 | - $code = 'echo '.$codewriter->escapeCode($codewriter->getTranslatorReference(). '->translate('.$attr->getOverwrittenVariableName().', false)'); |
|
| 83 | + $code = 'echo '.$codewriter->escapeCode($codewriter->getTranslatorReference().'->translate('.$attr->getOverwrittenVariableName().', false)'); |
|
| 84 | 84 | } else { |
| 85 | 85 | throw new PHPTAL_TemplateException("Unable to translate attribute $qname, because other TAL attributes are using it", |
| 86 | 86 | $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | array_shift($m); |
| 105 | 105 | $m = array_shift($m); |
| 106 | 106 | foreach ($m as $name) { |
| 107 | - $code .= "\n".$codewriter->getTranslatorReference(). '->setVar('.$codewriter->str($name).','.PHPTAL_Php_TalesInternal::compileToPHPExpression($name).');'; // allow more complex TAL expressions |
|
| 107 | + $code .= "\n".$codewriter->getTranslatorReference().'->setVar('.$codewriter->str($name).','.PHPTAL_Php_TalesInternal::compileToPHPExpression($name).');'; // allow more complex TAL expressions |
|
| 108 | 108 | } |
| 109 | 109 | $code .= "\n"; |
| 110 | 110 | } |
@@ -73,8 +73,10 @@ |
||
| 73 | 73 | $code = $this->_getTranslationCode($codewriter, $key); |
| 74 | 74 | } else { |
| 75 | 75 | $attr = $this->phpelement->getAttributeNode($qname); |
| 76 | - if (!$attr) throw new PHPTAL_TemplateException("Unable to translate attribute $qname, because there is no translation key specified", |
|
| 76 | + if (!$attr) { |
|
| 77 | + throw new PHPTAL_TemplateException("Unable to translate attribute $qname, because there is no translation key specified", |
|
| 77 | 78 | $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
| 79 | + } |
|
| 78 | 80 | |
| 79 | 81 | if ($attr->getReplacedState() === PHPTAL_Dom_Attr::NOT_REPLACED) { |
| 80 | 82 | $code = $this->_getTranslationCode($codewriter, $attr->getValue()); |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | $escape = true; |
| 35 | 35 | $this->_echoType = PHPTAL_Php_Attribute::ECHO_TEXT; |
| 36 | 36 | if (preg_match('/^(text|structure)(?:\s+(.*)|\s*$)/', $this->expression, $m)) { |
| 37 | - if ($m[1]=='structure') { $escape=false; $this->_echoType = PHPTAL_Php_Attribute::ECHO_STRUCTURE; } |
|
| 38 | - $this->expression = isset($m[2])?$m[2]:''; |
|
| 37 | + if ($m[1] == 'structure') { $escape = false; $this->_echoType = PHPTAL_Php_Attribute::ECHO_STRUCTURE; } |
|
| 38 | + $this->expression = isset($m[2]) ? $m[2] : ''; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $this->_prepareNames($codewriter, $this->phpelement); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | // a translation key |
| 45 | 45 | if (strlen(trim($this->expression)) == 0) { |
| 46 | 46 | $key = $this->_getTranslationKey($this->phpelement, !$escape, $codewriter->getEncoding()); |
| 47 | - $key = trim(preg_replace('/\s+/sm'.($codewriter->getEncoding()=='UTF-8'?'u':''), ' ', $key)); |
|
| 47 | + $key = trim(preg_replace('/\s+/sm'.($codewriter->getEncoding() == 'UTF-8' ? 'u' : ''), ' ', $key)); |
|
| 48 | 48 | if ('' === trim($key)) { |
| 49 | 49 | throw new PHPTAL_TemplateException("Empty translation key", |
| 50 | 50 | $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $code = $codewriter->evaluateExpression($this->expression); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $codewriter->pushCode('echo '.$codewriter->getTranslatorReference().'->translate('.$code.','.($escape ? 'true':'false').');'); |
|
| 61 | + $codewriter->pushCode('echo '.$codewriter->getTranslatorReference().'->translate('.$code.','.($escape ? 'true' : 'false').');'); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function after(PHPTAL_Php_CodeWriter $codewriter) |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $codewriter = $executor->getCodeWriter(); |
| 71 | 71 | |
| 72 | 72 | $escape = !($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE); |
| 73 | - $exp = $codewriter->getTranslatorReference()."->translate($exp, " . ($escape ? 'true':'false') . ')'; |
|
| 73 | + $exp = $codewriter->getTranslatorReference()."->translate($exp, ".($escape ? 'true' : 'false').')'; |
|
| 74 | 74 | if (!$islast) { |
| 75 | 75 | $var = $codewriter->createTempVariable(); |
| 76 | 76 | $executor->doIf('!phptal_isempty('.$var.' = '.$exp.')'); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | } elseif ($child instanceof PHPTAL_Dom_Element) { |
| 96 | 96 | if ($attr = $child->getAttributeNodeNS('http://xml.zope.org/namespaces/i18n', 'name')) { |
| 97 | - $result .= '${' . $attr->getValue() . '}'; |
|
| 97 | + $result .= '${'.$attr->getValue().'}'; |
|
| 98 | 98 | } else { |
| 99 | 99 | |
| 100 | 100 | if ($preserve_tags) { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $result .= ' '.$attr->getQualifiedName().'="'.$attr->getValueEscaped().'"'; |
| 106 | 106 | } |
| 107 | - $result .= '>'.$this->_getTranslationKey($child, $preserve_tags, $encoding) . '</'.$child->getQualifiedName().'>'; |
|
| 107 | + $result .= '>'.$this->_getTranslationKey($child, $preserve_tags, $encoding).'</'.$child->getQualifiedName().'>'; |
|
| 108 | 108 | } else { |
| 109 | 109 | $result .= $this->_getTranslationKey($child, $preserve_tags, $encoding); |
| 110 | 110 | } |
@@ -52,8 +52,9 @@ discard block |
||
| 52 | 52 | $code = $codewriter->str($key); |
| 53 | 53 | } else { |
| 54 | 54 | $code = $codewriter->evaluateExpression($this->expression); |
| 55 | - if (is_array($code)) |
|
| 56 | - return $this->generateChainedContent($codewriter, $code); |
|
| 55 | + if (is_array($code)) { |
|
| 56 | + return $this->generateChainedContent($codewriter, $code); |
|
| 57 | + } |
|
| 57 | 58 | |
| 58 | 59 | $code = $codewriter->evaluateExpression($this->expression); |
| 59 | 60 | } |
@@ -100,7 +101,9 @@ discard block |
||
| 100 | 101 | if ($preserve_tags) { |
| 101 | 102 | $result .= '<'.$child->getQualifiedName(); |
| 102 | 103 | foreach ($child->getAttributeNodes() as $attr) { |
| 103 | - if ($attr->getReplacedState() === PHPTAL_Dom_Attr::HIDDEN) continue; |
|
| 104 | + if ($attr->getReplacedState() === PHPTAL_Dom_Attr::HIDDEN) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 104 | 107 | |
| 105 | 108 | $result .= ' '.$attr->getQualifiedName().'="'.$attr->getValueEscaped().'"'; |
| 106 | 109 | } |