@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @param string $path Template file path. |
| 177 | 177 | */ |
| 178 | - public function __construct($path=false) |
|
| 178 | + public function __construct($path = false) |
|
| 179 | 179 | { |
| 180 | 180 | $this->_path = $path; |
| 181 | 181 | $this->_globalContext = new stdClass(); |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @return PHPTAL |
| 205 | 205 | */ |
| 206 | - public static function create($path=false) |
|
| 206 | + public static function create($path = false) |
|
| 207 | 207 | { |
| 208 | 208 | return new PHPTAL($path); |
| 209 | 209 | } |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | */ |
| 409 | 409 | public function setPhpCodeDestination($path) |
| 410 | 410 | { |
| 411 | - $this->_phpCodeDestination = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 411 | + $this->_phpCodeDestination = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
| 412 | 412 | $this->resetPrepared(); |
| 413 | 413 | return $this; |
| 414 | 414 | } |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | private function getPreFiltersCacheId() |
| 549 | 549 | { |
| 550 | 550 | $cacheid = ''; |
| 551 | - foreach($this->getPreFilters() as $key => $prefilter) { |
|
| 551 | + foreach ($this->getPreFilters() as $key => $prefilter) { |
|
| 552 | 552 | if ($prefilter instanceof PHPTAL_PreFilter) { |
| 553 | 553 | $cacheid .= $key.$prefilter->getCacheId(); |
| 554 | 554 | } elseif ($prefilter instanceof PHPTAL_Filter) { |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | { |
| 570 | 570 | $prefilters = $this->getPreFilters(); |
| 571 | 571 | |
| 572 | - foreach($prefilters as $prefilter) { |
|
| 572 | + foreach ($prefilters as $prefilter) { |
|
| 573 | 573 | if ($prefilter instanceof PHPTAL_PreFilter) { |
| 574 | 574 | $prefilter->setPHPTAL($this); |
| 575 | 575 | } |
@@ -675,12 +675,12 @@ discard block |
||
| 675 | 675 | |
| 676 | 676 | // unshift doctype |
| 677 | 677 | if ($this->_context->_docType) { |
| 678 | - $res = $this->_context->_docType . $res; |
|
| 678 | + $res = $this->_context->_docType.$res; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | // unshift xml declaration |
| 682 | 682 | if ($this->_context->_xmlDeclaration) { |
| 683 | - $res = $this->_context->_xmlDeclaration . "\n" . $res; |
|
| 683 | + $res = $this->_context->_xmlDeclaration."\n".$res; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | if ($this->_postfilter) { |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | $this->externalMacroTemplatesCache[$file] = $tpl; |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | - $fun = $tpl->getFunctionName() . '_' . strtr($macroName, "-", "_"); |
|
| 771 | + $fun = $tpl->getFunctionName().'_'.strtr($macroName, "-", "_"); |
|
| 772 | 772 | if (!function_exists($fun)) { |
| 773 | 773 | throw new PHPTAL_MacroMissingException("Macro '$macroName' is not defined in $file", $this->_source->getRealPath()); |
| 774 | 774 | } |
@@ -777,11 +777,11 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | } else { |
| 779 | 779 | // call local macro |
| 780 | - $fun = $local_tpl->getFunctionName() . '_' . strtr($path, "-", "_"); |
|
| 780 | + $fun = $local_tpl->getFunctionName().'_'.strtr($path, "-", "_"); |
|
| 781 | 781 | if (!function_exists($fun)) { |
| 782 | 782 | throw new PHPTAL_MacroMissingException("Macro '$path' is not defined", $local_tpl->_source->getRealPath()); |
| 783 | 783 | } |
| 784 | - $fun( $local_tpl, $this); |
|
| 784 | + $fun($local_tpl, $this); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | private function setCodeFile() |
| 792 | 792 | { |
| 793 | 793 | $this->findTemplate(); |
| 794 | - $this->_codeFile = $this->getPhpCodeDestination() . $this->getFunctionName() . '.' . $this->getPhpCodeExtension(); |
|
| 794 | + $this->_codeFile = $this->getPhpCodeDestination().$this->getFunctionName().'.'.$this->getPhpCodeExtension(); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | protected function resetPrepared() |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | |
| 820 | 820 | // i'm not sure where that belongs, but not in normal path of execution |
| 821 | 821 | // because some sites have _a lot_ of files in temp |
| 822 | - if ($this->getCachePurgeFrequency() && mt_rand()%$this->getCachePurgeFrequency() == 0) { |
|
| 822 | + if ($this->getCachePurgeFrequency() && mt_rand() % $this->getCachePurgeFrequency() == 0) { |
|
| 823 | 823 | $this->cleanUpGarbage(); |
| 824 | 824 | } |
| 825 | 825 | |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | try { |
| 837 | 837 | eval("?>\n".$result); |
| 838 | 838 | } |
| 839 | - catch(Exception $e) { |
|
| 839 | + catch (Exception $e) { |
|
| 840 | 840 | ob_end_clean(); |
| 841 | 841 | throw $e; |
| 842 | 842 | } |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | $msg = str_replace('eval()\'d code', $this->getCodePath(), ob_get_clean()); |
| 846 | 846 | |
| 847 | 847 | // greedy .* ensures last match |
| 848 | - if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line=$m[1]; else $line=0; |
|
| 848 | + if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line = $m[1]; else $line = 0; |
|
| 849 | 849 | throw new PHPTAL_TemplateException(trim($msg), $this->getCodePath(), $line); |
| 850 | 850 | } |
| 851 | 851 | ob_end_clean(); |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | */ |
| 887 | 887 | public function setCachePurgeFrequency($n) |
| 888 | 888 | { |
| 889 | - $this->_cachePurgeFrequency = (int)$n; |
|
| 889 | + $this->_cachePurgeFrequency = (int) $n; |
|
| 890 | 890 | return $this; |
| 891 | 891 | } |
| 892 | 892 | |
@@ -906,14 +906,14 @@ discard block |
||
| 906 | 906 | */ |
| 907 | 907 | public function cleanUpGarbage() |
| 908 | 908 | { |
| 909 | - $cacheFilesExpire = time() - $this->getCacheLifetime() * 3600 * 24; |
|
| 909 | + $cacheFilesExpire = time()-$this->getCacheLifetime() * 3600 * 24; |
|
| 910 | 910 | |
| 911 | 911 | // relies on templates sorting order being related to their modification dates |
| 912 | - $upperLimit = $this->getPhpCodeDestination() . $this->getFunctionNamePrefix($cacheFilesExpire) . '_'; |
|
| 913 | - $lowerLimit = $this->getPhpCodeDestination() . $this->getFunctionNamePrefix(0); |
|
| 912 | + $upperLimit = $this->getPhpCodeDestination().$this->getFunctionNamePrefix($cacheFilesExpire).'_'; |
|
| 913 | + $lowerLimit = $this->getPhpCodeDestination().$this->getFunctionNamePrefix(0); |
|
| 914 | 914 | |
| 915 | 915 | // second * gets phptal:cache |
| 916 | - $cacheFiles = glob($this->getPhpCodeDestination() . 'tpl_????????_*.' . $this->getPhpCodeExtension() . '*'); |
|
| 916 | + $cacheFiles = glob($this->getPhpCodeDestination().'tpl_????????_*.'.$this->getPhpCodeExtension().'*'); |
|
| 917 | 917 | |
| 918 | 918 | if ($cacheFiles) { |
| 919 | 919 | foreach ($cacheFiles as $index => $file) { |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | public function cleanUpCache() |
| 937 | 937 | { |
| 938 | 938 | $filename = $this->getCodePath(); |
| 939 | - $cacheFiles = glob($filename . '?*'); |
|
| 939 | + $cacheFiles = glob($filename.'?*'); |
|
| 940 | 940 | if ($cacheFiles) { |
| 941 | 941 | foreach ($cacheFiles as $file) { |
| 942 | 942 | if (substr($file, 0, strlen($filename)) !== $filename) continue; // safety net |
@@ -975,7 +975,7 @@ discard block |
||
| 975 | 975 | $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath())); |
| 976 | 976 | $basename = substr(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $basename), "_"), 0, 20); |
| 977 | 977 | |
| 978 | - $hash = md5(PHPTAL_VERSION . PHP_VERSION |
|
| 978 | + $hash = md5(PHPTAL_VERSION.PHP_VERSION |
|
| 979 | 979 | . $this->_source->getRealPath() |
| 980 | 980 | . $this->getEncoding() |
| 981 | 981 | . $this->getPrefiltersCacheId() |
@@ -986,10 +986,10 @@ discard block |
||
| 986 | 986 | // uses base64 rather than hex to make filename shorter. |
| 987 | 987 | // there is loss of some bits due to name constraints and case-insensivity, |
| 988 | 988 | // but that's still over 110 bits in addition to basename and timestamp. |
| 989 | - $hash = strtr(rtrim(base64_encode($hash),"="),"+/=","_A_"); |
|
| 989 | + $hash = strtr(rtrim(base64_encode($hash), "="), "+/=", "_A_"); |
|
| 990 | 990 | |
| 991 | - $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()) . |
|
| 992 | - $basename . '__' . $hash; |
|
| 991 | + $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()). |
|
| 992 | + $basename.'__'.$hash; |
|
| 993 | 993 | } |
| 994 | 994 | return $this->_functionName; |
| 995 | 995 | } |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | { |
| 1007 | 1007 | // tpl_ prefix and last modified time must not be changed, |
| 1008 | 1008 | // because cache cleanup relies on that |
| 1009 | - return 'tpl_' . sprintf("%08x", $timestamp) .'_'; |
|
| 1009 | + return 'tpl_'.sprintf("%08x", $timestamp).'_'; |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | /** |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | */ |
| 1037 | 1037 | public function addError(Exception $error) |
| 1038 | 1038 | { |
| 1039 | - $this->_errors[] = $error; |
|
| 1039 | + $this->_errors[] = $error; |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1092,7 +1092,7 @@ discard block |
||
| 1092 | 1092 | $data = $this->_source->getData(); |
| 1093 | 1093 | |
| 1094 | 1094 | $prefilters = $this->getPreFilterInstances(); |
| 1095 | - foreach($prefilters as $prefilter) { |
|
| 1095 | + foreach ($prefilters as $prefilter) { |
|
| 1096 | 1096 | $data = $prefilter->filter($data); |
| 1097 | 1097 | } |
| 1098 | 1098 | |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | $builder = new PHPTAL_Dom_PHPTALDocumentBuilder(); |
| 1103 | 1103 | $tree = $parser->parseString($builder, $data, $realpath)->getResult(); |
| 1104 | 1104 | |
| 1105 | - foreach($prefilters as $prefilter) { |
|
| 1105 | + foreach ($prefilters as $prefilter) { |
|
| 1106 | 1106 | if ($prefilter instanceof PHPTAL_PreFilter) { |
| 1107 | 1107 | if ($prefilter->filterDOM($tree) !== NULL) { |
| 1108 | 1108 | throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()"); |
@@ -1189,7 +1189,7 @@ discard block |
||
| 1189 | 1189 | |
| 1190 | 1190 | if (substr($class, 0, 7) !== 'PHPTAL_') return; |
| 1191 | 1191 | |
| 1192 | - $path = dirname(__FILE__) . strtr("_".$class, "_", DIRECTORY_SEPARATOR) . '.php'; |
|
| 1192 | + $path = dirname(__FILE__).strtr("_".$class, "_", DIRECTORY_SEPARATOR).'.php'; |
|
| 1193 | 1193 | |
| 1194 | 1194 | require $path; |
| 1195 | 1195 | } |
@@ -1214,9 +1214,9 @@ discard block |
||
| 1214 | 1214 | // Prepending PHPTAL's autoloader helps if there are other autoloaders |
| 1215 | 1215 | // that throw/die when file is not found. Only >5.3 though. |
| 1216 | 1216 | if (version_compare(PHP_VERSION, '5.3', '>=')) { |
| 1217 | - spl_autoload_register(array(__CLASS__,'autoload'), false, true); |
|
| 1217 | + spl_autoload_register(array(__CLASS__, 'autoload'), false, true); |
|
| 1218 | 1218 | } else { |
| 1219 | - spl_autoload_register(array(__CLASS__,'autoload')); |
|
| 1219 | + spl_autoload_register(array(__CLASS__, 'autoload')); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | if ($uses_autoload) { |
@@ -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(Exception $e) { |
|
| 837 | + } catch(Exception $e) { |
|
| 840 | 838 | ob_end_clean(); |
| 841 | 839 | throw $e; |
| 842 | 840 | } |
@@ -845,7 +843,11 @@ discard block |
||
| 845 | 843 | $msg = str_replace('eval()\'d code', $this->getCodePath(), ob_get_clean()); |
| 846 | 844 | |
| 847 | 845 | // greedy .* ensures last match |
| 848 | - if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line=$m[1]; else $line=0; |
|
| 846 | + if (preg_match('/.*on line (\d+)$/m', $msg, $m)) { |
|
| 847 | + $line=$m[1]; |
|
| 848 | + } else { |
|
| 849 | + $line=0; |
|
| 850 | + } |
|
| 849 | 851 | throw new PHPTAL_TemplateException(trim($msg), $this->getCodePath(), $line); |
| 850 | 852 | } |
| 851 | 853 | ob_end_clean(); |
@@ -939,7 +941,10 @@ discard block |
||
| 939 | 941 | $cacheFiles = glob($filename . '?*'); |
| 940 | 942 | if ($cacheFiles) { |
| 941 | 943 | foreach ($cacheFiles as $file) { |
| 942 | - if (substr($file, 0, strlen($filename)) !== $filename) continue; // safety net |
|
| 944 | + if (substr($file, 0, strlen($filename)) !== $filename) { |
|
| 945 | + continue; |
|
| 946 | + } |
|
| 947 | + // safety net |
|
| 943 | 948 | @unlink($file); |
| 944 | 949 | } |
| 945 | 950 | } |
@@ -956,7 +961,9 @@ discard block |
||
| 956 | 961 | */ |
| 957 | 962 | public function getCodePath() |
| 958 | 963 | { |
| 959 | - if (!$this->_codeFile) $this->setCodeFile(); |
|
| 964 | + if (!$this->_codeFile) { |
|
| 965 | + $this->setCodeFile(); |
|
| 966 | + } |
|
| 960 | 967 | return $this->_codeFile; |
| 961 | 968 | } |
| 962 | 969 | |
@@ -1187,7 +1194,9 @@ discard block |
||
| 1187 | 1194 | $class = strtr($class, '\\', '_'); |
| 1188 | 1195 | } |
| 1189 | 1196 | |
| 1190 | - if (substr($class, 0, 7) !== 'PHPTAL_') return; |
|
| 1197 | + if (substr($class, 0, 7) !== 'PHPTAL_') { |
|
| 1198 | + return; |
|
| 1199 | + } |
|
| 1191 | 1200 | |
| 1192 | 1201 | $path = dirname(__FILE__) . strtr("_".$class, "_", DIRECTORY_SEPARATOR) . '.php'; |
| 1193 | 1202 | |
@@ -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 | } |
@@ -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) |
@@ -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 | |