@@ -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, |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @var array |
52 | 52 | */ |
53 | - private $attributes=[]; |
|
53 | + private $attributes=[ ]; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Real constructor. |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | protected function construct():parent |
63 | 63 | { |
64 | 64 | |
65 | - $name= $this->line->pregGet('/(?<=^-)[\w-:]+/'); |
|
65 | + $name=$this->line->pregGet('/(?<=^-)[\w-:]+/'); |
|
66 | 66 | $this->name=$name; |
67 | 67 | |
68 | - $this->loadConfig($name,$this->document); |
|
68 | + $this->loadConfig($name, $this->document); |
|
69 | 69 | |
70 | - $this->tagName=$this->config['name']??$name; |
|
71 | - $this->isEmpty= $this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags',$this->tagName); |
|
72 | - isset($this->config['default_attributes']) and array_walk($this->config['default_attributes'],function( $value,$key ){ $this->setAttribute($key,$value); }); |
|
70 | + $this->tagName=$this->config[ 'name' ]??$name; |
|
71 | + $this->isEmpty=$this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags', $this->tagName); |
|
72 | + isset($this->config[ 'default_attributes' ]) and array_walk($this->config[ 'default_attributes' ], function( $value, $key ){ $this->setAttribute($key, $value); }); |
|
73 | 73 | |
74 | 74 | return $this; |
75 | 75 | } |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function open():string |
85 | 85 | { |
86 | - if( isset($this->config['opener']) ) |
|
87 | - { return $this->config['opener']; } |
|
86 | + if( isset($this->config[ 'opener' ]) ) |
|
87 | + { return $this->config[ 'opener' ]; } |
|
88 | 88 | |
89 | 89 | $this->parsePrivateAttributes(); |
90 | 90 | $this->parseCommonAttributes(); |
91 | 91 | |
92 | - if( isset($this->config['in_scope']) && isset($this->config['scope_function']) && is_callable($this->config['scope_function']) ) |
|
93 | - { $this->config['scope_function']->call($this,$this->document->scope); } |
|
92 | + if( isset($this->config[ 'in_scope' ]) && isset($this->config[ 'scope_function' ]) && is_callable($this->config[ 'scope_function' ]) ) |
|
93 | + { $this->config[ 'scope_function' ]->call($this, $this->document->scope); } |
|
94 | 94 | |
95 | - $finisher= $this->isEmpty ? ' />' : '>'; |
|
95 | + $finisher=$this->isEmpty? ' />' : '>'; |
|
96 | 96 | |
97 | 97 | return "<{$this->tagName}{$this->attributesString}{$finisher}"; |
98 | 98 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function close( Line$closerLine ):string |
110 | 110 | { |
111 | - return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>"; |
|
111 | + return $this->isEmpty? '' : $this->config[ 'closer' ]??"</{$this->tagName}>"; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getEmbed():string |
122 | 122 | { |
123 | - return $this->config['embedding']??''; |
|
123 | + return $this->config[ 'embedding' ]??''; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function getScope() |
134 | 134 | { |
135 | - return $this->config['scope']??null; |
|
135 | + return $this->config[ 'scope' ]??null; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | protected function parsePrivateAttributes():self |
146 | 146 | { |
147 | 147 | foreach( self::PRIVATE_ATTRIBUTES as $attribute ){ |
148 | - isset($this->config[$attribute]) and $this->{'parse'.Helper\camel_case($attribute)}(); |
|
148 | + isset($this->config[ $attribute ]) and $this->{'parse'.Helper\camel_case($attribute)}(); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $this; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @todo Make this const private when php 7.1 |
162 | 162 | */ |
163 | - const PRIVATE_ATTRIBUTES= [ |
|
163 | + const PRIVATE_ATTRIBUTES=[ |
|
164 | 164 | 'params', |
165 | 165 | 'name_value', |
166 | 166 | 'link', |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected function parseParams():self |
179 | 179 | { |
180 | - $params= preg_split('/(?<!\\\\)\\|/',$this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/',1)); |
|
180 | + $params=preg_split('/(?<!\\\\)\\|/', $this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/', 1)); |
|
181 | 181 | |
182 | - if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("Tag $this->name has $n parameters $m given.");} |
|
182 | + if( ($m=count($params))!=($n=count($this->config[ 'params' ])) ){$this->document->throw("Tag $this->name has $n parameters $m given."); } |
|
183 | 183 | |
184 | - array_map(function( $key, $value ){return $this->setAttribute($key,str_replace('\\|','|',$value));},$this->config['params'],$params); |
|
184 | + array_map(function( $key, $value ){return $this->setAttribute($key, str_replace('\\|', '|', $value)); },$this->config[ 'params' ], $params); |
|
185 | 185 | |
186 | 186 | return $this; |
187 | 187 | } |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | */ |
196 | 196 | protected function parseNameValue():self |
197 | 197 | { |
198 | - $params= $this->line->pregGet('/ <(.*?)>(?= |$)/',1) |
|
199 | - and $params= preg_split('/(?<!\\\\)\\|/',$params) |
|
200 | - and array_map(function( $key, $value ){return isset($key)&&isset($value) ? $this->setAttribute($key,$this->checkExpression(str_replace('\\|','|',$value))) : '';},$this->config['name_value'],$params); |
|
198 | + $params=$this->line->pregGet('/ <(.*?)>(?= |$)/', 1) |
|
199 | + and $params=preg_split('/(?<!\\\\)\\|/', $params) |
|
200 | + and array_map(function( $key, $value ){return isset($key) && isset($value)? $this->setAttribute($key, $this->checkExpression(str_replace('\\|', '|', $value))) : ''; },$this->config[ 'name_value' ], $params); |
|
201 | 201 | |
202 | 202 | return $this; |
203 | 203 | } |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | */ |
240 | 240 | protected function parseLink():self |
241 | 241 | { |
242 | - return $this->setMultinameAttribute('link',$this->sectionLedBy('@',true),function( string$link ){ |
|
243 | - if( isset($this->config['target']) && ':'===$link{0} ){ |
|
242 | + return $this->setMultinameAttribute('link', $this->sectionLedBy('@', true), function( string$link ){ |
|
243 | + if( isset($this->config[ 'target' ]) && ':'===$link{0} ){ |
|
244 | 244 | return 'javascript'.$link; |
245 | - }elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){ |
|
245 | + }elseif( '//'===($firstTwoLetters=substr($link, 0, 2)) ){ |
|
246 | 246 | return 'http:'.$link; |
247 | 247 | }elseif( '\\\\'===$firstTwoLetters ){ |
248 | - return 'https://'.substr($link,2); |
|
248 | + return 'https://'.substr($link, 2); |
|
249 | 249 | }else{ |
250 | 250 | return $this->checkExpression($link); |
251 | 251 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | protected function parseTarget():self |
263 | 263 | { |
264 | - return $this->setMultinameAttribute('target',$this->sectionLedBy('>',true)); |
|
264 | + return $this->setMultinameAttribute('target', $this->sectionLedBy('>', true)); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | protected function parseAlt():self |
275 | 275 | { |
276 | - return $this->setMultinameAttribute('alt',$this->sectionLedBy('_',true)); |
|
276 | + return $this->setMultinameAttribute('alt', $this->sectionLedBy('_', true)); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -289,8 +289,8 @@ discard block |
||
289 | 289 | */ |
290 | 290 | private function setMultinameAttribute( string$name, string$value, callable$processer=null ):self |
291 | 291 | { |
292 | - if( strlen($value) && !empty($this->config[$name]) ){ |
|
293 | - return $this->setAttribute($this->config[$name],call_user_func($processer??[$this,'checkExpression',],$value)); |
|
292 | + if( strlen($value) && !empty($this->config[ $name ]) ){ |
|
293 | + return $this->setAttribute($this->config[ $name ], call_user_func($processer??[ $this, 'checkExpression', ], $value)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | return $this; |
@@ -305,33 +305,33 @@ discard block |
||
305 | 305 | */ |
306 | 306 | protected function parseCommonAttributes():string |
307 | 307 | { |
308 | - $attributes= ''; |
|
308 | + $attributes=''; |
|
309 | 309 | |
310 | - $id= $this->sectionLedBy('#') |
|
311 | - and $this->setAttribute('id',$id); |
|
310 | + $id=$this->sectionLedBy('#') |
|
311 | + and $this->setAttribute('id', $id); |
|
312 | 312 | |
313 | - $classes= $this->line->pregGet('/ \.[^ ]+(?= |$)/') |
|
314 | - and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/',$classes,$matches) |
|
315 | - and $classes= implode(' ',array_filter(array_map(function( $className ){return $this->checkExpression($className);},$matches[1]))) |
|
316 | - and $this->setAttribute('class',$classes); |
|
313 | + $classes=$this->line->pregGet('/ \.[^ ]+(?= |$)/') |
|
314 | + and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/', $classes, $matches) |
|
315 | + and $classes=implode(' ', array_filter(array_map(function( $className ){return $this->checkExpression($className); },$matches[ 1 ]))) |
|
316 | + and $this->setAttribute('class', $classes); |
|
317 | 317 | |
318 | - $title= $this->sectionLedBy('^',true) |
|
319 | - and $this->setAttribute('title',$title); |
|
318 | + $title=$this->sectionLedBy('^', true) |
|
319 | + and $this->setAttribute('title', $title); |
|
320 | 320 | |
321 | - $style= $this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/',1) |
|
322 | - and $this->setAttribute('style',$style); |
|
321 | + $style=$this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/', 1) |
|
322 | + and $this->setAttribute('style', $style); |
|
323 | 323 | |
324 | - $eventListeners= $this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/',function( $string, $name, $code ){ |
|
325 | - $this->setAttribute('on'.$name,str_replace('"','"',$code)); |
|
324 | + $eventListeners=$this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/', function( $string, $name, $code ){ |
|
325 | + $this->setAttribute('on'.$name, str_replace('"', '"', $code)); |
|
326 | 326 | }) |
327 | - and implode('',$eventListeners); |
|
327 | + and implode('', $eventListeners); |
|
328 | 328 | |
329 | - $other= $this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
329 | + $other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
330 | 330 | and array_map(function( $keyValue ){ |
331 | - preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/',function($matches){ |
|
332 | - $this->setAttribute($matches[1],($matches[3]??$matches[1])?:$matches[1],$matches[2]??null); |
|
331 | + preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/', function( $matches ){ |
|
332 | + $this->setAttribute($matches[ 1 ], ($matches[ 3 ]??$matches[ 1 ])?: $matches[ 1 ], $matches[ 2 ]??null); |
|
333 | 333 | },$keyValue); |
334 | - },explode(';',$other)); |
|
334 | + },explode(';', $other)); |
|
335 | 335 | |
336 | 336 | return $attributes; |
337 | 337 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | protected function checkExpression( string$value ):string |
349 | 349 | { |
350 | - return preg_match('/^\(.*\)$/',$value) ? '<?=str_replace(\'"\',\'"\','.substr($value,1,-1).')?>' : str_replace('"','"',$value); |
|
350 | + return preg_match('/^\(.*\)$/', $value)? '<?=str_replace(\'"\',\'"\','.substr($value, 1, -1).')?>' : str_replace('"', '"', $value); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -360,13 +360,13 @@ discard block |
||
360 | 360 | protected function getAttributesString():string |
361 | 361 | { |
362 | 362 | ksort($this->attributes); |
363 | - return implode('',array_map(static function( string$key, array$data ){ |
|
364 | - return (isset($data['condition'])&&strlen($data['condition'])? |
|
365 | - "<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>" |
|
363 | + return implode('', array_map(static function( string$key, array$data ){ |
|
364 | + return (isset($data[ 'condition' ]) && strlen($data[ 'condition' ])? |
|
365 | + "<?php if( {$data[ 'condition' ]} ){?> $key=\"{$data[ 'value' ]}\"<?php }?>" |
|
366 | 366 | : |
367 | - " $key=\"{$data['value']}\"" |
|
367 | + " $key=\"{$data[ 'value' ]}\"" |
|
368 | 368 | ); |
369 | - },array_keys($this->attributes),$this->attributes)); |
|
369 | + },array_keys($this->attributes), $this->attributes)); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -380,10 +380,10 @@ discard block |
||
380 | 380 | */ |
381 | 381 | protected function setAttribute( string$key, string$value, string$condition=null ):self |
382 | 382 | { |
383 | - if( isset($this->attributes[$key]) ) |
|
383 | + if( isset($this->attributes[ $key ]) ) |
|
384 | 384 | { $this->document->throw("Attribute $key of $this->name cannot redeclare."); } |
385 | 385 | |
386 | - $this->attributes[$key]=[ |
|
386 | + $this->attributes[ $key ]=[ |
|
387 | 387 | 'value'=> $value, |
388 | 388 | 'condition'=> $condition, |
389 | 389 | ]; |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public function offsetExists( $offset ):bool |
409 | 409 | { |
410 | - return isset($this->attributes[$offset]); |
|
410 | + return isset($this->attributes[ $offset ]); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | */ |
422 | 422 | public function offsetGet( $offset ) |
423 | 423 | { |
424 | - return $this->attributes[$offset]??null; |
|
424 | + return $this->attributes[ $offset ]??null; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function offsetSet( $offset, $value ) |
436 | 436 | { |
437 | - $this->setAttribute($offset,$value); |
|
437 | + $this->setAttribute($offset, $value); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | */ |
447 | 447 | public function offsetUnset( $offset ) |
448 | 448 | { |
449 | - if( isset($this->attributes[$offset]) ) |
|
450 | - { unset($this->attributes[$offset]); } |
|
449 | + if( isset($this->attributes[ $offset ]) ) |
|
450 | + { unset($this->attributes[ $offset ]); } |
|
451 | 451 | } |
452 | 452 | } |
@@ -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 | } |
@@ -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; |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function __construct( Htsl$htsl, string$filePath ) |
29 | 29 | { |
30 | - substr($filePath,-5)==='.htsl' or $filePath.= '.htsl'; |
|
30 | + substr($filePath, -5)==='.htsl' or $filePath.='.htsl'; |
|
31 | 31 | |
32 | 32 | if( !file_exists($filePath) || !is_file($filePath) ){ |
33 | 33 | throw new \Exception("File $filePath not exists.", 1); |
34 | 34 | } |
35 | 35 | |
36 | - $this->filePath= $filePath; |
|
36 | + $this->filePath=$filePath; |
|
37 | 37 | |
38 | - $this->handle= fopen($filePath,'r'); |
|
38 | + $this->handle=fopen($filePath, 'r'); |
|
39 | 39 | |
40 | 40 | parent::__construct($htsl); |
41 | 41 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function getLine():Line |
61 | 61 | { |
62 | - while( "\n"===$content= fgets($this->handle) ); |
|
62 | + while( "\n"===$content=fgets($this->handle) ); |
|
63 | 63 | |
64 | 64 | return new Line($content); |
65 | 65 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function goSide( $fileName ):parent |
77 | 77 | { |
78 | - $filePath= $this->htsl->getFilePath($fileName,dirname($this->filePath)); |
|
78 | + $filePath=$this->htsl->getFilePath($fileName, dirname($this->filePath)); |
|
79 | 79 | |
80 | - return new static($this->htsl,$filePath); |
|
80 | + return new static($this->htsl, $filePath); |
|
81 | 81 | } |
82 | 82 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | false===$content and $this->isLast=true; |
35 | 35 | |
36 | - $this->content= rtrim($content,"\n"); |
|
36 | + $this->content=rtrim($content, "\n"); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getContent():string |
45 | 45 | { |
46 | - return ltrim($this->content,"\t"); |
|
46 | + return ltrim($this->content, "\t"); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function slice( int$start=0, int...$lengths ):string |
68 | 68 | { |
69 | - return substr($this->getContent(),$start,...array_slice($lengths,0,1)); |
|
69 | + return substr($this->getContent(), $start, ...array_slice($lengths, 0, 1)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function getChar( int$offset ):string |
80 | 80 | { |
81 | - return substr($this->getcontent(),$offset,1); |
|
81 | + return substr($this->getcontent(), $offset, 1); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function pregMatch( string$pattern ):bool |
92 | 92 | { |
93 | - return !!preg_match($pattern,ltrim($this->content,"\t")); |
|
93 | + return !!preg_match($pattern, ltrim($this->content, "\t")); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function pregGet( string$pattern, /*int|string*/$match=0 ):string |
105 | 105 | { |
106 | - preg_match($pattern,ltrim($this->content,"\t"),$matches); |
|
107 | - return $matches[$match]??''; |
|
106 | + preg_match($pattern, ltrim($this->content, "\t"), $matches); |
|
107 | + return $matches[ $match ]??''; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function pregMap( string$pattern, callable$callback ):array |
119 | 119 | { |
120 | - preg_match_all($pattern,ltrim($this->content,"\t"),$matches); |
|
121 | - return array_map($callback,...$matches); |
|
120 | + preg_match_all($pattern, ltrim($this->content, "\t"), $matches); |
|
121 | + return array_map($callback, ...$matches); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | { |
131 | 131 | // return (static function( $a ):int{$i=0;while($a{$i}==="\t")++$i;return $i;})($this->content); |
132 | 132 | |
133 | - return strlen($this->content)-strlen(ltrim($this->content,"\t")); |
|
133 | + return strlen($this->content)-strlen(ltrim($this->content, "\t")); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -190,6 +190,6 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function getSubIndentLine():self |
192 | 192 | { |
193 | - return new static(ltrim($this->getContent(),' ')); |
|
193 | + return new static(ltrim($this->getContent(), ' ')); |
|
194 | 194 | } |
195 | 195 | } |
@@ -79,6 +79,7 @@ |
||
79 | 79 | * |
80 | 80 | * @param int $start |
81 | 81 | * @param int ...$lengths |
82 | + * @param integer[] $lengths |
|
82 | 83 | * |
83 | 84 | * @return string |
84 | 85 | */ |
@@ -30,7 +30,7 @@ |
||
30 | 30 | */ |
31 | 31 | final public function __construct( Document$document ) |
32 | 32 | { |
33 | - $this->document= $document; |
|
33 | + $this->document=$document; |
|
34 | 34 | |
35 | 35 | $this->construct(); |
36 | 36 | } |
@@ -48,7 +48,9 @@ |
||
48 | 48 | /** |
49 | 49 | * Real constructor to be rewrite. |
50 | 50 | */ |
51 | - protected function construct(){} |
|
51 | + protected function construct() |
|
52 | + { |
|
53 | +} |
|
52 | 54 | |
53 | 55 | /** |
54 | 56 | * Parsing line. |