@@ -31,7 +31,8 @@ |
||
31 | 31 | function __construct($s) { |
32 | 32 | $s = explode("->", $s, 2); |
33 | 33 | $this->key = $s[0]; |
34 | - if (count($s) > 1) |
|
35 | - $this->sel = $s[1]; |
|
34 | + if (count($s) > 1) { |
|
35 | + $this->sel = $s[1]; |
|
36 | + } |
|
36 | 37 | } |
37 | 38 | } |
38 | 39 | \ No newline at end of file |
@@ -36,14 +36,18 @@ |
||
36 | 36 | function getInputAttDynamic(&$atts, &$type, &$content) { |
37 | 37 | parent::getInputAttDynamic($atts, $type, $content); |
38 | 38 | $atts['value'] = "ON"; |
39 | - if ($this->getValue()) |
|
40 | - $atts['checked'] = "checked"; |
|
39 | + if ($this->getValue()) { |
|
40 | + $atts['checked'] = "checked"; |
|
41 | + } |
|
41 | 42 | } |
42 | 43 | |
43 | 44 | function getValue() { |
44 | - if (!is_null($this->setValue)) return $this->setValue; |
|
45 | - if (isset($_REQUEST[$this->form . "__submit"])) |
|
46 | - return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
45 | + if (!is_null($this->setValue)) { |
|
46 | + return $this->setValue; |
|
47 | + } |
|
48 | + if (isset($_REQUEST[$this->form . "__submit"])) { |
|
49 | + return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
50 | + } |
|
47 | 51 | return $this->opt['default']; |
48 | 52 | } |
49 | 53 | } |
50 | 54 | \ No newline at end of file |
@@ -41,7 +41,9 @@ discard block |
||
41 | 41 | public function cachePath($f) { |
42 | 42 | $s = DIRECTORY_SEPARATOR; |
43 | 43 | $dir = implode($s,[__DIR__,"..","..","cache",""]); |
44 | - if(!is_dir($dir)) mkdir($dir); |
|
44 | + if(!is_dir($dir)) { |
|
45 | + mkdir($dir); |
|
46 | + } |
|
45 | 47 | return $dir.$f; |
46 | 48 | } |
47 | 49 | |
@@ -67,8 +69,9 @@ discard block |
||
67 | 69 | * @throws Exception\RunTime |
68 | 70 | */ |
69 | 71 | public function getModelTypeID($typeId, $sort = [], $limit = 0, $offset = 0) { |
70 | - if(count($typeId) > 1) |
|
71 | - throw new Exception\RunTime("Unable to open more than one ID at a time"); |
|
72 | + if(count($typeId) > 1) { |
|
73 | + throw new Exception\RunTime("Unable to open more than one ID at a time"); |
|
74 | + } |
|
72 | 75 | return new Model\Zero(); |
73 | 76 | } |
74 | 77 |
@@ -35,8 +35,9 @@ |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | function hamleGet($key) { |
38 | - if (!isset($this->data[$this->pos][$key])) |
|
39 | - return "Missing Key [$key]"; |
|
38 | + if (!isset($this->data[$this->pos][$key])) { |
|
39 | + return "Missing Key [$key]"; |
|
40 | + } |
|
40 | 41 | return $this->data[$this->pos][$key]; |
41 | 42 | } |
42 | 43 |
@@ -44,8 +44,9 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | function toHTML($escape = false) { |
47 | - if($escape) |
|
48 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
47 | + if($escape) { |
|
48 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
49 | + } |
|
49 | 50 | return "<?=" . $this->toPHP() . "?>"; |
50 | 51 | } |
51 | 52 | |
@@ -67,8 +68,9 @@ discard block |
||
67 | 68 | */ |
68 | 69 | function setValue($value) { |
69 | 70 | $model = $this->getOrCreateModel(); |
70 | - if(!$model instanceof WriteModel) |
|
71 | - throw new \RuntimeException('Can only write to model that implements WriteModel'); |
|
71 | + if(!$model instanceof WriteModel) { |
|
72 | + throw new \RuntimeException('Can only write to model that implements WriteModel'); |
|
73 | + } |
|
72 | 74 | $model->hamleSet($this->var, $value); |
73 | 75 | return $model; |
74 | 76 | } |
@@ -54,10 +54,11 @@ discard block |
||
54 | 54 | */ |
55 | 55 | static function popInstance() { |
56 | 56 | array_pop(self::$hamleList); |
57 | - if (self::$hamleList) |
|
58 | - self::$hamle = self::$hamleList[count(self::$hamleList) - 1]; |
|
59 | - else |
|
60 | - self::$hamle = NULL; |
|
57 | + if (self::$hamleList) { |
|
58 | + self::$hamle = self::$hamleList[count(self::$hamleList) - 1]; |
|
59 | + } else { |
|
60 | + self::$hamle = NULL; |
|
61 | + } |
|
61 | 62 | } |
62 | 63 | |
63 | 64 | /** |
@@ -113,7 +114,9 @@ discard block |
||
113 | 114 | */ |
114 | 115 | static function modelId($id, $sort = [], $limit = 0, $offset = 0) { |
115 | 116 | $o = self::$hamle->setup->getModelDefault($id, $sort, $limit, $offset); |
116 | - if (!$o instanceOf Model) throw new RunTime("Application must return instance of hamleModel"); |
|
117 | + if (!$o instanceOf Model) { |
|
118 | + throw new RunTime("Application must return instance of hamleModel"); |
|
119 | + } |
|
117 | 120 | return $o; |
118 | 121 | } |
119 | 122 |
@@ -39,17 +39,25 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct($s) { |
41 | 41 | $m = array(); |
42 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
43 | - throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
44 | - if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
|
45 | - elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
|
46 | - else $this->dir = Hamle\Hamle::REL_ANY; |
|
42 | + if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) { |
|
43 | + throw new ParseError("Unable to read \$ sub func in '$s'"); |
|
44 | + } |
|
45 | + if ($m[1] == "<") { |
|
46 | + $this->dir = Hamle\Hamle::REL_PARENT; |
|
47 | + } elseif ($m[1] == ">") { |
|
48 | + $this->dir = Hamle\Hamle::REL_CHILD; |
|
49 | + } else { |
|
50 | + $this->dir = Hamle\Hamle::REL_ANY; |
|
51 | + } |
|
47 | 52 | $this->sortlimit = $this->attSortLimit($m[2]); |
48 | 53 | $this->filt = $this->attIdTag($m[2]); |
49 | 54 | $this->grouptype = $this->attGroupType($m[2]); |
50 | - if ($this->filt['id']) throw new ParseError("Unable to select by id"); |
|
51 | - if (trim($m[3])) |
|
52 | - $this->sub = new FuncSub($m[3]); |
|
55 | + if ($this->filt['id']) { |
|
56 | + throw new ParseError("Unable to select by id"); |
|
57 | + } |
|
58 | + if (trim($m[3])) { |
|
59 | + $this->sub = new FuncSub($m[3]); |
|
60 | + } |
|
53 | 61 | } |
54 | 62 | |
55 | 63 | /** |
@@ -69,13 +77,15 @@ discard block |
||
69 | 77 | $model = $parent->hamleRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
70 | 78 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
71 | 79 | if(!$model->valid()) { |
72 | - if(!$parent instanceof Hamle\WriteModel) |
|
73 | - throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.'); |
|
80 | + if(!$parent instanceof Hamle\WriteModel) { |
|
81 | + throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.'); |
|
82 | + } |
|
74 | 83 | $model = $parent->current()->hamleCreateRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
75 | 84 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
76 | 85 | } |
77 | - if($this->sub) |
|
78 | - return $this->sub->getOrCreateModel($model)->current(); |
|
86 | + if($this->sub) { |
|
87 | + return $this->sub->getOrCreateModel($model)->current(); |
|
88 | + } |
|
79 | 89 | return $model->current(); |
80 | 90 | } |
81 | 91 |
@@ -81,13 +81,16 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function __construct($baseModel, $setup = NULL) { |
83 | 83 | self::$me = $this; |
84 | - if(!$setup) |
|
85 | - $setup = new Setup(); |
|
84 | + if(!$setup) { |
|
85 | + $setup = new Setup(); |
|
86 | + } |
|
86 | 87 | $this->parse = new Parse(); |
87 | - if(!$setup instanceOf Setup) |
|
88 | - throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
89 | - if(!$baseModel instanceOf Model) |
|
90 | - throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
88 | + if(!$setup instanceOf Setup) { |
|
89 | + throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
90 | + } |
|
91 | + if(!$baseModel instanceOf Model) { |
|
92 | + throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
93 | + } |
|
91 | 94 | $this->setup = $setup; |
92 | 95 | $this->baseModel = $baseModel; |
93 | 96 | $this->initSnipFiles(); |
@@ -97,7 +100,9 @@ discard block |
||
97 | 100 | if($this->snipMod == 0) { |
98 | 101 | $this->snipFiles = $this->setup->snippetFiles(); |
99 | 102 | foreach($this->snipFiles as $f) { |
100 | - if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
103 | + if (!file_exists($f)) { |
|
104 | + throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
105 | + } |
|
101 | 106 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
102 | 107 | } |
103 | 108 | } |
@@ -111,8 +116,9 @@ discard block |
||
111 | 116 | */ |
112 | 117 | function load($hamleFile, \Closure $parseFunc = null) { |
113 | 118 | $template = $this->setup->templatePath($hamleFile); |
114 | - if(!file_exists($template)) |
|
115 | - throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
119 | + if(!file_exists($template)) { |
|
120 | + throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
121 | + } |
|
116 | 122 | $this->cacheFile = $this->setup->cachePath( |
117 | 123 | str_replace("/","-",$hamleFile).".php"); |
118 | 124 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
@@ -122,8 +128,9 @@ discard block |
||
122 | 128 | if($cacheDirty) { |
123 | 129 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
124 | 130 | $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
125 | - } else |
|
126 | - $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
131 | + } else { |
|
132 | + $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
133 | + } |
|
127 | 134 | return $this; |
128 | 135 | } |
129 | 136 | /** |
@@ -135,24 +142,29 @@ discard block |
||
135 | 142 | * @throws Exception\ParseError if unable to write to the cache file |
136 | 143 | */ |
137 | 144 | function parse($hamleCode, \Closure $parseFunc = null) { |
138 | - if(!$this->cacheFile) |
|
139 | - $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
140 | - if($parseFunc) |
|
141 | - $parseFunc($this->parse); |
|
142 | - else |
|
143 | - $this->parse->str($hamleCode); |
|
145 | + if(!$this->cacheFile) { |
|
146 | + $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
147 | + } |
|
148 | + if($parseFunc) { |
|
149 | + $parseFunc($this->parse); |
|
150 | + } else { |
|
151 | + $this->parse->str($hamleCode); |
|
152 | + } |
|
144 | 153 | $this->setup->debugLog("Loading Snippet Files"); |
145 | - foreach($this->snipFiles as $snip) |
|
146 | - $this->parse->parseSnip(file_get_contents($snip)); |
|
154 | + foreach($this->snipFiles as $snip) { |
|
155 | + $this->parse->parseSnip(file_get_contents($snip)); |
|
156 | + } |
|
147 | 157 | $this->setup->debugLog("Applying Snippet Files"); |
148 | 158 | $this->parse->applySnip(); |
149 | 159 | $this->setup->debugLog("Executing Parse Filters"); |
150 | - foreach($this->setup->getFilters() as $filter) |
|
151 | - $this->parse->parseFilter($filter); |
|
160 | + foreach($this->setup->getFilters() as $filter) { |
|
161 | + $this->parse->parseFilter($filter); |
|
162 | + } |
|
152 | 163 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) |
|
154 | - throw new Exception\ParseError( |
|
164 | + if(FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) { |
|
165 | + throw new Exception\ParseError( |
|
155 | 166 | "Unable to write to cache file ({$this->cacheFile})"); |
167 | + } |
|
156 | 168 | } |
157 | 169 | |
158 | 170 | /** |
@@ -163,8 +175,9 @@ discard block |
||
163 | 175 | $md5 = md5($hamleString); |
164 | 176 | $stringId = substr($md5,0,12).substr($md5,24,8); |
165 | 177 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
166 | - if(!is_file($this->cacheFile)) |
|
167 | - $this->parse($hamleString); |
|
178 | + if(!is_file($this->cacheFile)) { |
|
179 | + $this->parse($hamleString); |
|
180 | + } |
|
168 | 181 | } |
169 | 182 | |
170 | 183 | function getCacheFileName() { |
@@ -183,9 +196,13 @@ discard block |
||
183 | 196 | $baseModel = $this->baseModel; |
184 | 197 | $this->baseModel = null; |
185 | 198 | $currentModel = $baseModel == Scope::getTopScope(); |
186 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
199 | + if(!$currentModel && $baseModel) { |
|
200 | + Scope::add($baseModel); |
|
201 | + } |
|
187 | 202 | require $this->cacheFile; |
188 | - if(!$currentModel && $baseModel) Scope::done(); |
|
203 | + if(!$currentModel && $baseModel) { |
|
204 | + Scope::done(); |
|
205 | + } |
|
189 | 206 | $this->baseModel = $baseModel; |
190 | 207 | $out = ob_get_contents(); |
191 | 208 | ob_end_clean(); |
@@ -202,8 +219,9 @@ discard block |
||
202 | 219 | * @return int The line number being passed by the parser |
203 | 220 | */ |
204 | 221 | static function getLineNo() { |
205 | - if(!isset(self::$me)) |
|
206 | - return 0; |
|
222 | + if(!isset(self::$me)) { |
|
223 | + return 0; |
|
224 | + } |
|
207 | 225 | return self::$me->parse->getLineNo(); |
208 | 226 | } |
209 | 227 |
@@ -73,14 +73,16 @@ discard block |
||
73 | 73 | $scopeName = $m[1]; |
74 | 74 | $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0])); |
75 | 75 | $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL); |
76 | - } else |
|
77 | - $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
76 | + } else { |
|
77 | + $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
78 | + } |
|
78 | 79 | switch ($this->type) { |
79 | 80 | case "each": |
80 | - if ($this->var) |
|
81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
82 | - else |
|
83 | - $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
81 | + if ($this->var) { |
|
82 | + $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
83 | + } else { |
|
84 | + $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
85 | + } |
|
84 | 86 | $out .= "Hamle\\Scope::add({$this->o}); "; |
85 | 87 | break; |
86 | 88 | case "if": |
@@ -88,9 +90,9 @@ discard block |
||
88 | 90 | $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
89 | 91 | break; |
90 | 92 | case "with": |
91 | - if ($scopeName) |
|
92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
93 | - else { |
|
93 | + if ($scopeName) { |
|
94 | + $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
95 | + } else { |
|
94 | 96 | $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
95 | 97 | "{$this->o}->valid()) {\n"; |
96 | 98 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
@@ -101,10 +103,11 @@ discard block |
||
101 | 103 | break; |
102 | 104 | case "include": |
103 | 105 | $file = $hsv->toHTML(); |
104 | - if($file[0] == "#") |
|
105 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
106 | - else |
|
107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
106 | + if($file[0] == "#") { |
|
107 | + $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
108 | + } else { |
|
109 | + $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
110 | + } |
|
108 | 111 | break; |
109 | 112 | } |
110 | 113 | return $out . "\n?>"; |
@@ -123,8 +126,9 @@ discard block |
||
123 | 126 | case "each"; |
124 | 127 | $out .= 'Hamle\\Scope::done(); '; |
125 | 128 | $out .= '}'; |
126 | - if (!$this->var) |
|
127 | - $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
129 | + if (!$this->var) { |
|
130 | + $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
131 | + } |
|
128 | 132 | break; |
129 | 133 | case "if": |
130 | 134 | case "else": |
@@ -140,7 +144,9 @@ discard block |
||
140 | 144 | return ""; |
141 | 145 | break; |
142 | 146 | } |
143 | - if ($this->else) $out .= "else{"; |
|
147 | + if ($this->else) { |
|
148 | + $out .= "else{"; |
|
149 | + } |
|
144 | 150 | return $out . "\n?>"; |
145 | 151 | } |
146 | 152 | |
@@ -148,9 +154,12 @@ discard block |
||
148 | 154 | $ind = $minify ? '' : str_pad('', $indent); |
149 | 155 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
150 | 156 | $out = $this->renderStTag(); |
151 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
|
152 | - foreach ($this->tags as $tag) |
|
153 | - $out .= $tag->render($indent, $minify); |
|
157 | + if ($this->content) { |
|
158 | + $out .= $this->renderContent($ind, $oneliner || $minify); |
|
159 | + } |
|
160 | + foreach ($this->tags as $tag) { |
|
161 | + $out .= $tag->render($indent, $minify); |
|
162 | + } |
|
154 | 163 | $out .= $this->renderEnTag(); |
155 | 164 | return $out; |
156 | 165 | } |