@@ -41,9 +41,9 @@ |
||
| 41 | 41 | |
| 42 | 42 | function toPHP() { |
| 43 | 43 | if (is_numeric($this->scope)) |
| 44 | - return "Hamle\\Scope::get(" . Text::varToCode($this->scope) . ")"; |
|
| 44 | + return "Hamle\\Scope::get(".Text::varToCode($this->scope).")"; |
|
| 45 | 45 | else |
| 46 | - return "Hamle\\Scope::getName(" . Text::varToCode($this->scope) . ")"; |
|
| 46 | + return "Hamle\\Scope::getName(".Text::varToCode($this->scope).")"; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function toHTML($escape = false) { |
@@ -38,55 +38,55 @@ |
||
| 38 | 38 | protected $what; |
| 39 | 39 | |
| 40 | 40 | function __construct($s, Text $what) { |
| 41 | - if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
| 41 | + if (preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
| 42 | 42 | $this->filter = $m[1]; |
| 43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
| 44 | - foreach($this->vars as $k=>$v) |
|
| 45 | - $this->vars[$k] = str_replace(",",',',$v); |
|
| 44 | + foreach ($this->vars as $k=>$v) |
|
| 45 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
| 46 | 46 | } else { |
| 47 | 47 | throw new ParseError("Unable to parse filter expression \"$s\""); |
| 48 | 48 | } |
| 49 | - if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
| 50 | - 'strtoupper', 'strtolower', 'ucfirst','replace', 'json'])) { |
|
| 49 | + if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
| 50 | + 'strtoupper', 'strtolower', 'ucfirst', 'replace', 'json'])) { |
|
| 51 | 51 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
| 52 | 52 | } |
| 53 | - if(in_array($this->filter,['itersplit','newlinebr', 'replace'])) { |
|
| 53 | + if (in_array($this->filter, ['itersplit', 'newlinebr', 'replace'])) { |
|
| 54 | 54 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
| 55 | 55 | } |
| 56 | 56 | $mapFilter = ['json'=>'json_encode']; |
| 57 | - if(isset($mapFilter[$this->filter])) |
|
| 57 | + if (isset($mapFilter[$this->filter])) |
|
| 58 | 58 | $this->filter = $mapFilter[$this->filter]; |
| 59 | 59 | $this->what = $what; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | function toHTML($escape = false) { |
| 63 | - if($escape) |
|
| 64 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
| 65 | - return "<?=" . $this->toPHP() . "?>"; |
|
| 63 | + if ($escape) |
|
| 64 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
| 65 | + return "<?=".$this->toPHP()."?>"; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | function toPHP() { |
| 69 | - $o = [$this->what->toPHPVar()] ; |
|
| 70 | - foreach($this->vars as $v) |
|
| 69 | + $o = [$this->what->toPHPVar()]; |
|
| 70 | + foreach ($this->vars as $v) |
|
| 71 | 71 | $o[] = $this->varToCode($v); |
| 72 | - return "{$this->filter}(" . implode(',',$o) . ")"; |
|
| 72 | + return "{$this->filter}(".implode(',', $o).")"; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | static function itersplit($v, $sep = ",") { |
| 76 | 76 | $o = []; |
| 77 | - foreach(explode($sep, $v) as $k=>$i) { |
|
| 78 | - if($i) |
|
| 79 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
| 77 | + foreach (explode($sep, $v) as $k=>$i) { |
|
| 78 | + if ($i) |
|
| 79 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
| 80 | 80 | } |
| 81 | 81 | return new WrapArray($o); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | static function newlinebr($v) { |
| 85 | - return str_replace("\n","<br />\n",$v); |
|
| 85 | + return str_replace("\n", "<br />\n", $v); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | static function replace($v, $src, $dst) { |
| 89 | - return str_replace($src,$dst,$v); |
|
| 89 | + return str_replace($src, $dst, $v); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | } |
| 93 | 93 | \ No newline at end of file |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | self::$namedScopes[$name]->rewind(); |
| 68 | 68 | return self::$namedScopes[$name]; |
| 69 | 69 | } else |
| 70 | - if(self::$returnZeroOnNoScope) |
|
| 70 | + if (self::$returnZeroOnNoScope) |
|
| 71 | 71 | return new Model\Zero(); |
| 72 | 72 | throw new RunTime("Unable to find scope ($name)");
|
| 73 | 73 | } |
@@ -42,6 +42,6 @@ |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | function isClicked() { |
| 45 | - return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
| 45 | + return isset($_REQUEST[$this->form."_".$this->name]); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $i = self::indentLevel($indent); |
| 158 | 158 | unset($m[0]); |
| 159 | 159 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) {
|
| 160 | - case "|": //Control Tag |
|
| 160 | + case "|" : //Control Tag |
|
| 161 | 161 | if ($code == "|snippet") |
| 162 | 162 | $hTag = new Tag\Snippet($text); |
| 163 | 163 | elseif ($code == "|form") |
@@ -192,10 +192,10 @@ discard block |
||
| 192 | 192 | break; |
| 193 | 193 | default: |
| 194 | 194 | $attr = array(); |
| 195 | - if(isset($params[0]) && $params[0] == "[") {
|
|
| 195 | + if (isset($params[0]) && $params[0] == "[") {
|
|
| 196 | 196 | $param = substr($params, 1, strlen($params) - 2); |
| 197 | - $param = str_replace('+','%2B', $param);
|
|
| 198 | - $param = str_replace('\\&','%26', $param);
|
|
| 197 | + $param = str_replace('+', '%2B', $param);
|
|
| 198 | + $param = str_replace('\\&', '%26', $param);
|
|
| 199 | 199 | // parse_str($param, $attr); |
| 200 | 200 | $attr = $this->parseQueryString($param); |
| 201 | 201 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | if ($s[0] == ".") $class[] = substr($s, 1); |
| 207 | 207 | if ($s[0] == "!") $ref = substr($s, 1); |
| 208 | 208 | } |
| 209 | - if($ref) |
|
| 209 | + if ($ref) |
|
| 210 | 210 | $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
| 211 | 211 | else |
| 212 | 212 | $hTag = new Tag\Html($tag, $class, $attr, $id); |
@@ -219,16 +219,16 @@ discard block |
||
| 219 | 219 | else |
| 220 | 220 | $this->root[] = $hTag; |
| 221 | 221 | } else |
| 222 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error());
|
|
| 222 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/".preg_last_error());
|
|
| 223 | 223 | $this->lineNo++; |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | function parseQueryString($qs) {
|
| 228 | 228 | $out = []; |
| 229 | - foreach(explode('&',$qs) as $s) {
|
|
| 230 | - $kv = explode('=',$s,2);
|
|
| 231 | - $out[urldecode($kv[0])] = isset($kv[1])?urldecode($kv[1]):null; |
|
| 229 | + foreach (explode('&', $qs) as $s) {
|
|
| 230 | + $kv = explode('=', $s, 2);
|
|
| 231 | + $out[urldecode($kv[0])] = isset($kv[1]) ?urldecode($kv[1]) : null; |
|
| 232 | 232 | } |
| 233 | 233 | return $out; |
| 234 | 234 | } |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $m = array(); |
| 247 | 247 | while ($this->lineNo + 1 < $this->lineCount && |
| 248 | 248 | (!trim($this->lines[$this->lineNo + 1]) || |
| 249 | - preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/',
|
|
| 249 | + preg_match('/^(\s){'.$indent.'}((\s)+[^\s].*)$/',
|
|
| 250 | 250 | $this->lines[$this->lineNo + 1], $m))) {
|
| 251 | 251 | if (trim($this->lines[$this->lineNo + 1])) |
| 252 | 252 | $out[] = $m[2]; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function __construct($s) { |
| 45 | 45 | $m = array(); |
| 46 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
| 46 | + if (!preg_match('/^\$\(('.self::REGEX_FUNCSEL.'*)(.*)\)$/', $s, $m)) |
|
| 47 | 47 | throw new ParseError("Unable to read \$ func in '$s'"); |
| 48 | 48 | if (trim($m[2])) |
| 49 | 49 | $this->sub = new FuncSub($m[2]); |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | $rand = false; |
| 88 | 88 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9\_]*)/', $s, $m)) { |
| 89 | - foreach($m[0] as $k=>$mv) |
|
| 89 | + foreach ($m[0] as $k=>$mv) |
|
| 90 | 90 | if ($m[2][$k]) { |
| 91 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
| 91 | + $dir = $m[1][$k] == "-" ?Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
| 92 | 92 | $att['sort'][$m[2][$k]] = $dir; |
| 93 | 93 | } else $rand = true; |
| 94 | 94 | } |
| 95 | - if($rand) |
|
| 95 | + if ($rand) |
|
| 96 | 96 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
| 97 | 97 | return $att; |
| 98 | 98 | } |
@@ -110,25 +110,25 @@ discard block |
||
| 110 | 110 | * @return string PHP Code |
| 111 | 111 | */ |
| 112 | 112 | function toPHP() { |
| 113 | - $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
|
| 114 | - if($this->scope instanceof Scope) { |
|
| 115 | - return $this->scope->toPHP() . $sub; |
|
| 116 | - } elseif($this->scope === true) { |
|
| 113 | + $sub = $this->sub ? "->".$this->sub->toPHP() : ""; |
|
| 114 | + if ($this->scope instanceof Scope) { |
|
| 115 | + return $this->scope->toPHP().$sub; |
|
| 116 | + } elseif ($this->scope === true) { |
|
| 117 | 117 | return "Hamle\\Scope::get(0)$sub"; |
| 118 | 118 | } |
| 119 | - $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
|
| 120 | - $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
|
| 119 | + $limit = Text::varToCode($this->sortlimit['sort']).",". |
|
| 120 | + $this->sortlimit['limit'].",".$this->sortlimit['offset']; |
|
| 121 | 121 | if (count($this->filt['tag'])) |
| 122 | - return "Hamle\\Run::modelTypeTags(" . |
|
| 123 | - Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
|
| 122 | + return "Hamle\\Run::modelTypeTags(". |
|
| 123 | + Text::varToCode($this->filt['tag']).",$limit)$sub"; |
|
| 124 | 124 | if (count($this->filt['id'])) |
| 125 | 125 | if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
| 126 | - return "Hamle\\Run::modelId(" . |
|
| 127 | - Text::varToCode(current($this->filt['id']['*'])) . |
|
| 126 | + return "Hamle\\Run::modelId(". |
|
| 127 | + Text::varToCode(current($this->filt['id']['*'])). |
|
| 128 | 128 | ",$limit)$sub"; |
| 129 | 129 | else |
| 130 | - return "Hamle\\Run::modelTypeId(" . |
|
| 131 | - Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
|
| 130 | + return "Hamle\\Run::modelTypeId(". |
|
| 131 | + Text::varToCode($this->filt['id']).",$limit)$sub"; |
|
| 132 | 132 | return ""; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $this->setup(); |
| 55 | 55 | $fields = $this->_fields; |
| 56 | 56 | $this->_fields = array(); |
| 57 | - foreach($fields as $v) {
|
|
| 57 | + foreach ($fields as $v) {
|
|
| 58 | 58 | $this->_fields[$v->name] = $v; |
| 59 | 59 | $v->form($this->_name); |
| 60 | 60 | } |
@@ -64,23 +64,23 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function process() {
|
| 66 | 66 | $clicked = ""; |
| 67 | - foreach($this->_fields as $f) |
|
| 68 | - if($f instanceOf Field\Button) |
|
| 69 | - if($f->isClicked()) |
|
| 67 | + foreach ($this->_fields as $f) |
|
| 68 | + if ($f instanceOf Field\Button) |
|
| 69 | + if ($f->isClicked()) |
|
| 70 | 70 | $clicked = $f; |
| 71 | - foreach($this->_fields as $f) |
|
| 72 | - $f->doProcess($clicked?true:false); |
|
| 73 | - if($clicked) |
|
| 71 | + foreach ($this->_fields as $f) |
|
| 72 | + $f->doProcess($clicked ?true:false); |
|
| 73 | + if ($clicked) |
|
| 74 | 74 | try {
|
| 75 | 75 | $this->onSubmit($clicked); |
| 76 | - } catch(Exception\FormInvalid $e) {
|
|
| 76 | + } catch (Exception\FormInvalid $e) {
|
|
| 77 | 77 | $this->hint = $e->getMessage(); |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | function isValid() {
|
| 82 | 82 | $valid = true; |
| 83 | - foreach($this->_fields as $f) |
|
| 83 | + foreach ($this->_fields as $f) |
|
| 84 | 84 | $valid = $f->valid && $valid; |
| 85 | 85 | return $valid; |
| 86 | 86 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | return $this->_fields; |
| 96 | 96 | } |
| 97 | 97 | function getField($n) {
|
| 98 | - if(!isset($this->_fields[$n])) |
|
| 98 | + if (!isset($this->_fields[$n])) |
|
| 99 | 99 | throw new Exception\NoKey("unable to find form field ($n)");
|
| 100 | 100 | return $this->_fields[$n]; |
| 101 | 101 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function getHTMLProp() {
|
| 107 | - return array('action'=>'','method'=>'post','name'=>$this->_name,
|
|
| 107 | + return array('action'=>'', 'method'=>'post', 'name'=>$this->_name,
|
|
| 108 | 108 | 'enctype'=>'multipart/form-data'); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | function __construct($tag, $class = array(), $attr = array(), $id = "") { |
| 43 | 43 | parent::__construct(); |
| 44 | 44 | $this->opt = $attr; |
| 45 | - if(isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | - $this->opt['class'] = $attr['class']?explode(" ",$attr['class']):array(); |
|
| 45 | + if (isset($attr['class']) && !is_array($attr['class'])) |
|
| 46 | + $this->opt['class'] = $attr['class'] ?explode(" ", $attr['class']) : array(); |
|
| 47 | 47 | $this->source = array(); |
| 48 | 48 | $this->type = $tag ? $tag : "div"; |
| 49 | - if($class) { |
|
| 49 | + if ($class) { |
|
| 50 | 50 | if (isset($this->opt['class'])) |
| 51 | 51 | $this->opt['class'] = array_merge($this->opt['class'], $class); |
| 52 | 52 | else |
| 53 | 53 | $this->opt['class'] = $class; |
| 54 | 54 | } |
| 55 | - if($id) $this->opt['id'] = $id; |
|
| 55 | + if ($id) $this->opt['id'] = $id; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function renderStTag() { |
| 59 | 59 | $close = in_array($this->type, self::$selfCloseTags) ? " />" : ">"; |
| 60 | - return "<{$this->type}" . $this->optToTags() . $close; |
|
| 60 | + return "<{$this->type}".$this->optToTags().$close; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | function renderEnTag() { |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | if (!$v instanceof H\Text) |
| 80 | 80 | $v = new H\Text($v); |
| 81 | 81 | $k = new H\Text($k); |
| 82 | - $out[] = " " . $k->toHTML() . "=\"" . $v->toHTMLAtt() . "\""; |
|
| 82 | + $out[] = " ".$k->toHTML()."=\"".$v->toHTMLAtt()."\""; |
|
| 83 | 83 | } |
| 84 | 84 | return implode("", $out); |
| 85 | 85 | } |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | public $baseModel; |
| 65 | 65 | |
| 66 | - const REL_CHILD = 0x01; /* Child Relation */ |
|
| 66 | + const REL_CHILD = 0x01; /* Child Relation */ |
|
| 67 | 67 | const REL_PARENT = 0x02; /* Parent Relation */ |
| 68 | - const REL_ANY = 0x03; /* Unspecified or any relation */ |
|
| 68 | + const REL_ANY = 0x03; /* Unspecified or any relation */ |
|
| 69 | 69 | |
| 70 | - const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */ |
|
| 71 | - const SORT_ASCENDING = 0x02; /* Sort Ascending */ |
|
| 70 | + const SORT_NATURAL = 0x00; /* Sort in what ever order is 'default' */ |
|
| 71 | + const SORT_ASCENDING = 0x02; /* Sort Ascending */ |
|
| 72 | 72 | const SORT_DESCENDING = 0x03; /* Sort Decending */ |
| 73 | - const SORT_RANDOM = 0x04; /* Sort Randomly */ |
|
| 73 | + const SORT_RANDOM = 0x04; /* Sort Randomly */ |
|
| 74 | 74 | /** |
| 75 | 75 | * Create new HAMLE Parser |
| 76 | 76 | * |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function __construct($baseModel, $setup = NULL) { |
| 83 | 83 | self::$me = $this; |
| 84 | - if(!$setup) |
|
| 84 | + if (!$setup) |
|
| 85 | 85 | $setup = new Setup(); |
| 86 | 86 | $this->parse = new Parse(); |
| 87 | - if(!$setup instanceOf Setup) |
|
| 87 | + if (!$setup instanceOf Setup) |
|
| 88 | 88 | throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
| 89 | - if(!$baseModel instanceOf Model) |
|
| 89 | + if (!$baseModel instanceOf Model) |
|
| 90 | 90 | throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
| 91 | 91 | $this->setup = $setup; |
| 92 | 92 | $this->baseModel = $baseModel; |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function initSnipFiles() { |
| 97 | - if($this->snipMod == 0) { |
|
| 97 | + if ($this->snipMod == 0) { |
|
| 98 | 98 | $this->snipFiles = $this->setup->snippetFiles(); |
| 99 | - foreach($this->snipFiles as $f) { |
|
| 99 | + foreach ($this->snipFiles as $f) { |
|
| 100 | 100 | if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
| 101 | 101 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
| 102 | 102 | } |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function load($hamleFile, \Closure $parseFunc = null) { |
| 113 | 113 | $template = $this->setup->templatePath($hamleFile); |
| 114 | - if(!file_exists($template)) |
|
| 114 | + if (!file_exists($template)) |
|
| 115 | 115 | throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
| 116 | 116 | $this->cacheFile = $this->setup->cachePath( |
| 117 | - str_replace("/","-",$hamleFile).".php"); |
|
| 117 | + str_replace("/", "-", $hamleFile).".php"); |
|
| 118 | 118 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
| 119 | - $cacheFileAge = is_file($this->cacheFile)?filemtime($this->cacheFile):0; |
|
| 119 | + $cacheFileAge = is_file($this->cacheFile) ?filemtime($this->cacheFile) : 0; |
|
| 120 | 120 | $cacheDirty = !$this->cache || |
| 121 | 121 | $cacheFileAge < $this->snipMod || $cacheFileAge < filemtime($template); |
| 122 | - if($cacheDirty) { |
|
| 122 | + if ($cacheDirty) { |
|
| 123 | 123 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
| 124 | - $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
|
| 124 | + $this->parse($parseFunc ? "" : file_get_contents($template), $parseFunc); |
|
| 125 | 125 | } else |
| 126 | 126 | $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
| 127 | 127 | return $this; |
@@ -135,22 +135,22 @@ discard block |
||
| 135 | 135 | * @throws Exception\ParseError if unable to write to the cache file |
| 136 | 136 | */ |
| 137 | 137 | function parse($hamleCode, \Closure $parseFunc = null) { |
| 138 | - if(!$this->cacheFile) |
|
| 138 | + if (!$this->cacheFile) |
|
| 139 | 139 | $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
| 140 | - if($parseFunc) |
|
| 140 | + if ($parseFunc) |
|
| 141 | 141 | $parseFunc($this->parse); |
| 142 | 142 | else |
| 143 | 143 | $this->parse->str($hamleCode); |
| 144 | 144 | $this->setup->debugLog("Loading Snippet Files"); |
| 145 | - foreach($this->snipFiles as $snip) |
|
| 145 | + foreach ($this->snipFiles as $snip) |
|
| 146 | 146 | $this->parse->parseSnip(file_get_contents($snip)); |
| 147 | 147 | $this->setup->debugLog("Applying Snippet Files"); |
| 148 | 148 | $this->parse->applySnip(); |
| 149 | 149 | $this->setup->debugLog("Executing Parse Filters"); |
| 150 | - foreach($this->setup->getFilters() as $filter) |
|
| 150 | + foreach ($this->setup->getFilters() as $filter) |
|
| 151 | 151 | $this->parse->parseFilter($filter); |
| 152 | 152 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
| 153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output())) |
|
| 153 | + if (FALSE === file_put_contents($this->cacheFile, $this->parse->output())) |
|
| 154 | 154 | throw new Exception\ParseError( |
| 155 | 155 | "Unable to write to cache file ({$this->cacheFile})"); |
| 156 | 156 | } |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | function string($hamleString) { |
| 163 | 163 | $md5 = md5($hamleString); |
| 164 | - $stringId = substr($md5,0,12).substr($md5,24,8); |
|
| 164 | + $stringId = substr($md5, 0, 12).substr($md5, 24, 8); |
|
| 165 | 165 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
| 166 | - if(!is_file($this->cacheFile)) |
|
| 166 | + if (!is_file($this->cacheFile)) |
|
| 167 | 167 | $this->parse($hamleString); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | $baseModel = $this->baseModel; |
| 180 | 180 | $this->baseModel = null; |
| 181 | 181 | $currentModel = $baseModel == Scope::getTopScope(); |
| 182 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
| 182 | + if (!$currentModel && $baseModel) Scope::add($baseModel); |
|
| 183 | 183 | require $this->cacheFile; |
| 184 | - if(!$currentModel && $baseModel) Scope::done(); |
|
| 184 | + if (!$currentModel && $baseModel) Scope::done(); |
|
| 185 | 185 | $this->baseModel = $baseModel; |
| 186 | 186 | $out = ob_get_contents(); |
| 187 | 187 | ob_end_clean(); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return int The line number being passed by the parser |
| 199 | 199 | */ |
| 200 | 200 | static function getLineNo() { |
| 201 | - if(!isset(self::$me)) |
|
| 201 | + if (!isset(self::$me)) |
|
| 202 | 202 | return 0; |
| 203 | 203 | return self::$me->parse->getLineNo(); |
| 204 | 204 | } |