@@ -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,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct($s) { |
41 | 41 | $m = array(); |
42 | - if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL . '+)(.*)$/', $s, $m)) |
|
42 | + if (!preg_match('/^ +([><]) +('.self::REGEX_FUNCSEL.'+)(.*)$/', $s, $m)) |
|
43 | 43 | throw new ParseError("Unable to read \$ sub func in '$s'"); |
44 | 44 | if ($m[1] == "<") $this->dir = Hamle\Hamle::REL_PARENT; |
45 | 45 | elseif ($m[1] == ">") $this->dir = Hamle\Hamle::REL_CHILD; |
@@ -57,24 +57,24 @@ discard block |
||
57 | 57 | * @return string |
58 | 58 | */ |
59 | 59 | public function toPHP() { |
60 | - $limit = Hamle\Text::varToCode($this->sortlimit['sort']) . "," . |
|
61 | - $this->sortlimit['limit'] . "," . $this->sortlimit['offset'] . "," . |
|
60 | + $limit = Hamle\Text::varToCode($this->sortlimit['sort']).",". |
|
61 | + $this->sortlimit['limit'].",".$this->sortlimit['offset'].",". |
|
62 | 62 | $this->grouptype['grouptype']; |
63 | - $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
|
64 | - return "hamleRel(" . $this->dir . "," . |
|
65 | - Hamle\Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
|
63 | + $sub = $this->sub ? "->".$this->sub->toPHP() : ""; |
|
64 | + return "hamleRel(".$this->dir.",". |
|
65 | + Hamle\Text::varToCode($this->filt['tag']).",$limit)$sub"; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public function getOrCreateModel(Model $parent = null) { |
69 | 69 | $model = $parent->hamleRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
70 | 70 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
71 | - if(!$model->valid()) { |
|
72 | - if(!$parent instanceof Hamle\WriteModel) |
|
73 | - throw new \Exception('Cant create model, ' . get_class($parent) . ' must implement Hamle\\WriteModel.'); |
|
71 | + if (!$model->valid()) { |
|
72 | + if (!$parent instanceof Hamle\WriteModel) |
|
73 | + throw new \Exception('Cant create model, '.get_class($parent).' must implement Hamle\\WriteModel.'); |
|
74 | 74 | $model = $parent->current()->hamleCreateRel($this->dir, $this->filt['tag'], $this->sortlimit['sort'], |
75 | 75 | $this->sortlimit['limit'], $this->sortlimit['offset']); |
76 | 76 | } |
77 | - if($this->sub) |
|
77 | + if ($this->sub) |
|
78 | 78 | return $this->sub->getOrCreateModel($model)->current(); |
79 | 79 | return $model->current(); |
80 | 80 | } |
@@ -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 |
@@ -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($this->setup->getMinify()))) |
|
153 | + if (FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) |
|
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 | |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | $baseModel = $this->baseModel; |
184 | 184 | $this->baseModel = null; |
185 | 185 | $currentModel = $baseModel == Scope::getTopScope(); |
186 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
186 | + if (!$currentModel && $baseModel) Scope::add($baseModel); |
|
187 | 187 | require $this->cacheFile; |
188 | - if(!$currentModel && $baseModel) Scope::done(); |
|
188 | + if (!$currentModel && $baseModel) Scope::done(); |
|
189 | 189 | $this->baseModel = $baseModel; |
190 | 190 | $out = ob_get_contents(); |
191 | 191 | ob_end_clean(); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return int The line number being passed by the parser |
203 | 203 | */ |
204 | 204 | static function getLineNo() { |
205 | - if(!isset(self::$me)) |
|
205 | + if (!isset(self::$me)) |
|
206 | 206 | return 0; |
207 | 207 | return self::$me->parse->getLineNo(); |
208 | 208 | } |
@@ -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 |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | function render($indent = 0, $minify = false) { |
144 | 144 | $ind = $minify ? '' : str_pad('', $indent); |
145 | 145 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
146 | - $out = $ind . $this->renderStTag() . ($oneliner || $minify ? '' : "\n"); |
|
146 | + $out = $ind.$this->renderStTag().($oneliner || $minify ? '' : "\n"); |
|
147 | 147 | if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
148 | 148 | foreach ($this->tags as $tag) |
149 | 149 | $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
150 | - $out .= ($minify || $oneliner ? '' : $ind) . $this->renderEnTag() . ($minify ? '' : "\n"); |
|
150 | + $out .= ($minify || $oneliner ? '' : $ind).$this->renderEnTag().($minify ? '' : "\n"); |
|
151 | 151 | return $out; |
152 | 152 | } |
153 | 153 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | function renderContent($pad = "", $oneliner = false) { |
162 | 162 | $out = ""; |
163 | 163 | foreach ($this->content as $c) |
164 | - $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
164 | + $out .= ($oneliner ? '' : $pad).$c.($oneliner ? '' : "\n"); |
|
165 | 165 | return $out; |
166 | 166 | } |
167 | 167 |
@@ -76,9 +76,10 @@ discard block |
||
76 | 76 | } |
77 | 77 | array_shift($path); |
78 | 78 | } |
79 | - foreach ($this->tags as $tag) |
|
80 | - if ($found = $tag->find($path)) |
|
81 | - $list = array_merge($list, $found); |
|
79 | + foreach ($this->tags as $tag) { |
|
80 | + if ($found = $tag->find($path)) |
|
81 | + $list = array_merge($list, $found); |
|
82 | + } |
|
82 | 83 | return $list; |
83 | 84 | } |
84 | 85 | |
@@ -90,7 +91,9 @@ discard block |
||
90 | 91 | */ |
91 | 92 | function replace($path, Tag $newTag) { |
92 | 93 | if ($this->compare($path[0])) { |
93 | - if (count($path) == 1) return $newTag; |
|
94 | + if (count($path) == 1) { |
|
95 | + return $newTag; |
|
96 | + } |
|
94 | 97 | array_shift($path); |
95 | 98 | } |
96 | 99 | foreach ($this->tags as $k => $tag) { |
@@ -103,19 +106,23 @@ discard block |
||
103 | 106 | } |
104 | 107 | |
105 | 108 | function addSnipContent($contentTag, &$tagArray = array(), $key = 0) { |
106 | - foreach ($this->tags as $k => $tag) |
|
107 | - $tag->addSnipContent($contentTag, $this->tags, $k); |
|
109 | + foreach ($this->tags as $k => $tag) { |
|
110 | + $tag->addSnipContent($contentTag, $this->tags, $k); |
|
111 | + } |
|
108 | 112 | } |
109 | 113 | |
110 | 114 | function compare($tic) { |
111 | - if (isset($tic['type']) && $this->type != $tic['type']) |
|
112 | - return false; |
|
115 | + if (isset($tic['type']) && $this->type != $tic['type']) { |
|
116 | + return false; |
|
117 | + } |
|
113 | 118 | if (isset($tic['id']) && |
114 | 119 | !(isset($this->opt['id']) && $tic['id'] == $this->opt['id']) |
115 | - ) |
|
116 | - return false; |
|
117 | - if (array_diff($tic['class'] ?? [], $this->opt['class'] ?? [])) |
|
118 | - return false; |
|
120 | + ) { |
|
121 | + return false; |
|
122 | + } |
|
123 | + if (array_diff($tic['class'] ?? [], $this->opt['class'] ?? [])) { |
|
124 | + return false; |
|
125 | + } |
|
119 | 126 | return true; |
120 | 127 | } |
121 | 128 | |
@@ -125,10 +132,11 @@ discard block |
||
125 | 132 | * @param string $mode Mode to add child [append|prepend] |
126 | 133 | */ |
127 | 134 | function addChild(Tag $tag, $mode = "append") { |
128 | - if ($mode == "prepend") |
|
129 | - array_unshift($this->tags, $tag); |
|
130 | - else |
|
131 | - $this->tags[] = $tag; |
|
135 | + if ($mode == "prepend") { |
|
136 | + array_unshift($this->tags, $tag); |
|
137 | + } else { |
|
138 | + $this->tags[] = $tag; |
|
139 | + } |
|
132 | 140 | } |
133 | 141 | |
134 | 142 | /** |
@@ -142,9 +150,12 @@ discard block |
||
142 | 150 | $ind = $minify ? '' : str_pad('', $indent); |
143 | 151 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
144 | 152 | $out = $ind . $this->renderStTag() . ($oneliner || $minify ? '' : "\n"); |
145 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
|
146 | - foreach ($this->tags as $tag) |
|
147 | - $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
|
153 | + if ($this->content) { |
|
154 | + $out .= $this->renderContent($ind, $oneliner || $minify); |
|
155 | + } |
|
156 | + foreach ($this->tags as $tag) { |
|
157 | + $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
|
158 | + } |
|
148 | 159 | $out .= ($minify || $oneliner ? '' : $ind) . $this->renderEnTag() . ($minify ? '' : "\n"); |
149 | 160 | return $out; |
150 | 161 | } |
@@ -158,8 +169,9 @@ discard block |
||
158 | 169 | */ |
159 | 170 | function renderContent($pad = "", $oneliner = false) { |
160 | 171 | $out = ""; |
161 | - foreach ($this->content as $c) |
|
162 | - $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
172 | + foreach ($this->content as $c) { |
|
173 | + $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
174 | + } |
|
163 | 175 | return $out; |
164 | 176 | } |
165 | 177 |
@@ -45,7 +45,7 @@ |
||
45 | 45 | |
46 | 46 | static function decodeClassId($s) { |
47 | 47 | $out = $m = array(); |
48 | - if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
48 | + if (preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
49 | 49 | $out['type'] = $m[0]; |
50 | 50 | preg_match_all('/[#\.][a-zA-Z0-9\-\_]+/m', $s, $m); |
51 | 51 | if (isset($m[0])) foreach ($m[0] as $ss) { |
@@ -32,25 +32,33 @@ discard block |
||
32 | 32 | |
33 | 33 | function __construct($params) { |
34 | 34 | parent::__construct(); |
35 | - if (!preg_match('/^(append|content|prepend|replace)(?: (.*))?$/', $params, $m)) |
|
36 | - throw new Hamle\Exception\ParseError("Unable to parse Snippet($params)"); |
|
35 | + if (!preg_match('/^(append|content|prepend|replace)(?: (.*))?$/', $params, $m)) { |
|
36 | + throw new Hamle\Exception\ParseError("Unable to parse Snippet($params)"); |
|
37 | + } |
|
37 | 38 | $this->type = $m[1]; |
38 | - if (isset($m[2])) |
|
39 | - $this->path = explode(" ", $m[2]); |
|
40 | - else |
|
41 | - $this->path = array(); |
|
42 | - foreach ($this->path as $k => $v) |
|
43 | - $this->path[$k] = self::decodeClassId($v); |
|
39 | + if (isset($m[2])) { |
|
40 | + $this->path = explode(" ", $m[2]); |
|
41 | + } else { |
|
42 | + $this->path = array(); |
|
43 | + } |
|
44 | + foreach ($this->path as $k => $v) { |
|
45 | + $this->path[$k] = self::decodeClassId($v); |
|
46 | + } |
|
44 | 47 | } |
45 | 48 | |
46 | 49 | static function decodeClassId($s) { |
47 | 50 | $out = $m = array(); |
48 | - if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) |
|
49 | - $out['type'] = $m[0]; |
|
51 | + if(preg_match('/^[a-zA-Z0-9\_]+/', $s, $m)) { |
|
52 | + $out['type'] = $m[0]; |
|
53 | + } |
|
50 | 54 | preg_match_all('/[#\.][a-zA-Z0-9\-\_]+/m', $s, $m); |
51 | - if (isset($m[0])) foreach ($m[0] as $ss) { |
|
55 | + if (isset($m[0])) { |
|
56 | + foreach ($m[0] as $ss) { |
|
52 | 57 | if ($ss[0] === "#") $out['id'] = substr($ss, 1); |
53 | - if ($ss[0] === ".") $out['class'][] = substr($ss, 1); |
|
58 | + } |
|
59 | + if ($ss[0] === ".") { |
|
60 | + $out['class'][] = substr($ss, 1); |
|
61 | + } |
|
54 | 62 | } |
55 | 63 | return $out; |
56 | 64 | } |
@@ -62,21 +70,24 @@ discard block |
||
62 | 70 | function addSnipContent($contentTag, &$tagArray = array(), $key = 0) { |
63 | 71 | if ($this->type == "content") { |
64 | 72 | $tagArray[$key] = $contentTag; |
65 | - } else |
|
66 | - parent::addSnipContent($contentTag, $tagArray, $key); |
|
73 | + } else { |
|
74 | + parent::addSnipContent($contentTag, $tagArray, $key); |
|
75 | + } |
|
67 | 76 | } |
68 | 77 | |
69 | 78 | function apply(Hamle\Tag $rootTag) { |
70 | 79 | if ($this->type == "append" or $this->type == "prepend") { |
71 | 80 | $matchTags = $rootTag->find($this->path); |
72 | - foreach ($matchTags as $tag) |
|
73 | - foreach ($this->tags as $t) { |
|
81 | + foreach ($matchTags as $tag) { |
|
82 | + foreach ($this->tags as $t) { |
|
74 | 83 | $tag->addChild($t, $this->type); |
84 | + } |
|
75 | 85 | } |
76 | 86 | } elseif ($this->type == "replace") { |
77 | 87 | $rootTag->replace($this->path, $this); |
78 | - } else |
|
79 | - throw new Hamle\Exception\ParseError("Cant Apply snippet to document '{$this->type}'"); |
|
88 | + } else { |
|
89 | + throw new Hamle\Exception\ParseError("Cant Apply snippet to document '{$this->type}'"); |
|
90 | + } |
|
80 | 91 | } |
81 | 92 | |
82 | 93 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function __construct($s) { |
52 | 52 | $m = array(); |
53 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
53 | + if (!preg_match('/^\$\(('.self::REGEX_FUNCSEL.'*)(.*)\)$/', $s, $m)) |
|
54 | 54 | throw new ParseError("Unable to read \$ func in '$s'"); |
55 | 55 | if (trim($m[2])) |
56 | 56 | $this->sub = new FuncSub($m[2]); |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | } |
93 | 93 | $rand = false; |
94 | 94 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9_]*)/', $s, $m)) { |
95 | - foreach($m[0] as $k=>$mv) |
|
95 | + foreach ($m[0] as $k=>$mv) |
|
96 | 96 | if ($m[2][$k]) { |
97 | - $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
|
97 | + $dir = $m[1][$k] == "-" ?Hamle\Hamle::SORT_DESCENDING : Hamle\Hamle::SORT_ASCENDING; |
|
98 | 98 | $att['sort'][$m[2][$k]] = $dir; |
99 | 99 | } else $rand = true; |
100 | 100 | } |
101 | - if($rand) |
|
101 | + if ($rand) |
|
102 | 102 | $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
103 | 103 | return $att; |
104 | 104 | } |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | * @return string PHP Code |
117 | 117 | */ |
118 | 118 | public function toPHP() { |
119 | - $sub = $this->sub ? "->" . $this->sub->toPHP() : ""; |
|
120 | - if($this->scope instanceof Scope) { |
|
121 | - return $this->scope->toPHP() . $sub; |
|
122 | - } elseif($this->scope === true) { |
|
119 | + $sub = $this->sub ? "->".$this->sub->toPHP() : ""; |
|
120 | + if ($this->scope instanceof Scope) { |
|
121 | + return $this->scope->toPHP().$sub; |
|
122 | + } elseif ($this->scope === true) { |
|
123 | 123 | return "Hamle\\Scope::get(0)$sub"; |
124 | 124 | } |
125 | - $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
|
126 | - $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
|
125 | + $limit = Text::varToCode($this->sortlimit['sort']).",". |
|
126 | + $this->sortlimit['limit'].",".$this->sortlimit['offset']; |
|
127 | 127 | if (count($this->filt['tag'])) |
128 | - return "Hamle\\Run::modelTypeTags(" . |
|
129 | - Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
|
128 | + return "Hamle\\Run::modelTypeTags(". |
|
129 | + Text::varToCode($this->filt['tag']).",$limit)$sub"; |
|
130 | 130 | if (count($this->filt['id'])) |
131 | 131 | if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
132 | - return "Hamle\\Run::modelId(" . |
|
133 | - Text::varToCode(current($this->filt['id']['*'])) . |
|
132 | + return "Hamle\\Run::modelId(". |
|
133 | + Text::varToCode(current($this->filt['id']['*'])). |
|
134 | 134 | ",$limit)$sub"; |
135 | 135 | else |
136 | - return "Hamle\\Run::modelTypeId(" . |
|
137 | - Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
|
136 | + return "Hamle\\Run::modelTypeId(". |
|
137 | + Text::varToCode($this->filt['id']).",$limit)$sub"; |
|
138 | 138 | return ""; |
139 | 139 | } |
140 | 140 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return Model |
144 | 144 | */ |
145 | 145 | public function getOrCreateModel(Model $parent = null) { |
146 | - if($this->scope instanceof Scope) { |
|
146 | + if ($this->scope instanceof Scope) { |
|
147 | 147 | $parent = $this->scope->getOrCreateModel(); |
148 | 148 | } elseif ($this->scope === true) |
149 | 149 | $parent = \Seufert\Hamle\Scope::get(0); |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | $this->sortlimit['limit'], |
170 | 170 | $this->sortlimit['offset'] |
171 | 171 | ); |
172 | - if($this->sub) |
|
172 | + if ($this->sub) |
|
173 | 173 | return $this->sub->getOrCreateModel($parent)->current(); |
174 | - if(!$parent) |
|
174 | + if (!$parent) |
|
175 | 175 | throw new \RuntimeException('Unable to create model with no relation'); |
176 | 176 | return $parent->current(); |
177 | 177 | } |
@@ -50,10 +50,12 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function __construct($s) { |
52 | 52 | $m = array(); |
53 | - if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) |
|
54 | - throw new ParseError("Unable to read \$ func in '$s'"); |
|
55 | - if (trim($m[2])) |
|
56 | - $this->sub = new FuncSub($m[2]); |
|
53 | + if (!preg_match('/^\$\((' . self::REGEX_FUNCSEL . '*)(.*)\)$/', $s, $m)) { |
|
54 | + throw new ParseError("Unable to read \$ func in '$s'"); |
|
55 | + } |
|
56 | + if (trim($m[2])) { |
|
57 | + $this->sub = new FuncSub($m[2]); |
|
58 | + } |
|
57 | 59 | if (!trim($m[1])) { |
58 | 60 | $this->scope = true; |
59 | 61 | return; |
@@ -70,16 +72,23 @@ discard block |
||
70 | 72 | $m = array(); |
71 | 73 | $att = array('id' => array(), 'tag' => array()); |
72 | 74 | foreach (explode(",", $s) as $str) { |
73 | - if (preg_match('/^[a-zA-Z0-9_]+/', $str, $m)) $type = $m[0]; |
|
74 | - else $type = "*"; |
|
75 | - if (preg_match('/#([a-zA-Z0-9_${}]+)/', $str, $m)) $att['id'][$type][] = $m[1]; |
|
76 | - elseif (preg_match_all('/\\.([a-zA-Z0-9_\-${}]+)/', $str, $m)) |
|
77 | - foreach ($m[1] as $tag) |
|
75 | + if (preg_match('/^[a-zA-Z0-9_]+/', $str, $m)) { |
|
76 | + $type = $m[0]; |
|
77 | + } else { |
|
78 | + $type = "*"; |
|
79 | + } |
|
80 | + if (preg_match('/#([a-zA-Z0-9_${}]+)/', $str, $m)) { |
|
81 | + $att['id'][$type][] = $m[1]; |
|
82 | + } elseif (preg_match_all('/\\.([a-zA-Z0-9_\-${}]+)/', $str, $m)) { |
|
83 | + foreach ($m[1] as $tag) |
|
78 | 84 | $att['tag'][$type][] = new Text($tag, Text::TOKEN_CODE); |
79 | - else $att['tag'][$type] = array(); |
|
85 | + } else { |
|
86 | + $att['tag'][$type] = array(); |
|
87 | + } |
|
88 | + } |
|
89 | + if (!(count($att['id']) xor count($att['tag']))) { |
|
90 | + throw new ParseError("Only tag, type or id can be combined"); |
|
80 | 91 | } |
81 | - if (!(count($att['id']) xor count($att['tag']))) |
|
82 | - throw new ParseError("Only tag, type or id can be combined"); |
|
83 | 92 | return $att; |
84 | 93 | } |
85 | 94 | |
@@ -92,14 +101,18 @@ discard block |
||
92 | 101 | } |
93 | 102 | $rand = false; |
94 | 103 | if (preg_match_all('/\\^(-?)([a-zA-Z0-9_]*)/', $s, $m)) { |
95 | - foreach($m[0] as $k=>$mv) |
|
96 | - if ($m[2][$k]) { |
|
104 | + foreach($m[0] as $k=>$mv) { |
|
105 | + if ($m[2][$k]) { |
|
97 | 106 | $dir = $m[1][$k] == "-"?Hamle\Hamle::SORT_DESCENDING:Hamle\Hamle::SORT_ASCENDING; |
107 | + } |
|
98 | 108 | $att['sort'][$m[2][$k]] = $dir; |
99 | - } else $rand = true; |
|
109 | + } else { |
|
110 | + $rand = true; |
|
111 | + } |
|
112 | + } |
|
113 | + if($rand) { |
|
114 | + $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
|
100 | 115 | } |
101 | - if($rand) |
|
102 | - $att['sort'] = [""=>$att['dir'] = Hamle\Hamle::SORT_RANDOM]; |
|
103 | 116 | return $att; |
104 | 117 | } |
105 | 118 | |
@@ -124,17 +137,19 @@ discard block |
||
124 | 137 | } |
125 | 138 | $limit = Text::varToCode($this->sortlimit['sort']) . "," . |
126 | 139 | $this->sortlimit['limit'] . "," . $this->sortlimit['offset']; |
127 | - if (count($this->filt['tag'])) |
|
128 | - return "Hamle\\Run::modelTypeTags(" . |
|
140 | + if (count($this->filt['tag'])) { |
|
141 | + return "Hamle\\Run::modelTypeTags(" . |
|
129 | 142 | Text::varToCode($this->filt['tag']) . ",$limit)$sub"; |
130 | - if (count($this->filt['id'])) |
|
131 | - if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
|
143 | + } |
|
144 | + if (count($this->filt['id'])) { |
|
145 | + if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) == 1) |
|
132 | 146 | return "Hamle\\Run::modelId(" . |
133 | 147 | Text::varToCode(current($this->filt['id']['*'])) . |
134 | 148 | ",$limit)$sub"; |
135 | - else |
|
136 | - return "Hamle\\Run::modelTypeId(" . |
|
149 | + } else { |
|
150 | + return "Hamle\\Run::modelTypeId(" . |
|
137 | 151 | Text::varToCode($this->filt['id']) . ",$limit)$sub"; |
152 | + } |
|
138 | 153 | return ""; |
139 | 154 | } |
140 | 155 | |
@@ -145,34 +160,39 @@ discard block |
||
145 | 160 | public function getOrCreateModel(Model $parent = null) { |
146 | 161 | if($this->scope instanceof Scope) { |
147 | 162 | $parent = $this->scope->getOrCreateModel(); |
148 | - } elseif ($this->scope === true) |
|
149 | - $parent = \Seufert\Hamle\Scope::get(0); |
|
150 | - if ($this->filt && count($this->filt['tag'])) |
|
151 | - $parent = \Seufert\Hamle\Run::modelTypeTags( |
|
163 | + } elseif ($this->scope === true) { |
|
164 | + $parent = \Seufert\Hamle\Scope::get(0); |
|
165 | + } |
|
166 | + if ($this->filt && count($this->filt['tag'])) { |
|
167 | + $parent = \Seufert\Hamle\Run::modelTypeTags( |
|
152 | 168 | $this->filt['tag'], |
153 | 169 | $this->sortlimit['sort'], |
154 | 170 | $this->sortlimit['limit'], |
155 | 171 | $this->sortlimit['offset'] |
156 | 172 | ); |
157 | - if ($this->filt && count($this->filt['id'])) |
|
158 | - if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) === 1) |
|
173 | + } |
|
174 | + if ($this->filt && count($this->filt['id'])) { |
|
175 | + if (isset($this->filt['id']['*']) && count($this->filt['id']['*']) === 1) |
|
159 | 176 | $parent = \Seufert\Hamle\Run::modelId( |
160 | 177 | current($this->filt['id']['*']), |
161 | 178 | $this->sortlimit['sort'], |
162 | 179 | $this->sortlimit['limit'], |
163 | 180 | $this->sortlimit['offset'] |
164 | 181 | ); |
165 | - else |
|
166 | - $parent = \Seufert\Hamle\Run::modelTypeId( |
|
182 | + } else { |
|
183 | + $parent = \Seufert\Hamle\Run::modelTypeId( |
|
167 | 184 | $this->filt['id'], |
168 | 185 | $this->sortlimit['sort'], |
169 | 186 | $this->sortlimit['limit'], |
170 | 187 | $this->sortlimit['offset'] |
171 | 188 | ); |
172 | - if($this->sub) |
|
173 | - return $this->sub->getOrCreateModel($parent)->current(); |
|
174 | - if(!$parent) |
|
175 | - throw new \RuntimeException('Unable to create model with no relation'); |
|
189 | + } |
|
190 | + if($this->sub) { |
|
191 | + return $this->sub->getOrCreateModel($parent)->current(); |
|
192 | + } |
|
193 | + if(!$parent) { |
|
194 | + throw new \RuntimeException('Unable to create model with no relation'); |
|
195 | + } |
|
176 | 196 | return $parent->current(); |
177 | 197 | } |
178 | 198 |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | protected $filter; |
38 | 38 | |
39 | 39 | function __construct($s) { |
40 | - if(FALSE !== $pos = strpos($s,'|')) { |
|
41 | - $this->filter = new Filter(substr($s, $pos+1), $this); |
|
42 | - $s = substr($s,0,$pos); |
|
40 | + if (FALSE !== $pos = strpos($s, '|')) { |
|
41 | + $this->filter = new Filter(substr($s, $pos + 1), $this); |
|
42 | + $s = substr($s, 0, $pos); |
|
43 | 43 | } |
44 | 44 | $s = preg_split("/-[>!]/", $s); |
45 | 45 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
@@ -55,27 +55,27 @@ discard block |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | function toHTML($escape = false) { |
58 | - if($escape) |
|
59 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
60 | - return "<?=" . $this->toPHP() . "?>"; |
|
58 | + if ($escape) |
|
59 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
60 | + return "<?=".$this->toPHP()."?>"; |
|
61 | 61 | } |
62 | 62 | function toPHP() { |
63 | - return $this->filter?$this->filter->toPHP():$this->toPHPVar(); |
|
63 | + return $this->filter ? $this->filter->toPHP() : $this->toPHPVar(); |
|
64 | 64 | } |
65 | 65 | function toPHPVar() { |
66 | 66 | if ($this->sel) { |
67 | 67 | $sel = array(); |
68 | 68 | foreach ($this->sel as $s) |
69 | 69 | $sel[] = "hamleGet('$s')"; |
70 | - return $this->func->toPHP() . "->" . implode('->', $sel); |
|
70 | + return $this->func->toPHP()."->".implode('->', $sel); |
|
71 | 71 | } else |
72 | 72 | return $this->func->toPHP(); |
73 | 73 | } |
74 | 74 | |
75 | 75 | function getOrCreateModel(Model $parent = null) { |
76 | - if($this->func instanceof Text\Scope) |
|
76 | + if ($this->func instanceof Text\Scope) |
|
77 | 77 | return $this->func->getOrCreateModel($parent); |
78 | - if($this->func instanceof Text\Func) |
|
78 | + if ($this->func instanceof Text\Func) |
|
79 | 79 | return $this->func->getOrCreateModel($parent); |
80 | 80 | throw new RuntimeException('Unsupported func type encountered:'.get_class($this->func)); |
81 | 81 | } |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | * @return WriteModel |
86 | 86 | */ |
87 | 87 | function setValue($value) { |
88 | - if(!$this->sel || count($this->sel) != 1) |
|
88 | + if (!$this->sel || count($this->sel) != 1) |
|
89 | 89 | throw new RuntimeException('Can only set values, when one var name is present'); |
90 | 90 | $model = $this->getOrCreateModel(); |
91 | - if(!$model instanceof WriteModel) |
|
91 | + if (!$model instanceof WriteModel) |
|
92 | 92 | throw new RuntimeException('Can only set values on WriteModel, got '.get_class($model)); |
93 | 93 | $model->hamleSet($this->sel[0], $value); |
94 | 94 | return $model; |
@@ -43,20 +43,24 @@ discard block |
||
43 | 43 | } |
44 | 44 | $s = preg_split("/-[>!]/", $s); |
45 | 45 | // if(count($s) == 1) $s = explode("-!",$s[0]); |
46 | - if (!$s[0]) throw new ParseError("Unable to parse Complex Expression"); |
|
47 | - if ($s[0][1] === '(') |
|
48 | - $this->func = new Text\Func($s[0]); |
|
49 | - elseif ($s[0][1] === '[') |
|
50 | - $this->func = new Text\Scope($s[0]); |
|
51 | - else |
|
52 | - $this->func = new SimpleVar($s[0]); |
|
46 | + if (!$s[0]) { |
|
47 | + throw new ParseError("Unable to parse Complex Expression"); |
|
48 | + } |
|
49 | + if ($s[0][1] === '(') { |
|
50 | + $this->func = new Text\Func($s[0]); |
|
51 | + } elseif ($s[0][1] === '[') { |
|
52 | + $this->func = new Text\Scope($s[0]); |
|
53 | + } else { |
|
54 | + $this->func = new SimpleVar($s[0]); |
|
55 | + } |
|
53 | 56 | array_shift($s); |
54 | 57 | $this->sel = $s; |
55 | 58 | } |
56 | 59 | |
57 | 60 | function toHTML($escape = false) { |
58 | - if($escape) |
|
59 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
61 | + if($escape) { |
|
62 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
63 | + } |
|
60 | 64 | return "<?=" . $this->toPHP() . "?>"; |
61 | 65 | } |
62 | 66 | function toPHP() { |
@@ -65,18 +69,22 @@ discard block |
||
65 | 69 | function toPHPVar() { |
66 | 70 | if ($this->sel) { |
67 | 71 | $sel = array(); |
68 | - foreach ($this->sel as $s) |
|
69 | - $sel[] = "hamleGet('$s')"; |
|
72 | + foreach ($this->sel as $s) { |
|
73 | + $sel[] = "hamleGet('$s')"; |
|
74 | + } |
|
70 | 75 | return $this->func->toPHP() . "->" . implode('->', $sel); |
71 | - } else |
|
72 | - return $this->func->toPHP(); |
|
76 | + } else { |
|
77 | + return $this->func->toPHP(); |
|
78 | + } |
|
73 | 79 | } |
74 | 80 | |
75 | 81 | function getOrCreateModel(Model $parent = null) { |
76 | - if($this->func instanceof Text\Scope) |
|
77 | - return $this->func->getOrCreateModel($parent); |
|
78 | - if($this->func instanceof Text\Func) |
|
79 | - return $this->func->getOrCreateModel($parent); |
|
82 | + if($this->func instanceof Text\Scope) { |
|
83 | + return $this->func->getOrCreateModel($parent); |
|
84 | + } |
|
85 | + if($this->func instanceof Text\Func) { |
|
86 | + return $this->func->getOrCreateModel($parent); |
|
87 | + } |
|
80 | 88 | throw new RuntimeException('Unsupported func type encountered:'.get_class($this->func)); |
81 | 89 | } |
82 | 90 | |
@@ -85,11 +93,13 @@ discard block |
||
85 | 93 | * @return WriteModel |
86 | 94 | */ |
87 | 95 | function setValue($value) { |
88 | - if(!$this->sel || count($this->sel) != 1) |
|
89 | - throw new RuntimeException('Can only set values, when one var name is present'); |
|
96 | + if(!$this->sel || count($this->sel) != 1) { |
|
97 | + throw new RuntimeException('Can only set values, when one var name is present'); |
|
98 | + } |
|
90 | 99 | $model = $this->getOrCreateModel(); |
91 | - if(!$model instanceof WriteModel) |
|
92 | - throw new RuntimeException('Can only set values on WriteModel, got '.get_class($model)); |
|
100 | + if(!$model instanceof WriteModel) { |
|
101 | + throw new RuntimeException('Can only set values on WriteModel, got '.get_class($model)); |
|
102 | + } |
|
93 | 103 | $model->hamleSet($this->sel[0], $value); |
94 | 104 | return $model; |
95 | 105 | } |
@@ -45,8 +45,9 @@ |
||
45 | 45 | if ($this->escape) { |
46 | 46 | $parse = new H\Text($s, $strtype); |
47 | 47 | $this->content[] = $parse->toHTML($this->escapeVars); |
48 | - } else |
|
49 | - $this->content[] = $s; |
|
48 | + } else { |
|
49 | + $this->content[] = $s; |
|
50 | + } |
|
50 | 51 | } |
51 | 52 | } |
52 | 53 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | self::$namedScopes[$name] = $model; |
28 | 28 | else |
29 | 29 | self::$scopes[] = $model; |
30 | - if(self::$scopeHook) { |
|
30 | + if (self::$scopeHook) { |
|
31 | 31 | (self::$scopeHook)($model); |
32 | 32 | } |
33 | 33 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | self::$namedScopes[$name]->rewind(); |
74 | 74 | return self::$namedScopes[$name]; |
75 | 75 | } else |
76 | - if(self::$returnZeroOnNoScope) |
|
76 | + if (self::$returnZeroOnNoScope) |
|
77 | 77 | return new Model\Zero(); |
78 | 78 | throw new RunTime("Unable to find scope ($name)"); |
79 | 79 | } |
@@ -21,12 +21,14 @@ discard block |
||
21 | 21 | static $scopeHook; |
22 | 22 | |
23 | 23 | static function add($model, $name = null) { |
24 | - if (!$model instanceOf Model) |
|
25 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
26 | - if ($name) |
|
27 | - self::$namedScopes[$name] = $model; |
|
28 | - else |
|
29 | - self::$scopes[] = $model; |
|
24 | + if (!$model instanceOf Model) { |
|
25 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
26 | + } |
|
27 | + if ($name) { |
|
28 | + self::$namedScopes[$name] = $model; |
|
29 | + } else { |
|
30 | + self::$scopes[] = $model; |
|
31 | + } |
|
30 | 32 | if(self::$scopeHook) { |
31 | 33 | (self::$scopeHook)($model); |
32 | 34 | } |
@@ -47,15 +49,21 @@ discard block |
||
47 | 49 | */ |
48 | 50 | static function get($id = 0) { |
49 | 51 | if (0 == $id) { |
50 | - if ($scope = end(self::$scopes)) |
|
51 | - return $scope; |
|
52 | + if ($scope = end(self::$scopes)) { |
|
53 | + return $scope; |
|
54 | + } |
|
52 | 55 | throw new OutOfScope("Unable to find Scope ($id)"); |
53 | 56 | } |
54 | 57 | $key = $id - 1; |
55 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
56 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
57 | - if (!isset(self::$scopes[$key])) |
|
58 | - throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
58 | + if ($id < 0) { |
|
59 | + $key = count(self::$scopes) + $id - 1; |
|
60 | + } |
|
61 | + if ($id == 0) { |
|
62 | + $key = count(self::$scopes) - 1; |
|
63 | + } |
|
64 | + if (!isset(self::$scopes[$key])) { |
|
65 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
66 | + } |
|
59 | 67 | return self::$scopes[$key]; |
60 | 68 | } |
61 | 69 | |
@@ -73,8 +81,9 @@ discard block |
||
73 | 81 | self::$namedScopes[$name]->rewind(); |
74 | 82 | return self::$namedScopes[$name]; |
75 | 83 | } else |
76 | - if(self::$returnZeroOnNoScope) |
|
77 | - return new Model\Zero(); |
|
84 | + if(self::$returnZeroOnNoScope) { |
|
85 | + return new Model\Zero(); |
|
86 | + } |
|
78 | 87 | throw new RunTime("Unable to find scope ($name)"); |
79 | 88 | } |
80 | 89 |