@@ -161,11 +161,11 @@ |
||
161 | 161 | if( strlen($link) ){ |
162 | 162 | if( isset($this->config['target']) && ':'===$link{0} ){ |
163 | 163 | $this->setAttribute($this->config['link'],'javascript'.$link); |
164 | - }elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){ |
|
164 | + } elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){ |
|
165 | 165 | $this->setAttribute($this->config['link'],'http:'.$link); |
166 | - }elseif( '\\\\'===$firstTwoLetters ){ |
|
166 | + } elseif( '\\\\'===$firstTwoLetters ){ |
|
167 | 167 | $this->setAttribute($this->config['link'],'https://'.substr($link,2)); |
168 | - }else{ |
|
168 | + } else{ |
|
169 | 169 | $this->setAttribute($this->config['link'],$this->checkExpression($link)); |
170 | 170 | } |
171 | 171 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | $params= preg_split('/(?<!\\\\)\\|/',$this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/',1)); |
130 | 130 | |
131 | - if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("Tag $this->name has $n parameters $m given.");} |
|
131 | + if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("tag $this->name has $n parameters $m given.");} |
|
132 | 132 | |
133 | 133 | array_map(function( $key, $value ){return $this->setAttribute($key,str_replace('\\|','|',$value));},$this->config['params'],$params); |
134 | 134 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | protected function setAttribute( string$key, string$value, string$condition=null ):self |
283 | 283 | { |
284 | 284 | if( isset($this->attributes[$key]) ) |
285 | - { $this->document->throw("Attribute $key of $this->name cannot redeclare."); } |
|
285 | + { $this->document->throw("attribute $key of $this->name cannot redeclare."); } |
|
286 | 286 | |
287 | 287 | $this->attributes[$key]=[ |
288 | 288 | 'value'=> $value, |
@@ -90,7 +90,6 @@ |
||
90 | 90 | /** |
91 | 91 | * Close this tag node, and returning node closer. |
92 | 92 | * |
93 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
94 | 93 | * |
95 | 94 | * @return string |
96 | 95 | */ |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @var array |
32 | 32 | */ |
33 | - private $attributes=[]; |
|
33 | + private $attributes=[ ]; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Real constructor. |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | protected function construct():parent |
41 | 41 | { |
42 | 42 | |
43 | - $name= $this->line->pregGet('/(?<=^-)[\w-:]+/'); |
|
43 | + $name=$this->line->pregGet('/(?<=^-)[\w-:]+/'); |
|
44 | 44 | $this->name=$name; |
45 | 45 | |
46 | - $this->loadConfig($name,$this->document); |
|
46 | + $this->loadConfig($name, $this->document); |
|
47 | 47 | |
48 | - $this->tagName=$this->config['name']??$name; |
|
49 | - $this->isEmpty= $this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags',$this->tagName); |
|
50 | - isset($this->config['default_attributes']) and array_walk($this->config['default_attributes'],function( $value,$key ){ $this->setAttribute($key,$value); }); |
|
48 | + $this->tagName=$this->config[ 'name' ]??$name; |
|
49 | + $this->isEmpty=$this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags', $this->tagName); |
|
50 | + isset($this->config[ 'default_attributes' ]) and array_walk($this->config[ 'default_attributes' ], function( $value, $key ){ $this->setAttribute($key, $value); }); |
|
51 | 51 | |
52 | 52 | return $this; |
53 | 53 | } |
@@ -59,30 +59,30 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function open():string |
61 | 61 | { |
62 | - if( isset($this->config['opener']) ) |
|
63 | - { return $this->config['opener']; } |
|
62 | + if( isset($this->config[ 'opener' ]) ) |
|
63 | + { return $this->config[ 'opener' ]; } |
|
64 | 64 | |
65 | - if( isset($this->config['params']) ) |
|
65 | + if( isset($this->config[ 'params' ]) ) |
|
66 | 66 | { $this->parseParams(); } |
67 | 67 | |
68 | - if( isset($this->config['name_value']) ) |
|
68 | + if( isset($this->config[ 'name_value' ]) ) |
|
69 | 69 | { $this->parseNameValue(); } |
70 | 70 | |
71 | - if( isset($this->config['link']) ) |
|
71 | + if( isset($this->config[ 'link' ]) ) |
|
72 | 72 | { $this->parseLink(); } |
73 | 73 | |
74 | - if( isset($this->config['target']) ) |
|
74 | + if( isset($this->config[ 'target' ]) ) |
|
75 | 75 | { $this->parseTarget(); } |
76 | 76 | |
77 | - if( isset($this->config['alt']) ) |
|
77 | + if( isset($this->config[ 'alt' ]) ) |
|
78 | 78 | { $this->parseAlt(); } |
79 | 79 | |
80 | 80 | $this->parseCommonAttributes(); |
81 | 81 | |
82 | - if( isset($this->config['in_scope']) && isset($this->config['scope_function']) && is_callable($this->config['scope_function']) ) |
|
83 | - { $this->config['scope_function']->call($this,$this->document->scope); } |
|
82 | + if( isset($this->config[ 'in_scope' ]) && isset($this->config[ 'scope_function' ]) && is_callable($this->config[ 'scope_function' ]) ) |
|
83 | + { $this->config[ 'scope_function' ]->call($this, $this->document->scope); } |
|
84 | 84 | |
85 | - $finisher= $this->isEmpty ? ' />' : '>'; |
|
85 | + $finisher=$this->isEmpty? ' />' : '>'; |
|
86 | 86 | |
87 | 87 | return "<{$this->tagName}{$this->attributesString}{$finisher}"; |
88 | 88 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function close( Line$Line ):string |
98 | 98 | { |
99 | - return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>"; |
|
99 | + return $this->isEmpty? '' : $this->config[ 'closer' ]??"</{$this->tagName}>"; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function getEmbed():string |
108 | 108 | { |
109 | - return $this->config['embedding']??''; |
|
109 | + return $this->config[ 'embedding' ]??''; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function getScope() |
118 | 118 | { |
119 | - return $this->config['scope']??null; |
|
119 | + return $this->config[ 'scope' ]??null; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function parseParams():self |
128 | 128 | { |
129 | - $params= preg_split('/(?<!\\\\)\\|/',$this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/',1)); |
|
129 | + $params=preg_split('/(?<!\\\\)\\|/', $this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/', 1)); |
|
130 | 130 | |
131 | - if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("Tag $this->name has $n parameters $m given.");} |
|
131 | + if( ($m=count($params))!=($n=count($this->config[ 'params' ])) ){$this->document->throw("Tag $this->name has $n parameters $m given."); } |
|
132 | 132 | |
133 | - array_map(function( $key, $value ){return $this->setAttribute($key,str_replace('\\|','|',$value));},$this->config['params'],$params); |
|
133 | + array_map(function( $key, $value ){return $this->setAttribute($key, str_replace('\\|', '|', $value)); },$this->config[ 'params' ], $params); |
|
134 | 134 | |
135 | 135 | return $this; |
136 | 136 | } |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | */ |
143 | 143 | protected function parseNameValue():self |
144 | 144 | { |
145 | - $params= $this->line->pregGet('/ <(.*?)>(?= |$)/',1) |
|
146 | - and $params= preg_split('/(?<!\\\\)\\|/',$params) |
|
147 | - and array_map(function( $key, $value ){return isset($key)&&isset($value) ? $this->setAttribute($key,$this->checkExpression(str_replace('\\|','|',$value))) : '';},$this->config['name_value'],$params); |
|
145 | + $params=$this->line->pregGet('/ <(.*?)>(?= |$)/', 1) |
|
146 | + and $params=preg_split('/(?<!\\\\)\\|/', $params) |
|
147 | + and array_map(function( $key, $value ){return isset($key) && isset($value)? $this->setAttribute($key, $this->checkExpression(str_replace('\\|', '|', $value))) : ''; },$this->config[ 'name_value' ], $params); |
|
148 | 148 | |
149 | 149 | return $this; |
150 | 150 | } |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | */ |
157 | 157 | protected function parseLink():self |
158 | 158 | { |
159 | - $link= $this->line->pregGet('/ @((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/',1); |
|
159 | + $link=$this->line->pregGet('/ @((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1); |
|
160 | 160 | |
161 | 161 | if( strlen($link) ){ |
162 | - if( isset($this->config['target']) && ':'===$link{0} ){ |
|
163 | - $this->setAttribute($this->config['link'],'javascript'.$link); |
|
164 | - }elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){ |
|
165 | - $this->setAttribute($this->config['link'],'http:'.$link); |
|
162 | + if( isset($this->config[ 'target' ]) && ':'===$link{0} ){ |
|
163 | + $this->setAttribute($this->config[ 'link' ], 'javascript'.$link); |
|
164 | + }elseif( '//'===($firstTwoLetters=substr($link, 0, 2)) ){ |
|
165 | + $this->setAttribute($this->config[ 'link' ], 'http:'.$link); |
|
166 | 166 | }elseif( '\\\\'===$firstTwoLetters ){ |
167 | - $this->setAttribute($this->config['link'],'https://'.substr($link,2)); |
|
167 | + $this->setAttribute($this->config[ 'link' ], 'https://'.substr($link, 2)); |
|
168 | 168 | }else{ |
169 | - $this->setAttribute($this->config['link'],$this->checkExpression($link)); |
|
169 | + $this->setAttribute($this->config[ 'link' ], $this->checkExpression($link)); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function parseTarget():self |
182 | 182 | { |
183 | - $target= $this->line->pregGet('/ >((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/',1); |
|
183 | + $target=$this->line->pregGet('/ >((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1); |
|
184 | 184 | |
185 | 185 | if( strlen($target) ){ |
186 | - $this->setAttribute($this->config['target'],$this->checkExpression($target)); |
|
186 | + $this->setAttribute($this->config[ 'target' ], $this->checkExpression($target)); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | return $this; |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | */ |
197 | 197 | protected function parseAlt():self |
198 | 198 | { |
199 | - $alt= $this->line->pregGet('/ _((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/',1); |
|
199 | + $alt=$this->line->pregGet('/ _((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1); |
|
200 | 200 | |
201 | 201 | if( strlen($alt) ){ |
202 | - $this->setAttribute($this->config['alt'],$this->checkExpression($alt)); |
|
202 | + $this->setAttribute($this->config[ 'alt' ], $this->checkExpression($alt)); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $this; |
@@ -212,33 +212,33 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function parseCommonAttributes():string |
214 | 214 | { |
215 | - $attributes= ''; |
|
215 | + $attributes=''; |
|
216 | 216 | |
217 | - $id= $this->line->pregGet('/ #([^ ]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/',1) |
|
218 | - and $this->setAttribute('id',$id); |
|
217 | + $id=$this->line->pregGet('/ #([^ ]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1) |
|
218 | + and $this->setAttribute('id', $id); |
|
219 | 219 | |
220 | - $classes= $this->line->pregGet('/ \.[^ ]+(?= |$)/') |
|
221 | - and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/',$classes,$matches) |
|
222 | - and $classes= implode(' ',array_filter(array_map(function( $className ){return $this->checkExpression($className);},$matches[1]))) |
|
223 | - and $this->setAttribute('class',$classes); |
|
220 | + $classes=$this->line->pregGet('/ \.[^ ]+(?= |$)/') |
|
221 | + and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/', $classes, $matches) |
|
222 | + and $classes=implode(' ', array_filter(array_map(function( $className ){return $this->checkExpression($className); },$matches[ 1 ]))) |
|
223 | + and $this->setAttribute('class', $classes); |
|
224 | 224 | |
225 | - $title= $this->line->pregGet('/ \^((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/',1) |
|
226 | - and $this->setAttribute('title',$title); |
|
225 | + $title=$this->line->pregGet('/ \^((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1) |
|
226 | + and $this->setAttribute('title', $title); |
|
227 | 227 | |
228 | - $style= $this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/',1) |
|
229 | - and $this->setAttribute('style',$style); |
|
228 | + $style=$this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/', 1) |
|
229 | + and $this->setAttribute('style', $style); |
|
230 | 230 | |
231 | - $eventListeners= $this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/',function( $string, $name, $code ){ |
|
232 | - $this->setAttribute('on'.$name,str_replace('"','"',$code)); |
|
231 | + $eventListeners=$this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/', function( $string, $name, $code ){ |
|
232 | + $this->setAttribute('on'.$name, str_replace('"', '"', $code)); |
|
233 | 233 | }) |
234 | - and implode('',$eventListeners); |
|
234 | + and implode('', $eventListeners); |
|
235 | 235 | |
236 | - $other= $this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
236 | + $other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
237 | 237 | and array_map(function( $keyValue ){ |
238 | - preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/',function($matches){ |
|
239 | - $this->setAttribute($matches[1],($matches[3]??$matches[1])?:$matches[1],$matches[2]??null); |
|
238 | + preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/', function( $matches ){ |
|
239 | + $this->setAttribute($matches[ 1 ], ($matches[ 3 ]??$matches[ 1 ])?: $matches[ 1 ], $matches[ 2 ]??null); |
|
240 | 240 | },$keyValue); |
241 | - },explode(';',$other)); |
|
241 | + },explode(';', $other)); |
|
242 | 242 | |
243 | 243 | return $attributes; |
244 | 244 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | protected function checkExpression( string$value ):string |
254 | 254 | { |
255 | - return preg_match('/^\(.*\)$/',$value) ? '<?='.substr($value,1,-1).'?>' : str_replace('"','"',$value); |
|
255 | + return preg_match('/^\(.*\)$/', $value)? '<?='.substr($value, 1, -1).'?>' : str_replace('"', '"', $value); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -263,13 +263,13 @@ discard block |
||
263 | 263 | protected function getAttributesString():string |
264 | 264 | { |
265 | 265 | ksort($this->attributes); |
266 | - return implode('',array_map(static function( string$key, array$data ){ |
|
267 | - return (isset($data['condition'])&&strlen($data['condition'])? |
|
268 | - "<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>" |
|
266 | + return implode('', array_map(static function( string$key, array$data ){ |
|
267 | + return (isset($data[ 'condition' ]) && strlen($data[ 'condition' ])? |
|
268 | + "<?php if( {$data[ 'condition' ]} ){?> $key=\"{$data[ 'value' ]}\"<?php }?>" |
|
269 | 269 | : |
270 | - " $key=\"{$data['value']}\"" |
|
270 | + " $key=\"{$data[ 'value' ]}\"" |
|
271 | 271 | ); |
272 | - },array_keys($this->attributes),$this->attributes)); |
|
272 | + },array_keys($this->attributes), $this->attributes)); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,10 +281,10 @@ discard block |
||
281 | 281 | */ |
282 | 282 | protected function setAttribute( string$key, string$value, string$condition=null ):self |
283 | 283 | { |
284 | - if( isset($this->attributes[$key]) ) |
|
284 | + if( isset($this->attributes[ $key ]) ) |
|
285 | 285 | { $this->document->throw("Attribute $key of $this->name cannot redeclare."); } |
286 | 286 | |
287 | - $this->attributes[$key]=[ |
|
287 | + $this->attributes[ $key ]=[ |
|
288 | 288 | 'value'=> $value, |
289 | 289 | 'condition'=> $condition, |
290 | 290 | ]; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function offsetExists( $offset ):bool |
308 | 308 | { |
309 | - return isset($this->attributes[$offset]); |
|
309 | + return isset($this->attributes[ $offset ]); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public function offsetGet( $offset ) |
320 | 320 | { |
321 | - return $this->attributes[$offset]??null; |
|
321 | + return $this->attributes[ $offset ]??null; |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public function offsetSet( $offset, $value ) |
331 | 331 | { |
332 | - $this->setAttribute($offset,$value); |
|
332 | + $this->setAttribute($offset, $value); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function offsetUnset( $offset ) |
341 | 341 | { |
342 | - if( isset($this->attributes[$offset]) ) |
|
343 | - { unset($this->attributes[$offset]); } |
|
342 | + if( isset($this->attributes[ $offset ]) ) |
|
343 | + { unset($this->attributes[ $offset ]); } |
|
344 | 344 | } |
345 | 345 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | public function __get( $attribute ) |
17 | 17 | { |
18 | - if( is_callable([static::class, $getter= 'get'.implode('',array_map('ucfirst',explode('_',$attribute))),]) ){ |
|
18 | + if( is_callable([ static::class, $getter='get'.implode('', array_map('ucfirst', explode('_', $attribute))), ]) ){ |
|
19 | 19 | return static::$getter(); |
20 | 20 | }else{ |
21 | 21 | throw new \Exception(static::class.' has no attribute named '.$attribute); |
@@ -16,7 +16,7 @@ |
||
16 | 16 | { |
17 | 17 | if( is_callable([static::class, $setter= 'set'.implode('',array_map('ucfirst',explode('_',$attribute))),]) ){ |
18 | 18 | return static::$setter($value); |
19 | - }else{ |
|
19 | + } else{ |
|
20 | 20 | throw new \Exception(static::class.' has no attribute named '.$attribute); |
21 | 21 | } |
22 | 22 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | public function __construct( string$name=null ) |
33 | 33 | { |
34 | - $this->name = $name; |
|
34 | + $this->name=$name; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -25,7 +25,7 @@ |
||
25 | 25 | */ |
26 | 26 | protected function construct():parent |
27 | 27 | { |
28 | - $this->name= null; |
|
28 | + $this->name=null; |
|
29 | 29 | |
30 | 30 | return $this; |
31 | 31 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | */ |
26 | 26 | protected function construct():parent |
27 | 27 | { |
28 | - $this->name= $this->line->pregGet('/(?<=\( ).*(?= \))/'); |
|
28 | + $this->name=$this->line->pregGet('/(?<=\( ).*(?= \))/'); |
|
29 | 29 | |
30 | 30 | return $this; |
31 | 31 | } |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function construct():parent |
40 | 40 | { |
41 | - $name= $this->line->pregGet('/(?<=^~)[\w-]*/'); |
|
41 | + $name=$this->line->pregGet('/(?<=^~)[\w-]*/'); |
|
42 | 42 | $this->name=$name; |
43 | 43 | |
44 | - $this->loadConfig($name,$this->htsl); |
|
44 | + $this->loadConfig($name, $this->htsl); |
|
45 | 45 | |
46 | - $this->param= $this->line->pregGet('/^~[\w-]*\( (.*) \)/',1); |
|
46 | + $this->param=$this->line->pregGet('/^~[\w-]*\( (.*) \)/', 1); |
|
47 | 47 | |
48 | - $this->structureName=$this->config['name']??$name; |
|
48 | + $this->structureName=$this->config[ 'name' ]??$name; |
|
49 | 49 | |
50 | 50 | $this->id=strtoupper(uniqid()); |
51 | 51 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function open():string |
61 | 61 | { |
62 | - return $this->withParam($this->config['opener']); |
|
62 | + return $this->withParam($this->config[ 'opener' ]); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function getScope() |
71 | 71 | { |
72 | - return $this->config['scope']??null; |
|
72 | + return $this->config[ 'scope' ]??null; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function close( Line$closerLine ):string |
84 | 84 | { |
85 | - if( isset($this->config['close_by']) && $closerLine->indentLevel==$this->line->indentLevel ){ |
|
86 | - foreach( $this->config['close_by'] as $key=>$value ){ |
|
85 | + if( isset($this->config[ 'close_by' ]) && $closerLine->indentLevel==$this->line->indentLevel ){ |
|
86 | + foreach( $this->config[ 'close_by' ] as $key=>$value ){ |
|
87 | 87 | if( $closerLine->pregMatch($key) ){ |
88 | 88 | return $this->withParam($value); |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - if( isset($this->config['closer']) ) |
|
94 | - { return $this->withParam($this->config['closer']); } |
|
93 | + if( isset($this->config[ 'closer' ]) ) |
|
94 | + { return $this->withParam($this->config[ 'closer' ]); } |
|
95 | 95 | |
96 | 96 | return ''; |
97 | 97 | } |
@@ -105,23 +105,23 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function withParam( string$input ) |
107 | 107 | { |
108 | - return str_replace('$_FLAG_$',"__HTSL_CTRL_FLAG_{$this->id}__",preg_replace_callback('/(?<!%)%s((?:\\/.+?(?<!\\\\)\\/.+?(?<!\\\\)\\/)+)?/',function( array$matches ){ |
|
109 | - $param= $this->param; |
|
108 | + return str_replace('$_FLAG_$', "__HTSL_CTRL_FLAG_{$this->id}__", preg_replace_callback('/(?<!%)%s((?:\\/.+?(?<!\\\\)\\/.+?(?<!\\\\)\\/)+)?/', function( array$matches ){ |
|
109 | + $param=$this->param; |
|
110 | 110 | |
111 | - if( isset($matches[1]) ){ |
|
111 | + if( isset($matches[ 1 ]) ){ |
|
112 | 112 | array_map(...[ |
113 | - function($replacer)use(&$param){ |
|
114 | - list($pattern,$replacement,)= preg_split('/(?<!\\\\)\\//',$replacer); |
|
115 | - $param= preg_replace(...[ |
|
113 | + function( $replacer )use(&$param){ |
|
114 | + list($pattern, $replacement,)=preg_split('/(?<!\\\\)\\//', $replacer); |
|
115 | + $param=preg_replace(...[ |
|
116 | 116 | "/$pattern/", |
117 | - preg_replace('/^\\\\_$/','',$replacement), |
|
117 | + preg_replace('/^\\\\_$/', '', $replacement), |
|
118 | 118 | $param, |
119 | 119 | ]); |
120 | 120 | }, |
121 | 121 | preg_split( |
122 | 122 | '/(?<!\\\\)\\/\\//' |
123 | 123 | , |
124 | - trim($matches[1],'/') |
|
124 | + trim($matches[ 1 ], '/') |
|
125 | 125 | ), |
126 | 126 | ]); |
127 | 127 | } |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct( Htsl$htsl, string$filePath ) |
25 | 25 | { |
26 | - substr($filePath,-5)==='.htsl' or $filePath.= '.htsl'; |
|
26 | + substr($filePath, -5)==='.htsl' or $filePath.='.htsl'; |
|
27 | 27 | |
28 | 28 | if( !file_exists($filePath) || !is_file($filePath) ){ |
29 | 29 | throw new \Exception("File $filePath not exists.", 1); |
30 | 30 | } |
31 | 31 | |
32 | - $this->filePath= $filePath; |
|
32 | + $this->filePath=$filePath; |
|
33 | 33 | |
34 | - $this->handle= fopen($filePath,'r'); |
|
34 | + $this->handle=fopen($filePath, 'r'); |
|
35 | 35 | |
36 | 36 | parent::__construct($htsl); |
37 | 37 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function getLine():Line |
53 | 53 | { |
54 | - while( "\n"===$content= fgets($this->handle) ); |
|
54 | + while( "\n"===$content=fgets($this->handle) ); |
|
55 | 55 | |
56 | 56 | return new Line($content); |
57 | 57 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function goSide( $filePath ):parent |
67 | 67 | { |
68 | - $filePath= $this->htsl->getFilePath($filePath,dirname($this->filePath)); |
|
68 | + $filePath=$this->htsl->getFilePath($filePath, dirname($this->filePath)); |
|
69 | 69 | |
70 | - return new static($this->htsl,$filePath); |
|
70 | + return new static($this->htsl, $filePath); |
|
71 | 71 | } |
72 | 72 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | substr($filePath,-5)==='.htsl' or $filePath.= '.htsl'; |
27 | 27 | |
28 | 28 | if( !file_exists($filePath) || !is_file($filePath) ){ |
29 | - throw new \Exception("File $filePath not exists.", 1); |
|
29 | + throw new \Exception("file $filePath not exists.", 1); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $this->filePath= $filePath; |
@@ -23,11 +23,11 @@ |
||
23 | 23 | * |
24 | 24 | * @var string |
25 | 25 | */ |
26 | - protected $fileName= ''; |
|
26 | + protected $fileName=''; |
|
27 | 27 | |
28 | 28 | public function __construct( Htsl$htsl ) |
29 | 29 | { |
30 | - $this->htsl= $htsl; |
|
30 | + $this->htsl=$htsl; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct( Htsl$htsl, string$content, string$filePath='' ) |
26 | 26 | { |
27 | - if( false!==strpos($content,"\r") ){ |
|
27 | + if( false!==strpos($content, "\r") ){ |
|
28 | 28 | throw new \Exception("Line ending must be LF.", 1); |
29 | 29 | } |
30 | 30 | |
31 | - $this->filePath= $filePath; |
|
31 | + $this->filePath=$filePath; |
|
32 | 32 | |
33 | - $this->lines= array_filter(explode("\n",$content),'strlen'); |
|
34 | - array_unshift($this->lines,null); |
|
33 | + $this->lines=array_filter(explode("\n", $content), 'strlen'); |
|
34 | + array_unshift($this->lines, null); |
|
35 | 35 | |
36 | 36 | parent::__construct($htsl); |
37 | 37 | } |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function goSide( $filePath ):parent |
57 | 57 | { |
58 | - $filePath= $this->htsl->getFilePath($filePath,dirname($this->filePath)); |
|
59 | - $content= $this->htsl->getFileContent($filePath); |
|
58 | + $filePath=$this->htsl->getFilePath($filePath, dirname($this->filePath)); |
|
59 | + $content=$this->htsl->getFileContent($filePath); |
|
60 | 60 | |
61 | - return new static($this->htsl,$content,$filePath); |
|
61 | + return new static($this->htsl, $content, $filePath); |
|
62 | 62 | } |
63 | 63 | } |