@@ -119,7 +119,9 @@ |
||
| 119 | 119 | */ |
| 120 | 120 | public function isValidAttributeNS($namespace_uri, $local_name) |
| 121 | 121 | { |
| 122 | - if (!$this->isHandledNamespace($namespace_uri)) return false; |
|
| 122 | + if (!$this->isHandledNamespace($namespace_uri)) { |
|
| 123 | + return false; |
|
| 124 | + } |
|
| 123 | 125 | |
| 124 | 126 | $attrs = $this->namespaces_by_uri[$namespace_uri]->getAttributes(); |
| 125 | 127 | return isset($attrs[$local_name]); |
@@ -76,7 +76,7 @@ |
||
| 76 | 76 | $prefix_to_uri[$prefix] = $value; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ($qname == 'xmlns') {$changed=true;$current_default = $value;} |
|
| 79 | + if ($qname == 'xmlns') {$changed = true; $current_default = $value; } |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if ($changed) { |
@@ -34,8 +34,12 @@ |
||
| 34 | 34 | |
| 35 | 35 | public function prefixToNamespaceURI($prefix) |
| 36 | 36 | { |
| 37 | - if ($prefix === 'xmlns') return 'http://www.w3.org/2000/xmlns/'; |
|
| 38 | - if ($prefix === 'xml') return 'http://www.w3.org/XML/1998/namespace'; |
|
| 37 | + if ($prefix === 'xmlns') { |
|
| 38 | + return 'http://www.w3.org/2000/xmlns/'; |
|
| 39 | + } |
|
| 40 | + if ($prefix === 'xml') { |
|
| 41 | + return 'http://www.w3.org/XML/1998/namespace'; |
|
| 42 | + } |
|
| 39 | 43 | |
| 40 | 44 | // domdefs provides fallback for all known phptal ns |
| 41 | 45 | if (isset($this->prefix_to_uri[$prefix])) { |
@@ -34,10 +34,12 @@ |
||
| 34 | 34 | $codewriter->pushHTML($codewriter->interpolateCDATA(str_replace('</', '<\/', $value))); |
| 35 | 35 | } elseif (($mode === PHPTAL::XHTML && $inCDATAelement) // safe for text/html |
| 36 | 36 | || ($mode === PHPTAL::XML && preg_match('/[<>&]/', $value)) // non-useless in XML |
| 37 | - || ($mode !== PHPTAL::HTML5 && preg_match('/<\?|\${structure/', $value))) // hacks with structure (in X[HT]ML) may need it |
|
| 37 | + || ($mode !== PHPTAL::HTML5 && preg_match('/<\?|\${structure/', $value))) { |
|
| 38 | + // hacks with structure (in X[HT]ML) may need it |
|
| 38 | 39 | { |
| 39 | 40 | // in text/html "</" is dangerous and the only sensible way to escape is ECMAScript string escapes. |
| 40 | 41 | if ($mode === PHPTAL::XHTML) $value = str_replace('</', '<\/', $value); |
| 42 | + } |
|
| 41 | 43 | |
| 42 | 44 | $codewriter->pushHTML($codewriter->interpolateCDATA('<![CDATA['.$value.']]>')); |
| 43 | 45 | } else { |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class PHPTAL_Dom_DocumentBuilder |
| 23 | 23 | { |
| 24 | - protected $_stack; /* array<PHPTAL_Dom_Node> */ |
|
| 24 | + protected $_stack; /* array<PHPTAL_Dom_Node> */ |
|
| 25 | 25 | protected $_current; /* PHPTAL_Dom_Node */ |
| 26 | 26 | |
| 27 | 27 | protected $file, $line; |
@@ -53,7 +53,9 @@ |
||
| 53 | 53 | { |
| 54 | 54 | if (count($this->_stack) > 0) { |
| 55 | 55 | $left='</'.$this->_current->getQualifiedName().'>'; |
| 56 | - for ($i = count($this->_stack)-1; $i>0; $i--) $left .= '</'.$this->_stack[$i]->getQualifiedName().'>'; |
|
| 56 | + for ($i = count($this->_stack)-1; $i>0; $i--) { |
|
| 57 | + $left .= '</'.$this->_stack[$i]->getQualifiedName().'>'; |
|
| 58 | + } |
|
| 57 | 59 | throw new PHPTAL_ParserException("Not all elements were closed before end of the document. Missing: ".$left, |
| 58 | 60 | $this->file, $this->line); |
| 59 | 61 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class PHPTAL_Dom_PHPTALDocumentBuilder extends PHPTAL_Dom_DocumentBuilder |
| 24 | 24 | { |
| 25 | - private $_xmlns; /* PHPTAL_Dom_XmlnsState */ |
|
| 25 | + private $_xmlns; /* PHPTAL_Dom_XmlnsState */ |
|
| 26 | 26 | private $encoding; |
| 27 | 27 | private ?PHPTAL_Dom_Element $documentElement = null; |
| 28 | 28 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | public function onDocumentEnd() |
| 54 | 54 | { |
| 55 | 55 | if (count($this->_stack) > 0) { |
| 56 | - $left='</'.$this->_current->getQualifiedName().'>'; |
|
| 57 | - for ($i = count($this->_stack)-1; $i>0; $i--) $left .= '</'.$this->_stack[$i]->getQualifiedName().'>'; |
|
| 56 | + $left = '</'.$this->_current->getQualifiedName().'>'; |
|
| 57 | + for ($i = count($this->_stack)-1; $i > 0; $i--) $left .= '</'.$this->_stack[$i]->getQualifiedName().'>'; |
|
| 58 | 58 | throw new PHPTAL_ParserException("Not all elements were closed before end of the document. Missing: ".$left, |
| 59 | 59 | $this->file, $this->line); |
| 60 | 60 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | $node = new PHPTAL_Dom_Element($element_qname, $namespace_uri, $attrnodes, $this->getXmlnsState()); |
| 132 | 132 | $this->pushNode($node); |
| 133 | - $this->_stack[] = $this->_current; |
|
| 133 | + $this->_stack[] = $this->_current; |
|
| 134 | 134 | $this->_current = $node; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * Encoding must be set before calling addDomain! |
| 105 | 105 | */ |
| 106 | - public function addDomain($domain, $path='./locale/') |
|
| 106 | + public function addDomain($domain, $path = './locale/') |
|
| 107 | 107 | { |
| 108 | 108 | bindtextdomain($domain, $path); |
| 109 | 109 | if ($this->_encoding) { |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @param bool $htmlencode if true, output will be HTML-escaped. |
| 142 | 142 | */ |
| 143 | - public function translate($key, $htmlencode=true) |
|
| 143 | + public function translate($key, $htmlencode = true) |
|
| 144 | 144 | { |
| 145 | 145 | if ($this->_canonicalize) $key = self::_canonicalizeKey($key); |
| 146 | 146 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $key_ = trim($key_); |
| 169 | 169 | $key_ = str_replace("\n", "", $key_); |
| 170 | 170 | $key_ = str_replace("\r", "", $key_); |
| 171 | - for ($i = 0; $i<strlen($key_); $i++) { |
|
| 171 | + for ($i = 0; $i < strlen($key_); $i++) { |
|
| 172 | 172 | $c = $key_[$i]; |
| 173 | 173 | $o = ord($c); |
| 174 | 174 | if ($o < 5 || $o > 127) { |
@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function __construct() |
| 36 | 36 | { |
| 37 | - if (!function_exists('gettext')) throw new PHPTAL_ConfigurationException("Gettext not installed"); |
|
| 37 | + if (!function_exists('gettext')) { |
|
| 38 | + throw new PHPTAL_ConfigurationException("Gettext not installed"); |
|
| 39 | + } |
|
| 38 | 40 | $this->useDomain("messages"); // PHP bug #21965 |
| 39 | 41 | } |
| 40 | 42 | |
@@ -75,11 +77,15 @@ discard block |
||
| 75 | 77 | $langs = func_get_args(); |
| 76 | 78 | |
| 77 | 79 | $langCode = $this->trySettingLanguages(LC_ALL, $langs); |
| 78 | - if ($langCode) return $langCode; |
|
| 80 | + if ($langCode) { |
|
| 81 | + return $langCode; |
|
| 82 | + } |
|
| 79 | 83 | |
| 80 | 84 | if (defined("LC_MESSAGES")) { |
| 81 | 85 | $langCode = $this->trySettingLanguages(LC_MESSAGES, $langs); |
| 82 | - if ($langCode) return $langCode; |
|
| 86 | + if ($langCode) { |
|
| 87 | + return $langCode; |
|
| 88 | + } |
|
| 83 | 89 | } |
| 84 | 90 | |
| 85 | 91 | throw new PHPTAL_ConfigurationException('Language(s) code(s) "'.implode(', ', $langs).'" not supported by your system'); |
@@ -142,7 +148,9 @@ discard block |
||
| 142 | 148 | */ |
| 143 | 149 | public function translate($key, $htmlencode=true) |
| 144 | 150 | { |
| 145 | - if ($this->_canonicalize) $key = self::_canonicalizeKey($key); |
|
| 151 | + if ($this->_canonicalize) { |
|
| 152 | + $key = self::_canonicalizeKey($key); |
|
| 153 | + } |
|
| 146 | 154 | |
| 147 | 155 | $value = gettext($key); |
| 148 | 156 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | try |
| 29 | 29 | { |
| 30 | - if (! empty($_SERVER['REQUEST_URI'])) { |
|
| 30 | + if (!empty($_SERVER['REQUEST_URI'])) { |
|
| 31 | 31 | throw new Exception("Please use this tool from command line"); |
| 32 | 32 | } |
| 33 | 33 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | echo " Skipped ".$this->plural($lint->skipped, "non-template file")."."; |
| 77 | 77 | } |
| 78 | 78 | echo "\n"; |
| 79 | - if (! $custom_extensions && count($lint->skipped_filenames)) { |
|
| 79 | + if (!$custom_extensions && count($lint->skipped_filenames)) { |
|
| 80 | 80 | echo "Skipped file(s): ", implode(', ', array_keys($lint->skipped_filenames)), ".\n"; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | echo "\n"; |
| 87 | 87 | exit(2); |
| 88 | 88 | } else if (count($lint->warnings)) { |
| 89 | - echo "Found ".$this->plural(count($lint->warnings),"warning").":\n"; |
|
| 89 | + echo "Found ".$this->plural(count($lint->warnings), "warning").":\n"; |
|
| 90 | 90 | $this->display_erorr_array($lint->warnings); |
| 91 | 91 | echo "\n"; |
| 92 | 92 | exit(0); |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | exit($lint->checked ? 0 : 1); |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - catch(Exception $e) { |
|
| 99 | - fwrite(STDERR, $e->getMessage() . "\n"); |
|
| 98 | + catch (Exception $e) { |
|
| 99 | + fwrite(STDERR, $e->getMessage()."\n"); |
|
| 100 | 100 | $errcode = $e->getCode(); |
| 101 | 101 | exit($errcode ? $errcode : 1); |
| 102 | 102 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | function usage() |
| 120 | 120 | { |
| 121 | 121 | $this->require_phptal(); |
| 122 | - echo "PHPTAL Lint 1.1.3 (PHPTAL ", strtr(PHPTAL_VERSION,"_","."), ")\n"; |
|
| 122 | + echo "PHPTAL Lint 1.1.3 (PHPTAL ", strtr(PHPTAL_VERSION, "_", "."), ")\n"; |
|
| 123 | 123 | |
| 124 | 124 | echo "Usage: phptal_lint.php [-e extensions] [-i php_file_or_directory] file_or_directory_to_check ...\n"; |
| 125 | 125 | echo " -e comma-separated list of extensions\n"; |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | function extended_getopt(array $options) |
| 137 | 137 | { |
| 138 | 138 | $results = array('--filenames--'=>array()); |
| 139 | - for ($i = 1; $i < count($_SERVER['argv']); $i ++) { |
|
| 139 | + for ($i = 1; $i < count($_SERVER['argv']); $i++) { |
|
| 140 | 140 | if (in_array($_SERVER['argv'][$i], $options)) { |
| 141 | - $results[substr($_SERVER['argv'][$i], 1)][] = $_SERVER['argv'][++ $i]; |
|
| 141 | + $results[substr($_SERVER['argv'][$i], 1)][] = $_SERVER['argv'][++$i]; |
|
| 142 | 142 | } else if ($_SERVER['argv'][$i] == '--') { |
| 143 | - $results['--filenames--'] = array_merge($results['--filenames--'], array_slice($_SERVER['argv'],$i+1)); |
|
| 143 | + $results['--filenames--'] = array_merge($results['--filenames--'], array_slice($_SERVER['argv'], $i+1)); |
|
| 144 | 144 | break; |
| 145 | 145 | } else if (substr($_SERVER['argv'][$i], 0, 1) == '-') { |
| 146 | 146 | $this->usage(); |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | { |
| 172 | 172 | if (class_exists('PHPTAL', false)) return; |
| 173 | 173 | |
| 174 | - $myphptal = dirname(__FILE__) . '/../classes/PHPTAL.php'; |
|
| 174 | + $myphptal = dirname(__FILE__).'/../classes/PHPTAL.php'; |
|
| 175 | 175 | if (file_exists($myphptal)) { |
| 176 | 176 | require_once $myphptal; |
| 177 | 177 | } else { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | function acceptExtensions(array $ext) { |
| 205 | - $this->accept_pattern = '/\.(?:' . implode('|', $ext) . ')$/i'; |
|
| 205 | + $this->accept_pattern = '/\.(?:'.implode('|', $ext).')$/i'; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | protected function reportProgress($symbol) |
@@ -226,17 +226,17 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | if ($entry->isDir()) { |
| 228 | 228 | $this->reportProgress('.'); |
| 229 | - $this->scan($path . DIRECTORY_SEPARATOR . $filename); |
|
| 229 | + $this->scan($path.DIRECTORY_SEPARATOR.$filename); |
|
| 230 | 230 | continue; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if (! preg_match($this->accept_pattern, $filename)) { |
|
| 233 | + if (!preg_match($this->accept_pattern, $filename)) { |
|
| 234 | 234 | $this->skipped++; |
| 235 | 235 | $this->skipped_filenames[$filename] = true; |
| 236 | 236 | continue; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - $result = $this->testFile($path . DIRECTORY_SEPARATOR . $filename); |
|
| 239 | + $result = $this->testFile($path.DIRECTORY_SEPARATOR.$filename); |
|
| 240 | 240 | |
| 241 | 241 | if (self::TEST_OK == $result) { |
| 242 | 242 | $this->reportProgress('.'); |
@@ -258,25 +258,25 @@ discard block |
||
| 258 | 258 | function testFile($fullpath) |
| 259 | 259 | { |
| 260 | 260 | try { |
| 261 | - $this->checked ++; |
|
| 261 | + $this->checked++; |
|
| 262 | 262 | $phptal = new PHPTAL($fullpath); |
| 263 | 263 | $phptal->setForceReparse(true); |
| 264 | 264 | $phptal->prepare(); |
| 265 | 265 | return self::TEST_OK; |
| 266 | 266 | } |
| 267 | - catch(PHPTAL_UnknownModifierException $e) { |
|
| 267 | + catch (PHPTAL_UnknownModifierException $e) { |
|
| 268 | 268 | if ($this->skipUnknownModifiers && is_callable(array($e, 'getModifierName'))) { |
| 269 | 269 | $this->warnings[] = array(dirname($fullpath), basename($fullpath), "Unknown expression modifier: ".$e->getModifierName()." (use -i to include your custom modifier functions)", $e->getLine()); |
| 270 | 270 | return self::TEST_SKIPPED; |
| 271 | 271 | } |
| 272 | 272 | $log_exception = $e; |
| 273 | 273 | } |
| 274 | - catch(Exception $e) { |
|
| 274 | + catch (Exception $e) { |
|
| 275 | 275 | $log_exception = $e; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Takes exception from either of the two catch blocks above |
| 279 | - $this->errors[] = array(dirname($fullpath) , basename($fullpath) , $log_exception->getMessage() , $log_exception->getLine()); |
|
| 279 | + $this->errors[] = array(dirname($fullpath), basename($fullpath), $log_exception->getMessage(), $log_exception->getLine()); |
|
| 280 | 280 | return self::TEST_ERROR; |
| 281 | 281 | } |
| 282 | 282 | } |
@@ -94,8 +94,7 @@ discard block |
||
| 94 | 94 | echo "No errors found!\n"; |
| 95 | 95 | exit($lint->checked ? 0 : 1); |
| 96 | 96 | } |
| 97 | - } |
|
| 98 | - catch(Exception $e) { |
|
| 97 | + } catch(Exception $e) { |
|
| 99 | 98 | fwrite(STDERR, $e->getMessage() . "\n"); |
| 100 | 99 | $errcode = $e->getCode(); |
| 101 | 100 | exit($errcode ? $errcode : 1); |
@@ -129,7 +128,9 @@ discard block |
||
| 129 | 128 | |
| 130 | 129 | function plural($num, $word) |
| 131 | 130 | { |
| 132 | - if ($num == 1) return "$num $word"; |
|
| 131 | + if ($num == 1) { |
|
| 132 | + return "$num $word"; |
|
| 133 | + } |
|
| 133 | 134 | return "$num {$word}s"; |
| 134 | 135 | } |
| 135 | 136 | |
@@ -169,7 +170,9 @@ discard block |
||
| 169 | 170 | |
| 170 | 171 | function require_phptal() |
| 171 | 172 | { |
| 172 | - if (class_exists('PHPTAL', false)) return; |
|
| 173 | + if (class_exists('PHPTAL', false)) { |
|
| 174 | + return; |
|
| 175 | + } |
|
| 173 | 176 | |
| 174 | 177 | $myphptal = dirname(__FILE__) . '/../classes/PHPTAL.php'; |
| 175 | 178 | if (file_exists($myphptal)) { |
@@ -263,15 +266,13 @@ discard block |
||
| 263 | 266 | $phptal->setForceReparse(true); |
| 264 | 267 | $phptal->prepare(); |
| 265 | 268 | return self::TEST_OK; |
| 266 | - } |
|
| 267 | - catch(PHPTAL_UnknownModifierException $e) { |
|
| 269 | + } catch(PHPTAL_UnknownModifierException $e) { |
|
| 268 | 270 | if ($this->skipUnknownModifiers && is_callable(array($e, 'getModifierName'))) { |
| 269 | 271 | $this->warnings[] = array(dirname($fullpath), basename($fullpath), "Unknown expression modifier: ".$e->getModifierName()." (use -i to include your custom modifier functions)", $e->getLine()); |
| 270 | 272 | return self::TEST_SKIPPED; |
| 271 | 273 | } |
| 272 | 274 | $log_exception = $e; |
| 273 | - } |
|
| 274 | - catch(Exception $e) { |
|
| 275 | + } catch(Exception $e) { |
|
| 275 | 276 | $log_exception = $e; |
| 276 | 277 | } |
| 277 | 278 | |
@@ -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 | |
@@ -975,10 +975,10 @@ discard block |
||
| 975 | 975 | */ |
| 976 | 976 | public function getFunctionName() |
| 977 | 977 | { |
| 978 | - // function name is used as base for caching, so it must be unique for |
|
| 979 | - // every combination of settings that changes code in compiled template |
|
| 978 | + // function name is used as base for caching, so it must be unique for |
|
| 979 | + // every combination of settings that changes code in compiled template |
|
| 980 | 980 | |
| 981 | - if (!$this->_functionName) { |
|
| 981 | + if (!$this->_functionName) { |
|
| 982 | 982 | |
| 983 | 983 | // just to make tempalte name recognizable |
| 984 | 984 | $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath() ?? '')); |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $hash = strtr(rtrim(base64_encode($hash),"="),"+/=","_A_"); |
| 999 | 999 | |
| 1000 | 1000 | $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()) . |
| 1001 | - $basename . '__' . $hash; |
|
| 1001 | + $basename . '__' . $hash; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | return $this->_functionName; |
| 1004 | 1004 | } |
@@ -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,16 +836,16 @@ discard block |
||
| 836 | 836 | try { |
| 837 | 837 | eval("?>\n".$result); |
| 838 | 838 | } |
| 839 | - catch(ParseError $parseError) { |
|
| 839 | + catch (ParseError $parseError) { |
|
| 840 | 840 | ob_end_clean(); |
| 841 | 841 | throw new PHPTAL_TemplateException( |
| 842 | - 'Parse error: ' . $parseError->getMessage(), |
|
| 842 | + 'Parse error: '.$parseError->getMessage(), |
|
| 843 | 843 | $this->getCodePath(), |
| 844 | 844 | $parseError->getLine(), |
| 845 | 845 | $parseError |
| 846 | 846 | ); |
| 847 | 847 | } |
| 848 | - catch(Exception $e) { |
|
| 848 | + catch (Exception $e) { |
|
| 849 | 849 | ob_end_clean(); |
| 850 | 850 | throw $e; |
| 851 | 851 | } |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | $msg = str_replace('eval()\'d code', $this->getCodePath(), ob_get_clean()); |
| 855 | 855 | |
| 856 | 856 | // greedy .* ensures last match |
| 857 | - if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line=$m[1]; else $line=0; |
|
| 857 | + if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line = $m[1]; else $line = 0; |
|
| 858 | 858 | throw new PHPTAL_TemplateException(trim($msg), $this->getCodePath(), $line); |
| 859 | 859 | } |
| 860 | 860 | ob_end_clean(); |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | */ |
| 896 | 896 | public function setCachePurgeFrequency($n) |
| 897 | 897 | { |
| 898 | - $this->_cachePurgeFrequency = (int)$n; |
|
| 898 | + $this->_cachePurgeFrequency = (int) $n; |
|
| 899 | 899 | return $this; |
| 900 | 900 | } |
| 901 | 901 | |
@@ -915,14 +915,14 @@ discard block |
||
| 915 | 915 | */ |
| 916 | 916 | public function cleanUpGarbage() |
| 917 | 917 | { |
| 918 | - $cacheFilesExpire = time() - $this->getCacheLifetime() * 3600 * 24; |
|
| 918 | + $cacheFilesExpire = time()-$this->getCacheLifetime() * 3600 * 24; |
|
| 919 | 919 | |
| 920 | 920 | // relies on templates sorting order being related to their modification dates |
| 921 | - $upperLimit = $this->getPhpCodeDestination() . $this->getFunctionNamePrefix($cacheFilesExpire) . '_'; |
|
| 922 | - $lowerLimit = $this->getPhpCodeDestination() . $this->getFunctionNamePrefix(0); |
|
| 921 | + $upperLimit = $this->getPhpCodeDestination().$this->getFunctionNamePrefix($cacheFilesExpire).'_'; |
|
| 922 | + $lowerLimit = $this->getPhpCodeDestination().$this->getFunctionNamePrefix(0); |
|
| 923 | 923 | |
| 924 | 924 | // second * gets phptal:cache |
| 925 | - $cacheFiles = glob($this->getPhpCodeDestination() . 'tpl_????????_*.' . $this->getPhpCodeExtension() . '*'); |
|
| 925 | + $cacheFiles = glob($this->getPhpCodeDestination().'tpl_????????_*.'.$this->getPhpCodeExtension().'*'); |
|
| 926 | 926 | |
| 927 | 927 | if ($cacheFiles) { |
| 928 | 928 | foreach ($cacheFiles as $index => $file) { |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | public function cleanUpCache() |
| 946 | 946 | { |
| 947 | 947 | $filename = $this->getCodePath(); |
| 948 | - $cacheFiles = glob($filename . '?*'); |
|
| 948 | + $cacheFiles = glob($filename.'?*'); |
|
| 949 | 949 | if ($cacheFiles) { |
| 950 | 950 | foreach ($cacheFiles as $file) { |
| 951 | 951 | if (substr($file, 0, strlen($filename)) !== $filename) continue; // safety net |
@@ -984,7 +984,7 @@ discard block |
||
| 984 | 984 | $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath() ?? '')); |
| 985 | 985 | $basename = substr(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $basename), "_"), 0, 20); |
| 986 | 986 | |
| 987 | - $hash = md5(PHPTAL_VERSION . PHP_VERSION |
|
| 987 | + $hash = md5(PHPTAL_VERSION.PHP_VERSION |
|
| 988 | 988 | . $this->_source->getRealPath() |
| 989 | 989 | . $this->getEncoding() |
| 990 | 990 | . $this->getPrefiltersCacheId() |
@@ -995,10 +995,10 @@ discard block |
||
| 995 | 995 | // uses base64 rather than hex to make filename shorter. |
| 996 | 996 | // there is loss of some bits due to name constraints and case-insensivity, |
| 997 | 997 | // but that's still over 110 bits in addition to basename and timestamp. |
| 998 | - $hash = strtr(rtrim(base64_encode($hash),"="),"+/=","_A_"); |
|
| 998 | + $hash = strtr(rtrim(base64_encode($hash), "="), "+/=", "_A_"); |
|
| 999 | 999 | |
| 1000 | - $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()) . |
|
| 1001 | - $basename . '__' . $hash; |
|
| 1000 | + $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()). |
|
| 1001 | + $basename.'__'.$hash; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | return $this->_functionName; |
| 1004 | 1004 | } |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | { |
| 1016 | 1016 | // tpl_ prefix and last modified time must not be changed, |
| 1017 | 1017 | // because cache cleanup relies on that |
| 1018 | - return 'tpl_' . sprintf("%08x", $timestamp) .'_'; |
|
| 1018 | + return 'tpl_'.sprintf("%08x", $timestamp).'_'; |
|
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | */ |
| 1046 | 1046 | public function addError(Exception $error) |
| 1047 | 1047 | { |
| 1048 | - $this->_errors[] = $error; |
|
| 1048 | + $this->_errors[] = $error; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1101,7 +1101,7 @@ discard block |
||
| 1101 | 1101 | $data = $this->_source->getData(); |
| 1102 | 1102 | |
| 1103 | 1103 | $prefilters = $this->getPreFilterInstances(); |
| 1104 | - foreach($prefilters as $prefilter) { |
|
| 1104 | + foreach ($prefilters as $prefilter) { |
|
| 1105 | 1105 | $data = $prefilter->filter($data); |
| 1106 | 1106 | } |
| 1107 | 1107 | |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | $builder = new PHPTAL_Dom_PHPTALDocumentBuilder(); |
| 1112 | 1112 | $tree = $parser->parseString($builder, $data, $realpath)->getResult(); |
| 1113 | 1113 | |
| 1114 | - foreach($prefilters as $prefilter) { |
|
| 1114 | + foreach ($prefilters as $prefilter) { |
|
| 1115 | 1115 | if ($prefilter instanceof PHPTAL_PreFilter) { |
| 1116 | 1116 | if ($prefilter->filterDOM($tree) !== NULL) { |
| 1117 | 1117 | throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()"); |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | |
| 1199 | 1199 | if (substr($class, 0, 7) !== 'PHPTAL_') return; |
| 1200 | 1200 | |
| 1201 | - $path = dirname(__FILE__) . strtr("_".$class, "_", DIRECTORY_SEPARATOR) . '.php'; |
|
| 1201 | + $path = dirname(__FILE__).strtr("_".$class, "_", DIRECTORY_SEPARATOR).'.php'; |
|
| 1202 | 1202 | |
| 1203 | 1203 | require $path; |
| 1204 | 1204 | } |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | |
| 1223 | 1223 | // Prepending PHPTAL's autoloader helps if there are other autoloaders |
| 1224 | 1224 | // that throw/die when file is not found. Only >5.3 though. |
| 1225 | - @spl_autoload_register(array(__CLASS__,'autoload'), true, true); |
|
| 1225 | + @spl_autoload_register(array(__CLASS__, 'autoload'), true, true); |
|
| 1226 | 1226 | |
| 1227 | 1227 | if ($uses_autoload) { |
| 1228 | 1228 | spl_autoload_register('__autoload'); |
@@ -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 | /** |