@@ -966,10 +966,10 @@ discard block |
||
| 966 | 966 | */ |
| 967 | 967 | public function getFunctionName() |
| 968 | 968 | { |
| 969 | - // function name is used as base for caching, so it must be unique for |
|
| 970 | - // every combination of settings that changes code in compiled template |
|
| 969 | + // function name is used as base for caching, so it must be unique for |
|
| 970 | + // every combination of settings that changes code in compiled template |
|
| 971 | 971 | |
| 972 | - if (!$this->_functionName) { |
|
| 972 | + if (!$this->_functionName) { |
|
| 973 | 973 | |
| 974 | 974 | // just to make tempalte name recognizable |
| 975 | 975 | $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath())); |
@@ -989,7 +989,7 @@ discard block |
||
| 989 | 989 | $hash = strtr(rtrim(base64_encode($hash),"="),"+/=","_A_"); |
| 990 | 990 | |
| 991 | 991 | $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()) . |
| 992 | - $basename . '__' . $hash; |
|
| 992 | + $basename . '__' . $hash; |
|
| 993 | 993 | } |
| 994 | 994 | return $this->_functionName; |
| 995 | 995 | } |
@@ -379,7 +379,9 @@ discard block |
||
| 379 | 379 | $enc = strtoupper($enc); |
| 380 | 380 | if ($enc != $this->_encoding) { |
| 381 | 381 | $this->_encoding = $enc; |
| 382 | - if ($this->_translator) $this->_translator->setEncoding($enc); |
|
| 382 | + if ($this->_translator) { |
|
| 383 | + $this->_translator->setEncoding($enc); |
|
| 384 | + } |
|
| 383 | 385 | |
| 384 | 386 | $this->resetPrepared(); |
| 385 | 387 | } |
@@ -666,8 +668,7 @@ discard block |
||
| 666 | 668 | ob_start(); |
| 667 | 669 | $templateFunction($this, $this->_context); |
| 668 | 670 | $res = ob_get_clean(); |
| 669 | - } |
|
| 670 | - catch (Exception $e) |
|
| 671 | + } catch (Exception $e) |
|
| 671 | 672 | { |
| 672 | 673 | ob_end_clean(); |
| 673 | 674 | throw $e; |
@@ -686,8 +687,7 @@ discard block |
||
| 686 | 687 | if ($this->_postfilter) { |
| 687 | 688 | return $this->_postfilter->filter($res); |
| 688 | 689 | } |
| 689 | - } |
|
| 690 | - catch (Exception $e) |
|
| 690 | + } catch (Exception $e) |
|
| 691 | 691 | { |
| 692 | 692 | PHPTAL_ExceptionHandler::handleException($e, $this->getEncoding()); |
| 693 | 693 | } |
@@ -717,8 +717,7 @@ discard block |
||
| 717 | 717 | |
| 718 | 718 | $templateFunction = $this->getFunctionName(); |
| 719 | 719 | $templateFunction($this, $this->_context); |
| 720 | - } |
|
| 721 | - catch (Exception $e) |
|
| 720 | + } catch (Exception $e) |
|
| 722 | 721 | { |
| 723 | 722 | PHPTAL_ExceptionHandler::handleException($e, $this->getEncoding()); |
| 724 | 723 | } |
@@ -835,8 +834,7 @@ discard block |
||
| 835 | 834 | ob_start(); |
| 836 | 835 | try { |
| 837 | 836 | eval("?>\n".$result); |
| 838 | - } |
|
| 839 | - catch(ParseError $parseError) { |
|
| 837 | + } catch(ParseError $parseError) { |
|
| 840 | 838 | ob_end_clean(); |
| 841 | 839 | throw new PHPTAL_TemplateException( |
| 842 | 840 | 'Parse error: ' . $parseError->getMessage(), |
@@ -844,8 +842,7 @@ discard block |
||
| 844 | 842 | $parseError->getLine(), |
| 845 | 843 | $parseError |
| 846 | 844 | ); |
| 847 | - } |
|
| 848 | - catch(Exception $e) { |
|
| 845 | + } catch(Exception $e) { |
|
| 849 | 846 | ob_end_clean(); |
| 850 | 847 | throw $e; |
| 851 | 848 | } |
@@ -854,7 +851,11 @@ discard block |
||
| 854 | 851 | $msg = str_replace('eval()\'d code', $this->getCodePath(), ob_get_clean()); |
| 855 | 852 | |
| 856 | 853 | // greedy .* ensures last match |
| 857 | - if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line=$m[1]; else $line=0; |
|
| 854 | + if (preg_match('/.*on line (\d+)$/m', $msg, $m)) { |
|
| 855 | + $line=$m[1]; |
|
| 856 | + } else { |
|
| 857 | + $line=0; |
|
| 858 | + } |
|
| 858 | 859 | throw new PHPTAL_TemplateException(trim($msg), $this->getCodePath(), $line); |
| 859 | 860 | } |
| 860 | 861 | ob_end_clean(); |
@@ -948,7 +949,10 @@ discard block |
||
| 948 | 949 | $cacheFiles = glob($filename . '?*'); |
| 949 | 950 | if ($cacheFiles) { |
| 950 | 951 | foreach ($cacheFiles as $file) { |
| 951 | - if (substr($file, 0, strlen($filename)) !== $filename) continue; // safety net |
|
| 952 | + if (substr($file, 0, strlen($filename)) !== $filename) { |
|
| 953 | + continue; |
|
| 954 | + } |
|
| 955 | + // safety net |
|
| 952 | 956 | @unlink($file); |
| 953 | 957 | } |
| 954 | 958 | } |
@@ -965,7 +969,9 @@ discard block |
||
| 965 | 969 | */ |
| 966 | 970 | public function getCodePath() |
| 967 | 971 | { |
| 968 | - if (!$this->_codeFile) $this->setCodeFile(); |
|
| 972 | + if (!$this->_codeFile) { |
|
| 973 | + $this->setCodeFile(); |
|
| 974 | + } |
|
| 969 | 975 | return $this->_codeFile; |
| 970 | 976 | } |
| 971 | 977 | |
@@ -1196,7 +1202,9 @@ discard block |
||
| 1196 | 1202 | $class = strtr($class, '\\', '_'); |
| 1197 | 1203 | } |
| 1198 | 1204 | |
| 1199 | - if (substr($class, 0, 7) !== 'PHPTAL_') return; |
|
| 1205 | + if (substr($class, 0, 7) !== 'PHPTAL_') { |
|
| 1206 | + return; |
|
| 1207 | + } |
|
| 1200 | 1208 | |
| 1201 | 1209 | $path = dirname(__FILE__) . strtr("_".$class, "_", DIRECTORY_SEPARATOR) . '.php'; |
| 1202 | 1210 | |
@@ -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 | } |
@@ -76,10 +76,11 @@ |
||
| 76 | 76 | |
| 77 | 77 | protected function doEchoAttribute(PHPTAL_Php_CodeWriter $codewriter, $code) |
| 78 | 78 | { |
| 79 | - if ($this->_echoType === self::ECHO_TEXT) |
|
| 80 | - $codewriter->doEcho($code); |
|
| 81 | - else |
|
| 82 | - $codewriter->doEchoRaw($code); |
|
| 79 | + if ($this->_echoType === self::ECHO_TEXT) { |
|
| 80 | + $codewriter->doEcho($code); |
|
| 81 | + } else { |
|
| 82 | + $codewriter->doEchoRaw($code); |
|
| 83 | + } |
|
| 83 | 84 | } |
| 84 | 85 | |
| 85 | 86 | protected function parseSetExpression($exp) |
@@ -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 | |
@@ -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 | |
@@ -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()); |
@@ -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 | } |
@@ -52,14 +52,14 @@ |
||
| 52 | 52 | |
| 53 | 53 | $macroname = strtr($this->expression, '-', '_'); |
| 54 | 54 | |
| 55 | - // throw error if attempting to define and use macro at same time |
|
| 56 | - // [should perhaps be a TemplateException? but I don't know how to set that up...] |
|
| 57 | - if ($defineAttr = $this->phpelement->getAttributeNodeNS( |
|
| 58 | - 'http://xml.zope.org/namespaces/metal', 'define-macro')) { |
|
| 59 | - if ($defineAttr->getValue() == $macroname) |
|
| 60 | - throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'", |
|
| 61 | - $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 62 | - } |
|
| 55 | + // throw error if attempting to define and use macro at same time |
|
| 56 | + // [should perhaps be a TemplateException? but I don't know how to set that up...] |
|
| 57 | + if ($defineAttr = $this->phpelement->getAttributeNodeNS( |
|
| 58 | + 'http://xml.zope.org/namespaces/metal', 'define-macro')) { |
|
| 59 | + if ($defineAttr->getValue() == $macroname) |
|
| 60 | + throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'", |
|
| 61 | + $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | // local macro (no filename specified) and non dynamic macro name |
| 65 | 65 | // can be called directly if it's a known function (just generated or seen in previous compilation) |
@@ -56,9 +56,10 @@ |
||
| 56 | 56 | // [should perhaps be a TemplateException? but I don't know how to set that up...] |
| 57 | 57 | if ($defineAttr = $this->phpelement->getAttributeNodeNS( |
| 58 | 58 | 'http://xml.zope.org/namespaces/metal', 'define-macro')) { |
| 59 | - if ($defineAttr->getValue() == $macroname) |
|
| 60 | - throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'", |
|
| 61 | - $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 59 | + if ($defineAttr->getValue() == $macroname) { |
|
| 60 | + throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'", |
|
| 61 | + $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); |
|
| 62 | + } |
|
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | // local macro (no filename specified) and non dynamic macro name |