@@ -25,7 +25,9 @@ |
||
| 25 | 25 | public function __construct($path) |
| 26 | 26 | { |
| 27 | 27 | $this->_path = realpath($path); |
| 28 | - if ($this->_path === false) throw new PHPTAL_IOException("Unable to find real path of file '$path' (in ".getcwd().')'); |
|
| 28 | + if ($this->_path === false) { |
|
| 29 | + throw new PHPTAL_IOException("Unable to find real path of file '$path' (in ".getcwd().')'); |
|
| 30 | + } |
|
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | public function getRealPath() |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $root->removeChild($node); |
| 51 | 51 | } else if ($lastTextNode) { |
| 52 | 52 | // "foo " . " bar" gives 2 spaces. |
| 53 | - $norm = $lastTextNode->getValueEscaped().ltrim($norm,' '); |
|
| 53 | + $norm = $lastTextNode->getValueEscaped().ltrim($norm, ' '); |
|
| 54 | 54 | |
| 55 | 55 | $lastTextNode->setValueEscaped($norm); // assumes all nodes use same encoding (they do) |
| 56 | 56 | $root->removeChild($node); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected function normalizeSpace($text, $encoding) |
| 91 | 91 | { |
| 92 | - $utf_regex_mod = ($encoding=='UTF-8'?'u':''); |
|
| 92 | + $utf_regex_mod = ($encoding == 'UTF-8' ? 'u' : ''); |
|
| 93 | 93 | |
| 94 | 94 | return preg_replace('/[ \t\r\n]+/'.$utf_regex_mod, ' ', $text); // \s removes nbsp |
| 95 | 95 | } |
@@ -76,7 +76,9 @@ discard block |
||
| 76 | 76 | protected function findElementToFilter(PHPTAL_Dom_Element $root) |
| 77 | 77 | { |
| 78 | 78 | foreach ($root->childNodes as $node) { |
| 79 | - if (!$node instanceof PHPTAL_Dom_Element) continue; |
|
| 79 | + if (!$node instanceof PHPTAL_Dom_Element) { |
|
| 80 | + continue; |
|
| 81 | + } |
|
| 80 | 82 | |
| 81 | 83 | if ($node->getAttributeNS("http://www.w3.org/XML/1998/namespace", 'space') == 'default') { |
| 82 | 84 | $this->filterDOM($node); |
@@ -99,7 +101,9 @@ discard block |
||
| 99 | 101 | foreach ($element->getAttributeNodes() as $attrnode) { |
| 100 | 102 | |
| 101 | 103 | // skip replaced attributes (because getValueEscaped on them is meaningless) |
| 102 | - if ($attrnode->getReplacedState() !== PHPTAL_Dom_Attr::NOT_REPLACED) continue; |
|
| 104 | + if ($attrnode->getReplacedState() !== PHPTAL_Dom_Attr::NOT_REPLACED) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 103 | 107 | |
| 104 | 108 | $val = $this->normalizeSpace($attrnode->getValueEscaped(), $attrnode->getEncoding()); |
| 105 | 109 | $attrnode->setValueEscaped(trim($val, ' ')); |
@@ -23,13 +23,13 @@ discard block |
||
| 23 | 23 | * keeps track whether last element had trailing whitespace (or didn't need it). |
| 24 | 24 | * If had_space==false, next element must keep leading space. |
| 25 | 25 | */ |
| 26 | - private $had_space=false; |
|
| 26 | + private $had_space = false; |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * last text node before closing tag that may need trailing whitespace trimmed. |
| 30 | 30 | * It's often last-child, but comments, multiple end tags make that trickier. |
| 31 | 31 | */ |
| 32 | - private $most_recent_text_node=null; |
|
| 32 | + private $most_recent_text_node = null; |
|
| 33 | 33 | |
| 34 | 34 | function filterDOM(PHPTAL_Dom_Element $root) |
| 35 | 35 | { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // tal:replace makes element behave like text |
| 44 | - if ($root->getAttributeNS('http://xml.zope.org/namespaces/tal','replace')) { |
|
| 44 | + if ($root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'replace')) { |
|
| 45 | 45 | $this->most_recent_text_node = null; |
| 46 | 46 | $this->had_space = false; |
| 47 | 47 | return; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // mostly block-level elements |
| 57 | 57 | // if element is conditional, it may not always break the line |
| 58 | - $breaks_line = $no_spaces || ($this->breaksLine($root) && !$root->getAttributeNS('http://xml.zope.org/namespaces/tal','condition')); |
|
| 58 | + $breaks_line = $no_spaces || ($this->breaksLine($root) && !$root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'condition')); |
|
| 59 | 59 | |
| 60 | 60 | // start tag newline |
| 61 | 61 | if ($breaks_line) { |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | // HTML 5 (9.1.2.5) specifies quirk that a first *single* newline in <pre> can be removed |
| 78 | 78 | if (count($root->childNodes) && $root->childNodes[0] instanceof PHPTAL_Dom_Text) { |
| 79 | 79 | if (preg_match('/^\n[^\n]/', $root->childNodes[0]->getValueEscaped())) { |
| 80 | - $root->childNodes[0]->setValueEscaped(substr($root->childNodes[0]->getValueEscaped(),1)); |
|
| 80 | + $root->childNodes[0]->setValueEscaped(substr($root->childNodes[0]->getValueEscaped(), 1)); |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | $this->findElementToFilter($root); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | // collapsed whitespace-only nodes are ignored (otherwise trimming of most_recent_text_node would be useless) |
| 102 | 102 | if ($norm !== '') { |
| 103 | 103 | $this->most_recent_text_node = $node; |
| 104 | - $this->had_space = (substr($norm,-1) == ' '); |
|
| 104 | + $this->had_space = (substr($norm, -1) == ' '); |
|
| 105 | 105 | } |
| 106 | 106 | } else if ($node instanceof PHPTAL_Dom_Element) { |
| 107 | 107 | $this->filterDOM($node); |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // repeated element may need trailing space. |
| 118 | - if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal','repeat')) { |
|
| 118 | + if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'repeat')) { |
|
| 119 | 119 | $this->most_recent_text_node = null; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // tal:content may replace element with something without space |
| 123 | - if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal','content')) { |
|
| 123 | + if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'content')) { |
|
| 124 | 124 | $this->had_space = false; |
| 125 | 125 | $this->most_recent_text_node = null; |
| 126 | 126 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | private static $no_interelement_space = array( |
| 139 | - 'html','head','table','thead','tfoot','select','optgroup','dl','ol','ul','tr','datalist', |
|
| 139 | + 'html', 'head', 'table', 'thead', 'tfoot', 'select', 'optgroup', 'dl', 'ol', 'ul', 'tr', 'datalist', |
|
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | 142 | private function hasNoInterelementSpace(PHPTAL_Dom_Element $element) |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | * li is deliberately omitted, as it's commonly used with display:inline in menus. |
| 156 | 156 | */ |
| 157 | 157 | private static $breaks_line = array( |
| 158 | - 'address','article','aside','base','blockquote','body','br','dd','div','dl','dt','fieldset','figure', |
|
| 159 | - 'footer','form','h1','h2','h3','h4','h5','h6','head','header','hgroup','hr','html','legend','link', |
|
| 160 | - 'meta','nav','ol','option','p','param','pre','section','style','table','tbody','td','th','thead', |
|
| 161 | - 'title','tr','ul','details', |
|
| 158 | + 'address', 'article', 'aside', 'base', 'blockquote', 'body', 'br', 'dd', 'div', 'dl', 'dt', 'fieldset', 'figure', |
|
| 159 | + 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'link', |
|
| 160 | + 'meta', 'nav', 'ol', 'option', 'p', 'param', 'pre', 'section', 'style', 'table', 'tbody', 'td', 'th', 'thead', |
|
| 161 | + 'title', 'tr', 'ul', 'details', |
|
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | 164 | private function breaksLine(PHPTAL_Dom_Element $element) |
| 165 | 165 | { |
| 166 | - if ($element->getAttributeNS('http://xml.zope.org/namespaces/metal','define-macro')) { |
|
| 166 | + if ($element->getAttributeNS('http://xml.zope.org/namespaces/metal', 'define-macro')) { |
|
| 167 | 167 | return true; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * replaced elements need to preserve spaces before and after |
| 184 | 184 | */ |
| 185 | 185 | private static $inline_blocks = array( |
| 186 | - 'select','input','button','img','textarea','output','progress','meter', |
|
| 186 | + 'select', 'input', 'button', 'img', 'textarea', 'output', 'progress', 'meter', |
|
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | 189 | private function isInlineBlock(PHPTAL_Dom_Element $element) |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * pre-defined order of attributes roughly by popularity |
| 220 | 220 | */ |
| 221 | 221 | private static $attributes_order = array( |
| 222 | - 'href','src','class','rel','type','title','width','height','alt','content','name','style','lang','id', |
|
| 222 | + 'href', 'src', 'class', 'rel', 'type', 'title', 'width', 'height', 'alt', 'content', 'name', 'style', 'lang', 'id', |
|
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | /** |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $b_index = array_search($b, self::$attributes_order); |
| 233 | 233 | |
| 234 | 234 | if ($a_index !== false && $b_index !== false) { |
| 235 | - return $a_index - $b_index; |
|
| 235 | + return $a_index-$b_index; |
|
| 236 | 236 | } |
| 237 | 237 | if ($a_index === false && $b_index === false) { |
| 238 | 238 | return strcmp($a, $b); |
@@ -256,26 +256,26 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | // <meta charset> |
| 258 | 258 | if ('meta' === $element->getLocalName() && |
| 259 | - $element->getAttributeNS('','http-equiv') === 'Content-Type') { |
|
| 260 | - $element->removeAttributeNS('','http-equiv'); |
|
| 261 | - $element->removeAttributeNS('','content'); |
|
| 262 | - $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding())); |
|
| 259 | + $element->getAttributeNS('', 'http-equiv') === 'Content-Type') { |
|
| 260 | + $element->removeAttributeNS('', 'http-equiv'); |
|
| 261 | + $element->removeAttributeNS('', 'content'); |
|
| 262 | + $element->setAttributeNS('', 'charset', strtolower($this->getPHPTAL()->getEncoding())); |
|
| 263 | 263 | } |
| 264 | - elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') || |
|
| 264 | + elseif (('link' === $element->getLocalName() && $element->getAttributeNS('', 'rel') === 'stylesheet') || |
|
| 265 | 265 | ('style' === $element->getLocalName())) { |
| 266 | 266 | // There's only one type of stylesheets that works. |
| 267 | - $element->removeAttributeNS('','type'); |
|
| 267 | + $element->removeAttributeNS('', 'type'); |
|
| 268 | 268 | |
| 269 | 269 | } elseif ('script' === $element->getLocalName()) { |
| 270 | - $element->removeAttributeNS('','language'); |
|
| 270 | + $element->removeAttributeNS('', 'language'); |
|
| 271 | 271 | |
| 272 | 272 | // Only remove type that matches default. E4X, vbscript, coffeescript, etc. must be preserved |
| 273 | - $type = $element->getAttributeNS('','type'); |
|
| 273 | + $type = $element->getAttributeNS('', 'type'); |
|
| 274 | 274 | $is_std = preg_match('/^(?:text|application)\/(?:ecma|java)script(\s*;\s*charset\s*=\s*[^;]*)?$/', $type); |
| 275 | 275 | |
| 276 | 276 | // Remote scripts should have type specified in HTTP headers. |
| 277 | - if ($is_std || $element->getAttributeNS('','src')) { |
|
| 278 | - $element->removeAttributeNS('','type'); |
|
| 277 | + if ($is_std || $element->getAttributeNS('', 'src')) { |
|
| 278 | + $element->removeAttributeNS('', 'type'); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -260,8 +260,7 @@ |
||
| 260 | 260 | $element->removeAttributeNS('','http-equiv'); |
| 261 | 261 | $element->removeAttributeNS('','content'); |
| 262 | 262 | $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding())); |
| 263 | - } |
|
| 264 | - elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') || |
|
| 263 | + } elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') || |
|
| 265 | 264 | ('style' === $element->getLocalName())) { |
| 266 | 265 | // There's only one type of stylesheets that works. |
| 267 | 266 | $element->removeAttributeNS('','type'); |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' |
| 175 | - && $element->getNamespaceURI() !== '') { |
|
| 176 | - return false; |
|
| 175 | + && $element->getNamespaceURI() !== '') { |
|
| 176 | + return false; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | return in_array($element->getLocalName(), self::$breaks_line); |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | private function isInlineBlock(PHPTAL_Dom_Element $element) |
| 190 | 190 | { |
| 191 | 191 | if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' |
| 192 | - && $element->getNamespaceURI() !== '') { |
|
| 193 | - return false; |
|
| 192 | + && $element->getNamespaceURI() !== '') { |
|
| 193 | + return false; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | return in_array($element->getLocalName(), self::$inline_blocks); |
@@ -209,45 +209,45 @@ discard block |
||
| 209 | 209 | $attrs_by_qname[$attrnode->getQualifiedName()] = $attrnode; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if (count($attrs_by_qname) > 1) { |
|
| 213 | - uksort($attrs_by_qname, array($this, 'compareQNames')); |
|
| 214 | - $element->setAttributeNodes(array_values($attrs_by_qname)); |
|
| 215 | - } |
|
| 212 | + if (count($attrs_by_qname) > 1) { |
|
| 213 | + uksort($attrs_by_qname, array($this, 'compareQNames')); |
|
| 214 | + $element->setAttributeNodes(array_values($attrs_by_qname)); |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * pre-defined order of attributes roughly by popularity |
|
| 220 | - */ |
|
| 221 | - private static $attributes_order = array( |
|
| 219 | + * pre-defined order of attributes roughly by popularity |
|
| 220 | + */ |
|
| 221 | + private static $attributes_order = array( |
|
| 222 | 222 | 'href','src','class','rel','type','title','width','height','alt','content','name','style','lang','id', |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * compare names according to $attributes_order array. |
|
| 227 | - * Elements that are not in array, are considered greater than all elements in array, |
|
| 228 | - * and are sorted alphabetically. |
|
| 229 | - */ |
|
| 230 | - private static function compareQNames($a, $b) { |
|
| 231 | - $a_index = array_search($a, self::$attributes_order); |
|
| 232 | - $b_index = array_search($b, self::$attributes_order); |
|
| 233 | - |
|
| 234 | - if ($a_index !== false && $b_index !== false) { |
|
| 235 | - return $a_index - $b_index; |
|
| 236 | - } |
|
| 237 | - if ($a_index === false && $b_index === false) { |
|
| 238 | - return strcmp($a, $b); |
|
| 239 | - } |
|
| 240 | - return ($a_index === false) ? 1 : -1; |
|
| 241 | - } |
|
| 225 | + /** |
|
| 226 | + * compare names according to $attributes_order array. |
|
| 227 | + * Elements that are not in array, are considered greater than all elements in array, |
|
| 228 | + * and are sorted alphabetically. |
|
| 229 | + */ |
|
| 230 | + private static function compareQNames($a, $b) { |
|
| 231 | + $a_index = array_search($a, self::$attributes_order); |
|
| 232 | + $b_index = array_search($b, self::$attributes_order); |
|
| 233 | + |
|
| 234 | + if ($a_index !== false && $b_index !== false) { |
|
| 235 | + return $a_index - $b_index; |
|
| 236 | + } |
|
| 237 | + if ($a_index === false && $b_index === false) { |
|
| 238 | + return strcmp($a, $b); |
|
| 239 | + } |
|
| 240 | + return ($a_index === false) ? 1 : -1; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | /** |
| 244 | 244 | * HTML5 doesn't care about boilerplate |
| 245 | 245 | */ |
| 246 | - private function elementSpecificOptimizations(PHPTAL_Dom_Element $element) |
|
| 247 | - { |
|
| 248 | - if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' |
|
| 249 | - && $element->getNamespaceURI() !== '') { |
|
| 250 | - return; |
|
| 246 | + private function elementSpecificOptimizations(PHPTAL_Dom_Element $element) |
|
| 247 | + { |
|
| 248 | + if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' |
|
| 249 | + && $element->getNamespaceURI() !== '') { |
|
| 250 | + return; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | if ($this->getPHPTAL()->getOutputMode() !== PHPTAL::HTML5) { |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // <meta charset> |
| 258 | - if ('meta' === $element->getLocalName() && |
|
| 259 | - $element->getAttributeNS('','http-equiv') === 'Content-Type') { |
|
| 260 | - $element->removeAttributeNS('','http-equiv'); |
|
| 261 | - $element->removeAttributeNS('','content'); |
|
| 262 | - $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding())); |
|
| 258 | + if ('meta' === $element->getLocalName() && |
|
| 259 | + $element->getAttributeNS('','http-equiv') === 'Content-Type') { |
|
| 260 | + $element->removeAttributeNS('','http-equiv'); |
|
| 261 | + $element->removeAttributeNS('','content'); |
|
| 262 | + $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding())); |
|
| 263 | 263 | } |
| 264 | 264 | elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') || |
| 265 | 265 | ('style' === $element->getLocalName())) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @see PHPTAL_Php_TalesInternal::compileToPHPExpressions() |
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | -function phptal_tale($expression, $nothrow=false) |
|
| 39 | +function phptal_tale($expression, $nothrow = false) |
|
| 40 | 40 | { |
| 41 | 41 | return PHPTAL_Php_TalesInternal::compileToPHPExpression($expression, $nothrow); |
| 42 | 42 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param bool $nothrow if true, invalid expression will return NULL (at run time) rather than throwing exception |
| 52 | 52 | * @return string or array |
| 53 | 53 | */ |
| 54 | -function phptal_tales($expression, $nothrow=false) |
|
| 54 | +function phptal_tales($expression, $nothrow = false) |
|
| 55 | 55 | { |
| 56 | 56 | return PHPTAL_Php_TalesInternal::compileToPHPExpressions($expression, $nothrow); |
| 57 | 57 | } |
@@ -58,5 +58,5 @@ |
||
| 58 | 58 | * @param string $key - translation key, e.g. "hello ${username}!" |
| 59 | 59 | * @param string $htmlescape - if true, you should HTML-escape translated string. You should never HTML-escape interpolated variables. |
| 60 | 60 | */ |
| 61 | - function translate($key, $htmlescape=true); |
|
| 61 | + function translate($key, $htmlescape = true); |
|
| 62 | 62 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | public function resolve($path) |
| 30 | 30 | { |
| 31 | 31 | foreach ($this->_repositories as $repository) { |
| 32 | - $file = $repository . DIRECTORY_SEPARATOR . $path; |
|
| 32 | + $file = $repository.DIRECTORY_SEPARATOR.$path; |
|
| 33 | 33 | if (file_exists($file)) { |
| 34 | 34 | return new PHPTAL_FileSource($file); |
| 35 | 35 | } |
@@ -64,11 +64,11 @@ |
||
| 64 | 64 | |
| 65 | 65 | if (ini_get('display_errors')) { |
| 66 | 66 | $title = get_class($e).': '.htmlspecialchars($e->getMessage()); |
| 67 | - $body = "<p><strong>\n".htmlspecialchars($e->getMessage()).'</strong></p>' . |
|
| 67 | + $body = "<p><strong>\n".htmlspecialchars($e->getMessage()).'</strong></p>'. |
|
| 68 | 68 | '<p>In '.htmlspecialchars($line)."</p><pre>\n".htmlspecialchars($e->getTraceAsString()).'</pre>'; |
| 69 | 69 | } else { |
| 70 | 70 | $title = "PHPTAL Exception"; |
| 71 | - $body = "<p>This page cannot be displayed.</p><hr/>" . |
|
| 71 | + $body = "<p>This page cannot be displayed.</p><hr/>". |
|
| 72 | 72 | "<p><small>Enable <code>display_errors</code> to see detailed message.</small></p>"; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @return void |
| 103 | 103 | */ |
| 104 | - public function setDocType($doctype,$called_from_macro) |
|
| 104 | + public function setDocType($doctype, $called_from_macro) |
|
| 105 | 105 | { |
| 106 | 106 | // FIXME: this is temporary workaround for problem of DOCTYPE disappearing in cloned PHPTAL object (because clone keeps _parentContext) |
| 107 | 107 | if (!$this->_docType) { |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function pushSlots() |
| 248 | 248 | { |
| 249 | - $this->_slotsStack[] = $this->_slots; |
|
| 249 | + $this->_slotsStack[] = $this->_slots; |
|
| 250 | 250 | $this->_slots = array(); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | } else $pathinfo = ''; |
| 321 | 321 | |
| 322 | 322 | if (!empty($basename)) { |
| 323 | - $basename = "'" . $basename . "' "; |
|
| 323 | + $basename = "'".$basename."' "; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | if (is_array($base)) { |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | * @access private |
| 351 | 351 | * @return mixed |
| 352 | 352 | */ |
| 353 | - public static function path($base, $path, $nothrow=false) |
|
| 353 | + public static function path($base, $path, $nothrow = false) |
|
| 354 | 354 | { |
| 355 | 355 | if ($base === null) { |
| 356 | 356 | if ($nothrow) return null; |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | $base = $base->__call($current, array()); |
| 415 | 415 | continue; |
| 416 | 416 | } |
| 417 | - catch(BadMethodCallException $e) {} |
|
| 417 | + catch (BadMethodCallException $e) {} |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | if (is_callable($base)) { |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | // array handling |
| 434 | 434 | if (is_array($base)) { |
| 435 | 435 | // key or index |
| 436 | - if (array_key_exists((string)$current, $base)) { |
|
| 436 | + if (array_key_exists((string) $current, $base)) { |
|
| 437 | 437 | $base = $base[$current]; |
| 438 | 438 | continue; |
| 439 | 439 | } |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @see PHPTAL_Context::path() |
| 482 | 482 | * @deprecated |
| 483 | 483 | */ |
| 484 | -function phptal_path($base, $path, $nothrow=false) |
|
| 484 | +function phptal_path($base, $path, $nothrow = false) |
|
| 485 | 485 | { |
| 486 | 486 | return PHPTAL_Context::path($base, $path, $nothrow); |
| 487 | 487 | } |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | function phptal_isempty($var) |
| 497 | 497 | { |
| 498 | 498 | return $var === null || $var === false || $var === '' |
| 499 | - || ((is_array($var) || $var instanceof Countable) && count($var)===0); |
|
| 499 | + || ((is_array($var) || $var instanceof Countable) && count($var) === 0); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | if (is_string($var)) { |
| 536 | 536 | return $var; |
| 537 | 537 | } elseif (is_bool($var)) { |
| 538 | - return (int)$var; |
|
| 538 | + return (int) $var; |
|
| 539 | 539 | } elseif (is_array($var)) { |
| 540 | 540 | return implode(', ', array_map('phptal_tostring', $var)); |
| 541 | 541 | } elseif ($var instanceof SimpleXMLElement) { |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | return $xml; |
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | - return (string)phptal_unravel_closure($var); |
|
| 552 | + return (string) phptal_unravel_closure($var); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -116,8 +116,7 @@ discard block |
||
| 116 | 116 | } else { |
| 117 | 117 | throw new PHPTAL_ConfigurationException("Executed macro in file with DOCTYPE when using echoExecute(). This is not supported yet. Remove DOCTYPE or use PHPTAL->execute()."); |
| 118 | 118 | } |
| 119 | - } |
|
| 120 | - else if (!$this->_docType) { |
|
| 119 | + } else if (!$this->_docType) { |
|
| 121 | 120 | $this->_docType = $doctype; |
| 122 | 121 | } |
| 123 | 122 | } |
@@ -317,7 +316,9 @@ discard block |
||
| 317 | 316 | { |
| 318 | 317 | if ($current !== $path) { |
| 319 | 318 | $pathinfo = " (in path '.../$path')"; |
| 320 | - } else $pathinfo = ''; |
|
| 319 | + } else { |
|
| 320 | + $pathinfo = ''; |
|
| 321 | + } |
|
| 321 | 322 | |
| 322 | 323 | if (!empty($basename)) { |
| 323 | 324 | $basename = "'" . $basename . "' "; |
@@ -353,7 +354,9 @@ discard block |
||
| 353 | 354 | public static function path($base, $path, $nothrow=false) |
| 354 | 355 | { |
| 355 | 356 | if ($base === null) { |
| 356 | - if ($nothrow) return null; |
|
| 357 | + if ($nothrow) { |
|
| 358 | + return null; |
|
| 359 | + } |
|
| 357 | 360 | PHPTAL_Context::pathError($base, $path, $path, $path); |
| 358 | 361 | } |
| 359 | 362 | |
@@ -413,8 +416,7 @@ discard block |
||
| 413 | 416 | { |
| 414 | 417 | $base = $base->__call($current, array()); |
| 415 | 418 | continue; |
| 416 | - } |
|
| 417 | - catch(BadMethodCallException $e) {} |
|
| 419 | + } catch(BadMethodCallException $e) {} |
|
| 418 | 420 | } |
| 419 | 421 | |
| 420 | 422 | if (is_callable($base)) { |
@@ -444,8 +446,9 @@ discard block |
||
| 444 | 446 | continue; |
| 445 | 447 | } |
| 446 | 448 | |
| 447 | - if ($nothrow) |
|
| 448 | - return null; |
|
| 449 | + if ($nothrow) { |
|
| 450 | + return null; |
|
| 451 | + } |
|
| 449 | 452 | |
| 450 | 453 | PHPTAL_Context::pathError($base, $path, $current, $prev); |
| 451 | 454 | } |
@@ -467,8 +470,9 @@ discard block |
||
| 467 | 470 | |
| 468 | 471 | // if this point is reached, then the part cannot be resolved |
| 469 | 472 | |
| 470 | - if ($nothrow) |
|
| 471 | - return null; |
|
| 473 | + if ($nothrow) { |
|
| 474 | + return null; |
|
| 475 | + } |
|
| 472 | 476 | |
| 473 | 477 | PHPTAL_Context::pathError($base, $path, $current, $prev); |
| 474 | 478 | } |
@@ -46,7 +46,9 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function __toString() |
| 48 | 48 | { |
| 49 | - if (!$this->srcFile || $this->is_src_accurate) return parent::__toString(); |
|
| 49 | + if (!$this->srcFile || $this->is_src_accurate) { |
|
| 50 | + return parent::__toString(); |
|
| 51 | + } |
|
| 50 | 52 | return "From {$this->srcFile} around line {$this->srcLine}\n".parent::__toString(); |
| 51 | 53 | } |
| 52 | 54 | |
@@ -87,7 +89,9 @@ discard block |
||
| 87 | 89 | |
| 88 | 90 | // searches backtrace to find template file |
| 89 | 91 | foreach($this->getTrace() as $tr) { |
| 90 | - if (!isset($tr['file'],$tr['line'])) continue; |
|
| 92 | + if (!isset($tr['file'],$tr['line'])) { |
|
| 93 | + continue; |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | if ($this->isTemplatePath($tr['file'])) { |
| 93 | 97 | return array($tr['file'], $tr['line']); |
@@ -97,8 +101,7 @@ discard block |
||
| 97 | 101 | // However, function name matches template path and eval() is visible in backtrace. |
| 98 | 102 | if (false !== strpos($tr['file'], 'eval()')) { |
| 99 | 103 | $eval_line = $tr['line']; |
| 100 | - } |
|
| 101 | - else if ($eval_line && isset($tr['function'],$tr['args'],$tr['args'][0]) && |
|
| 104 | + } else if ($eval_line && isset($tr['function'],$tr['args'],$tr['args'][0]) && |
|
| 102 | 105 | $this->isTemplatePath("/".$tr['function'].".php") && $tr['args'][0] instanceof PHPTAL) { |
| 103 | 106 | return array($tr['args'][0]->getCodePath(), $eval_line); |
| 104 | 107 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param int $srcLine |
| 33 | 33 | * @param Throwable $previous |
| 34 | 34 | */ |
| 35 | - public function __construct($msg, $srcFile='', $srcLine=0, $previous = null) |
|
| 35 | + public function __construct($msg, $srcFile = '', $srcLine = 0, $previous = null) |
|
| 36 | 36 | { |
| 37 | 37 | parent::__construct($msg, 0, $previous); |
| 38 | 38 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | if ($this->is_src_accurate) { |
| 48 | 48 | $this->file = $this->srcFile; |
| 49 | - $this->line = (int)$this->srcLine; |
|
| 49 | + $this->line = (int) $this->srcLine; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | if ($this->is_src_accurate) { |
| 75 | 75 | $this->file = $this->srcFile; |
| 76 | - $this->line = (int)$this->srcLine; |
|
| 76 | + $this->line = (int) $this->srcLine; |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | $eval_path = NULL; |
| 93 | 93 | |
| 94 | 94 | // searches backtrace to find template file |
| 95 | - foreach($this->getTrace() as $tr) { |
|
| 96 | - if (!isset($tr['file'],$tr['line'])) continue; |
|
| 95 | + foreach ($this->getTrace() as $tr) { |
|
| 96 | + if (!isset($tr['file'], $tr['line'])) continue; |
|
| 97 | 97 | |
| 98 | 98 | if ($this->isTemplatePath($tr['file'])) { |
| 99 | 99 | return array($tr['file'], $tr['line']); |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | if (false !== strpos($tr['file'], 'eval()')) { |
| 105 | 105 | $eval_line = $tr['line']; |
| 106 | 106 | } |
| 107 | - else if ($eval_line && isset($tr['function'],$tr['args'],$tr['args'][0]) && |
|
| 107 | + else if ($eval_line && isset($tr['function'], $tr['args'], $tr['args'][0]) && |
|
| 108 | 108 | $this->isTemplatePath("/".$tr['function'].".php") && $tr['args'][0] instanceof PHPTAL) { |
| 109 | 109 | return array($tr['args'][0]->getCodePath(), $eval_line); |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - return array(NULL,NULL); |
|
| 113 | + return array(NULL, NULL); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $this->srcFile = $this->file; |
| 126 | 126 | $this->srcLine = $this->line; |
| 127 | 127 | |
| 128 | - list($file,$line) = $this->findFileAndLine(); |
|
| 128 | + list($file, $line) = $this->findFileAndLine(); |
|
| 129 | 129 | |
| 130 | 130 | if (NULL === $file) { |
| 131 | 131 | return false; |
@@ -140,23 +140,23 @@ discard block |
||
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $found_line=false; |
|
| 144 | - $found_file=false; |
|
| 143 | + $found_line = false; |
|
| 144 | + $found_file = false; |
|
| 145 | 145 | |
| 146 | 146 | // scan lines backwards looking for "from line" comments |
| 147 | 147 | $end = min(count($lines), $line)-1; |
| 148 | - for($i=$end; $i >= 0; $i--) { |
|
| 148 | + for ($i = $end; $i >= 0; $i--) { |
|
| 149 | 149 | if (preg_match('/tag "[^"]*" from line (\d+)/', $lines[$i], $m)) { |
| 150 | 150 | $this->srcLine = intval($m[1]); |
| 151 | - $found_line=true; |
|
| 151 | + $found_line = true; |
|
| 152 | 152 | break; |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - foreach(preg_grep('/Generated by PHPTAL from/',$lines) as $line) { |
|
| 156 | + foreach (preg_grep('/Generated by PHPTAL from/', $lines) as $line) { |
|
| 157 | 157 | if (preg_match('/Generated by PHPTAL from (.*) \(/', $line, $m)) { |
| 158 | 158 | $this->srcFile = $m[1]; |
| 159 | - $found_file=true; |
|
| 159 | + $found_file = true; |
|
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | 162 | } |