@@ -14,7 +14,7 @@ |
||
14 | 14 | * |
15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
16 | 16 | * |
17 | - * @return \Htsl\Embedment\Contracts |
|
17 | + * @return CodeEmbedment |
|
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
@@ -18,13 +18,13 @@ |
||
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
21 | - $content= '<code>'.htmlentities($line->fullContent).'</code>'; |
|
21 | + $content='<code>'.htmlentities($line->fullContent).'</code>'; |
|
22 | 22 | |
23 | - $indentation= $this->document->indentation; |
|
23 | + $indentation=$this->document->indentation; |
|
24 | 24 | |
25 | - false!==$indentation and $content= str_repeat($indentation,$this->document->indentLevel).$content."\n"; |
|
25 | + false!==$indentation and $content=str_repeat($indentation, $this->document->indentLevel).$content."\n"; |
|
26 | 26 | |
27 | - $this->content.= $content; |
|
27 | + $this->content.=$content; |
|
28 | 28 | |
29 | 29 | return $this; |
30 | 30 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | * |
15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
16 | 16 | * |
17 | - * @return \Htsl\Embedment\Contracts |
|
17 | + * @return CssEmbedment |
|
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
21 | - $this->content.= $line->content; |
|
21 | + $this->content.=$line->content; |
|
22 | 22 | return $this; |
23 | 23 | } |
24 | 24 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * |
23 | 23 | * @param \Htsl\ReadingBuffer\Line $line |
24 | 24 | * |
25 | - * @return \Htsl\Embedment\Contracts |
|
25 | + * @return JsEmbedment |
|
26 | 26 | */ |
27 | 27 | public function parseLine( Line$line ):parent |
28 | 28 | { |
@@ -26,7 +26,7 @@ |
||
26 | 26 | */ |
27 | 27 | public function parseLine( Line$line ):parent |
28 | 28 | { |
29 | - $this->content.= $line->fullContent."\n"; |
|
29 | + $this->content.=$line->fullContent."\n"; |
|
30 | 30 | return $this; |
31 | 31 | } |
32 | 32 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | * |
15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
16 | 16 | * |
17 | - * @return \Htsl\Embedment\Contracts |
|
17 | + * @return PhpEmbedment |
|
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
21 | - $this->content.= $line->content; |
|
21 | + $this->content.=$line->content; |
|
22 | 22 | return $this; |
23 | 23 | } |
24 | 24 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | * |
15 | 15 | * @param \Htsl\ReadingBuffer\Line $line |
16 | 16 | * |
17 | - * @return \Htsl\Embedment\Contracts |
|
17 | + * @return TextEmbedment |
|
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function parseLine( Line$line ):parent |
20 | 20 | { |
21 | - $this->content.= $line->fullContent."\n"; |
|
21 | + $this->content.=$line->fullContent."\n"; |
|
22 | 22 | return $this; |
23 | 23 | } |
24 | 24 | } |
@@ -123,7 +123,7 @@ |
||
123 | 123 | /** |
124 | 124 | * Getting the config of Htsl. |
125 | 125 | * |
126 | - * @param string $key |
|
126 | + * @param string $keys |
|
127 | 127 | * |
128 | 128 | * @return mixed |
129 | 129 | */ |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | if( $toFile ){ |
69 | 69 | return file_put_contents($toFile,$result); |
70 | - }else{ |
|
70 | + } else{ |
|
71 | 71 | return $result; |
72 | 72 | } |
73 | 73 | } |
@@ -159,15 +159,12 @@ discard block |
||
159 | 159 | |
160 | 160 | if( '/'===$filePath{0} ){ |
161 | 161 | if( is_null($path) ) |
162 | - { return $filePath; } |
|
163 | - else |
|
162 | + { return $filePath; } else |
|
164 | 163 | { return $this->basePath.$filePath; } |
165 | - }else{ |
|
164 | + } else{ |
|
166 | 165 | if( !strlen($path) ) |
167 | - { return $this->basePath.'/'.$filePath; } |
|
168 | - elseif( '/'===substr($path,-1) ) |
|
169 | - { return $path.$filePath; } |
|
170 | - else |
|
166 | + { return $this->basePath.'/'.$filePath; } elseif( '/'===substr($path,-1) ) |
|
167 | + { return $path.$filePath; } else |
|
171 | 168 | { return $path.'/'.$filePath; } |
172 | 169 | } |
173 | 170 |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param array $config |
36 | 36 | */ |
37 | - public function __construct( array$config=[] ) |
|
37 | + public function __construct( array$config=[ ] ) |
|
38 | 38 | { |
39 | - $this->config= array_replace_recursive($this->getDefaultConfigs(),$config); |
|
39 | + $this->config=array_replace_recursive($this->getDefaultConfigs(), $config); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function parse( string$content ):string |
50 | 50 | { |
51 | - return $this->execute(new StringBuffer($this,$content)); |
|
51 | + return $this->execute(new StringBuffer($this, $content)); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function compile( string$fromFile, string$toFile=null ) |
63 | 63 | { |
64 | - $fromFile= $this->getFilePath($fromFile); |
|
64 | + $fromFile=$this->getFilePath($fromFile); |
|
65 | 65 | |
66 | - $result= $this->execute(new FileBuffer($this,$fromFile)); |
|
66 | + $result=$this->execute(new FileBuffer($this, $fromFile)); |
|
67 | 67 | |
68 | 68 | if( $toFile ){ |
69 | - return file_put_contents($toFile,$result); |
|
69 | + return file_put_contents($toFile, $result); |
|
70 | 70 | }else{ |
71 | 71 | return $result; |
72 | 72 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function setBasePath( string$basePath ):self |
95 | 95 | { |
96 | - $this->basePath= '/'===substr($basePath,-1) ? substr($basePath,0,-1) : $basePath; |
|
96 | + $this->basePath='/'===substr($basePath, -1)? substr($basePath, 0, -1) : $basePath; |
|
97 | 97 | |
98 | 98 | return $this; |
99 | 99 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function execute( ABuffer$buffer ):string |
119 | 119 | { |
120 | - return (new Document($this,$buffer))->content; |
|
120 | + return (new Document($this, $buffer))->content; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getConfig( string...$keys ) |
131 | 131 | { |
132 | - $result= $this->config; |
|
132 | + $result=$this->config; |
|
133 | 133 | |
134 | 134 | foreach( $keys as $key ){ |
135 | - if( !isset($result[$key]) ) |
|
135 | + if( !isset($result[ $key ]) ) |
|
136 | 136 | { return null; } |
137 | 137 | |
138 | - $result= $result[$key]; |
|
138 | + $result=$result[ $key ]; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | return $result; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | }else{ |
166 | 166 | if( !strlen($path) ) |
167 | 167 | { return $this->basePath.'/'.$filePath; } |
168 | - elseif( '/'===substr($path,-1) ) |
|
168 | + elseif( '/'===substr($path, -1) ) |
|
169 | 169 | { return $path.$filePath; } |
170 | 170 | else |
171 | 171 | { return $path.'/'.$filePath; } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getFileContent( string$filePath ):string |
183 | 183 | { |
184 | - return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath); |
|
184 | + return isset($this->fileGetter)? $this->fileGetter($filePath) : file_get_contents($filePath); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | /** |
173 | 173 | * Alias of getContent. |
174 | 174 | * |
175 | - * @return sting |
|
175 | + * @return string |
|
176 | 176 | */ |
177 | 177 | public function __toString():string |
178 | 178 | { |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * Getting the config of type of this document. |
212 | 212 | * |
213 | 213 | * @param [ string, ] ...$keys |
214 | - * @return mixed |
|
214 | + * @return string |
|
215 | 215 | */ |
216 | 216 | public function getConfig( string...$keys ) |
217 | 217 | { |
@@ -165,7 +165,7 @@ |
||
165 | 165 | return $this; |
166 | 166 | } |
167 | 167 | return $this->lineByLine() |
168 | - ->bubbleSections() |
|
168 | + ->bubbleSections() |
|
169 | 169 | ; |
170 | 170 | } |
171 | 171 |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @var int |
70 | 70 | */ |
71 | - private $level= 0; |
|
71 | + private $level=0; |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Section indent level. |
75 | 75 | * |
76 | 76 | * @var int |
77 | 77 | */ |
78 | - private $sectionLevel= 0; |
|
78 | + private $sectionLevel=0; |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Opened nodes. |
82 | 82 | * |
83 | 83 | * @var [ Htsl\Parser\Node\Contracts\ANode, ] |
84 | 84 | */ |
85 | - private $openedNodes= []; |
|
85 | + private $openedNodes=[ ]; |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Current scopes. |
89 | 89 | * |
90 | 90 | * @var [ Htsl\Parser\Node\Contracts\ANode, ] |
91 | 91 | */ |
92 | - private $scopes= []; |
|
92 | + private $scopes=[ ]; |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * Current line number. |
96 | 96 | * |
97 | 97 | * @var int |
98 | 98 | */ |
99 | - private $lineNumber= 0; |
|
99 | + private $lineNumber=0; |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Current line. |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @var [ Htsl\Parser\Section, ] |
112 | 112 | */ |
113 | - private $sections=[]; |
|
113 | + private $sections=[ ]; |
|
114 | 114 | |
115 | 115 | /** |
116 | 116 | * Whether the document is executed. |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function __construct( Htsl$htsl, Buffer$buffer, self$parent=null ) |
144 | 144 | { |
145 | - $this->htsl= $htsl; |
|
146 | - $this->buffer= $buffer; |
|
145 | + $this->htsl=$htsl; |
|
146 | + $this->buffer=$buffer; |
|
147 | 147 | |
148 | 148 | if( $parent ){ |
149 | - $this->parent= $parent; |
|
150 | - $this->docType= $parent->docType; |
|
151 | - $this->indentation= $parent->indentation; |
|
149 | + $this->parent=$parent; |
|
150 | + $this->docType=$parent->docType; |
|
151 | + $this->indentation=$parent->indentation; |
|
152 | 152 | }else{ |
153 | 153 | $this->parseFirstLine(); |
154 | 154 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | protected function getLine():Line |
202 | 202 | { |
203 | 203 | do{ |
204 | - $line= $this->buffer->getLine(); |
|
204 | + $line=$this->buffer->getLine(); |
|
205 | 205 | }while( $line->isEmpty() && $line->hasMore() ); |
206 | 206 | |
207 | 207 | return $line; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function getConfig( string...$keys ) |
217 | 217 | { |
218 | - return $this->htsl->getConfig(array_shift($keys),$this->docType,...$keys); |
|
218 | + return $this->htsl->getConfig(array_shift($keys), $this->docType, ...$keys); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -255,16 +255,16 @@ discard block |
||
255 | 255 | */ |
256 | 256 | protected function parseFirstLine():self |
257 | 257 | { |
258 | - $line= $this->getLine(); |
|
258 | + $line=$this->getLine(); |
|
259 | 259 | |
260 | 260 | if( '@'===$line->getChar(0) ){ |
261 | 261 | return $this->setExtending($line); |
262 | 262 | } |
263 | 263 | |
264 | - $this->docType= $line->content; |
|
265 | - $docTypeContent= $this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
264 | + $this->docType=$line->content; |
|
265 | + $docTypeContent=$this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
266 | 266 | |
267 | - $this->indentation= $this->htsl->getConfig('indentation',$this->docType) ?? ( function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)?$scalarOrFalse:false; } )($this->htsl->getConfig('indentation')); |
|
267 | + $this->indentation=$this->htsl->getConfig('indentation', $this->docType) ?? (function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)? $scalarOrFalse : false; } )($this->htsl->getConfig('indentation')); |
|
268 | 268 | |
269 | 269 | $this->appendLine($docTypeContent); |
270 | 270 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | protected function setExtending( Line$firstLine ):self |
280 | 280 | { |
281 | - switch( $name= $firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
281 | + switch( $name=$firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
282 | 282 | default:{ |
283 | 283 | $this->throw("The @$name is not supported."); |
284 | 284 | }break; |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | */ |
303 | 303 | protected function lineByLine():self |
304 | 304 | { |
305 | - while( ($line= $this->getLine())->hasMore() ){ |
|
306 | - $this->lineNumber+= 1; |
|
305 | + while( ($line=$this->getLine())->hasMore() ){ |
|
306 | + $this->lineNumber+=1; |
|
307 | 307 | |
308 | 308 | if( $this->embedment ){ |
309 | 309 | $this->embeddingParse($line); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | |
317 | 317 | $this->closeNodes($this->level); |
318 | 318 | |
319 | - $this->isExecuted= true; |
|
319 | + $this->isExecuted=true; |
|
320 | 320 | |
321 | 321 | return $this; |
322 | 322 | } |
@@ -347,10 +347,10 @@ discard block |
||
347 | 347 | */ |
348 | 348 | protected function startEmbedding( string$embedType ):self |
349 | 349 | { |
350 | - $embedmentClass= '\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
|
350 | + $embedmentClass='\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
|
351 | 351 | class_exists($embedmentClass) or $this->throw("Embed type $embedType not exists."); |
352 | 352 | |
353 | - $this->embedment= new $embedmentClass($this); |
|
353 | + $this->embedment=new $embedmentClass($this); |
|
354 | 354 | |
355 | 355 | return $this; |
356 | 356 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | public function breakEmbedding():self |
364 | 364 | { |
365 | 365 | $this->append($this->embedment->getContent()); |
366 | - $this->embedment= null; |
|
366 | + $this->embedment=null; |
|
367 | 367 | |
368 | 368 | return $this; |
369 | 369 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | protected function parseLine( Line$line ):self |
379 | 379 | { |
380 | - $this->currentLine= $line; |
|
380 | + $this->currentLine=$line; |
|
381 | 381 | $this->setLevel($line->getIndentLevel()); |
382 | 382 | |
383 | 383 | switch( $line->getChar(0) ){ |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | */ |
419 | 419 | protected function parseHtmlLine( Line$line ):self |
420 | 420 | { |
421 | - $node= new StringNode($this,$line); |
|
421 | + $node=new StringNode($this, $line); |
|
422 | 422 | |
423 | 423 | $this->openNode($node); |
424 | 424 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | */ |
437 | 437 | protected function parseStringLine( Line$line ):self |
438 | 438 | { |
439 | - $node= new StringNode($this,$line); |
|
439 | + $node=new StringNode($this, $line); |
|
440 | 440 | |
441 | 441 | $this->openNode($node); |
442 | 442 | |
@@ -454,12 +454,12 @@ discard block |
||
454 | 454 | */ |
455 | 455 | protected function parseExpressionLine( Line$line ):self |
456 | 456 | { |
457 | - $node= new StringNode($this,$line); |
|
457 | + $node=new StringNode($this, $line); |
|
458 | 458 | |
459 | 459 | $this->openNode($node); |
460 | 460 | |
461 | - $content= $line->slice(1); |
|
462 | - $ent_flag= $this->htsl->getConfig('ENT_flags',$this->docType); |
|
461 | + $content=$line->slice(1); |
|
462 | + $ent_flag=$this->htsl->getConfig('ENT_flags', $this->docType); |
|
463 | 463 | |
464 | 464 | $this->appendLine("<?=htmlentities($content,'$ent_flag','UTF-8',false);?>"); |
465 | 465 | |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | */ |
476 | 476 | protected function parseExpressionHtmlLine( Line$line ):self |
477 | 477 | { |
478 | - $node= new StringNode($this,$line); |
|
478 | + $node=new StringNode($this, $line); |
|
479 | 479 | |
480 | 480 | $this->openNode($node); |
481 | 481 | |
482 | - $content= $line->slice(1); |
|
482 | + $content=$line->slice(1); |
|
483 | 483 | |
484 | 484 | $this->appendLine("<?$content?>"); |
485 | 485 | |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | */ |
496 | 496 | protected function parseCommentLine( Line$line ):self |
497 | 497 | { |
498 | - $node= new CommentNode($this,$line); |
|
498 | + $node=new CommentNode($this, $line); |
|
499 | 499 | |
500 | 500 | $this->openNode($node); |
501 | 501 | |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | */ |
514 | 514 | protected function parseTagLine( Line$line ):self |
515 | 515 | { |
516 | - $tag= new TagNode($this,$line); |
|
516 | + $tag=new TagNode($this, $line); |
|
517 | 517 | |
518 | 518 | $this->appendLine($tag->open()); |
519 | 519 | |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | */ |
534 | 534 | protected function parseControlLine( Line$line ):self |
535 | 535 | { |
536 | - $controlStructure= new ControlNode($this,$line); |
|
536 | + $controlStructure=new ControlNode($this, $line); |
|
537 | 537 | |
538 | 538 | $this->appendLine($controlStructure->open()); |
539 | 539 | |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | */ |
552 | 552 | protected function parseDocControlLine( Line$line ):self |
553 | 553 | { |
554 | - switch( $name= $line->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
554 | + switch( $name=$line->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
555 | 555 | default:{ |
556 | 556 | $this->throw("The @$name is not supported."); |
557 | 557 | }break; |
@@ -581,10 +581,10 @@ discard block |
||
581 | 581 | */ |
582 | 582 | protected function extend( string$fileName ):self |
583 | 583 | { |
584 | - $this->parent= new static($this->htsl,$this->buffer->goSide($fileName),null,$this->indentation); |
|
584 | + $this->parent=new static($this->htsl, $this->buffer->goSide($fileName), null, $this->indentation); |
|
585 | 585 | |
586 | - $this->docType= $this->parent->docType; |
|
587 | - $this->indentation= $this->parent->indentation; |
|
586 | + $this->docType=$this->parent->docType; |
|
587 | + $this->indentation=$this->parent->indentation; |
|
588 | 588 | |
589 | 589 | return $this; |
590 | 590 | } |
@@ -596,15 +596,15 @@ discard block |
||
596 | 596 | * |
597 | 597 | * @return \Htsl\Parser\Document |
598 | 598 | */ |
599 | - protected function include( Line$line ):self |
|
599 | + protected function include(Line$line):self |
|
600 | 600 | { |
601 | - $inclued= (new static($this->htsl,$this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')),$this,$this->indentation))->execute()->content; |
|
601 | + $inclued=(new static($this->htsl, $this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')), $this, $this->indentation))->execute()->content; |
|
602 | 602 | |
603 | 603 | if( false!==$this->indentation ){ |
604 | - $inclued= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level-$this->sectionLevel),$inclued); |
|
604 | + $inclued=preg_replace('/(?<=^|\\n)(?!$)/', str_repeat($this->indentation, $this->level-$this->sectionLevel), $inclued); |
|
605 | 605 | } |
606 | 606 | |
607 | - $node= new StringNode($this,$line); |
|
607 | + $node=new StringNode($this, $line); |
|
608 | 608 | |
609 | 609 | $this->openNode($node); |
610 | 610 | |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | */ |
623 | 623 | protected function defineSection( Line$line ):self |
624 | 624 | { |
625 | - $node= new SectionNode($this,$line); |
|
625 | + $node=new SectionNode($this, $line); |
|
626 | 626 | |
627 | 627 | $node->open(); |
628 | 628 | |
@@ -640,22 +640,22 @@ discard block |
||
640 | 640 | */ |
641 | 641 | protected function showSection( Line$line ):self |
642 | 642 | { |
643 | - $sectionName= $line->pregGet('/(?<=\( ).*(?= \))/'); |
|
643 | + $sectionName=$line->pregGet('/(?<=\( ).*(?= \))/'); |
|
644 | 644 | |
645 | - if( !isset($this->sections[$sectionName]) ){ |
|
646 | - $this->openNode(new StringNode($this,$line)); |
|
645 | + if( !isset($this->sections[ $sectionName ]) ){ |
|
646 | + $this->openNode(new StringNode($this, $line)); |
|
647 | 647 | |
648 | 648 | return $this; |
649 | 649 | } |
650 | - $content= $this->sections[$sectionName]->content; |
|
650 | + $content=$this->sections[ $sectionName ]->content; |
|
651 | 651 | |
652 | 652 | if( false!==$this->indentation ){ |
653 | - $content= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level),$content); |
|
653 | + $content=preg_replace('/(?<=^|\\n)(?!$)/', str_repeat($this->indentation, $this->level), $content); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | $this->append($content); |
657 | 657 | |
658 | - $node= new NamelessSectionNode($this,$line); |
|
658 | + $node=new NamelessSectionNode($this, $line); |
|
659 | 659 | |
660 | 660 | $node->open(); |
661 | 661 | |
@@ -672,8 +672,8 @@ discard block |
||
672 | 672 | public function setSection( Section$section=null ):self |
673 | 673 | { |
674 | 674 | if( !$section ){ |
675 | - $this->sectionLevel= 0; |
|
676 | - $this->currentSection= null; |
|
675 | + $this->sectionLevel=0; |
|
676 | + $this->currentSection=null; |
|
677 | 677 | |
678 | 678 | return $this; |
679 | 679 | } |
@@ -682,17 +682,17 @@ discard block |
||
682 | 682 | $this->throw('Nesting definition of section is forbidden.'); |
683 | 683 | } |
684 | 684 | |
685 | - if( isset($this->parent->sections[$section->name]) ){ |
|
685 | + if( isset($this->parent->sections[ $section->name ]) ){ |
|
686 | 686 | $this->throw("Section $sectionName already defined."); |
687 | 687 | } |
688 | 688 | |
689 | - $this->currentSection= $section; |
|
689 | + $this->currentSection=$section; |
|
690 | 690 | |
691 | 691 | if( $section->name ){ |
692 | - $this->parent->sections[$section->name]=$section; |
|
692 | + $this->parent->sections[ $section->name ]=$section; |
|
693 | 693 | } |
694 | 694 | |
695 | - $this->sectionLevel= $this->level+1; |
|
695 | + $this->sectionLevel=$this->level+1; |
|
696 | 696 | |
697 | 697 | return $this; |
698 | 698 | } |
@@ -706,8 +706,8 @@ discard block |
||
706 | 706 | { |
707 | 707 | if( $this->parent ){ |
708 | 708 | foreach( $this->sections as $name=>$section ){ |
709 | - if( !isset($this->parent->sections[$name]) ){ |
|
710 | - $this->parent->sections[$name]=$section; |
|
709 | + if( !isset($this->parent->sections[ $name ]) ){ |
|
710 | + $this->parent->sections[ $name ]=$section; |
|
711 | 711 | }; |
712 | 712 | } |
713 | 713 | } |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | */ |
725 | 725 | public function htmlEntities( string$input ):string |
726 | 726 | { |
727 | - return htmlentities($input,$this->htsl->getConfig('ENT_flags',$this->docType),'UTF-8',false); |
|
727 | + return htmlentities($input, $this->htsl->getConfig('ENT_flags', $this->docType), 'UTF-8', false); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
@@ -734,12 +734,12 @@ discard block |
||
734 | 734 | */ |
735 | 735 | protected function setLevel( int$level ):self |
736 | 736 | { |
737 | - $level-= $this->level; |
|
737 | + $level-=$this->level; |
|
738 | 738 | |
739 | 739 | if( $level<=0 ){ |
740 | 740 | $this->closeNodes(-$level); |
741 | 741 | }elseif( $level==1 ){ |
742 | - $this->level+= 1; |
|
742 | + $this->level+=1; |
|
743 | 743 | }else{ |
744 | 744 | $this->throw('Indent error.'); |
745 | 745 | } |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | */ |
757 | 757 | protected function openNode( Node$node ):self |
758 | 758 | { |
759 | - array_push($this->openedNodes,$node); |
|
759 | + array_push($this->openedNodes, $node); |
|
760 | 760 | |
761 | 761 | $node->scope and $this->setScope($node); |
762 | 762 | |
@@ -775,13 +775,13 @@ discard block |
||
775 | 775 | if( empty($this->openedNodes) ) return $this; |
776 | 776 | |
777 | 777 | while( $level-->=0 ){ |
778 | - $node= array_pop($this->openedNodes); |
|
778 | + $node=array_pop($this->openedNodes); |
|
779 | 779 | |
780 | 780 | $node->scope and $this->removeScope($node); |
781 | 781 | |
782 | 782 | $closer=$node->close($this->currentLine) and $this->appendLine($closer); |
783 | 783 | |
784 | - $this->level-= $level>=0 ?1:0; |
|
784 | + $this->level-=$level>=0? 1 : 0; |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | return $this; |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | */ |
795 | 795 | protected function setScope( Node$scope ):int |
796 | 796 | { |
797 | - return array_unshift($this->scopes,$scope); |
|
797 | + return array_unshift($this->scopes, $scope); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | /** |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | */ |
805 | 805 | public function getScope() |
806 | 806 | { |
807 | - return $this->scopes[0]??null; |
|
807 | + return $this->scopes[ 0 ]??null; |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | protected function appendLine( string$content ):self |
834 | 834 | { |
835 | 835 | if( false!==$this->indentation ){ |
836 | - $content= str_repeat($this->indentation,$this->level-$this->sectionLevel).$content."\n"; |
|
836 | + $content=str_repeat($this->indentation, $this->level-$this->sectionLevel).$content."\n"; |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | return $this->append($content); |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | * |
875 | 875 | * @throw \Htsl\Parser\HtslParsingException |
876 | 876 | */ |
877 | - public function throw( string$message ) |
|
877 | + public function throw(string$message) |
|
878 | 878 | { |
879 | 879 | throw new HtslParsingException("$message at file {$this->buffer->fileName} line $this->lineNumber"); |
880 | 880 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $this->parent= $parent; |
150 | 150 | $this->docType= $parent->docType; |
151 | 151 | $this->indentation= $parent->indentation; |
152 | - }else{ |
|
152 | + } else{ |
|
153 | 153 | $this->parseFirstLine(); |
154 | 154 | } |
155 | 155 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | { |
189 | 189 | if( $this->parent ){ |
190 | 190 | return $this->execute()->parent->getContent(); |
191 | - }else{ |
|
191 | + } else{ |
|
192 | 192 | return $this->execute()->content; |
193 | 193 | } |
194 | 194 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | |
308 | 308 | if( $this->embedment ){ |
309 | 309 | $this->embeddingParse($line); |
310 | - }else{ |
|
310 | + } else{ |
|
311 | 311 | $this->parseLine($line); |
312 | 312 | } |
313 | 313 | } |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | { |
333 | 333 | if( $line->content==='<}' ){ |
334 | 334 | $this->breakEmbedding(); |
335 | - }else{ |
|
335 | + } else{ |
|
336 | 336 | $this->embedment->parseLine($line->getSubIndentLine()); |
337 | 337 | } |
338 | 338 | return $this; |
@@ -386,8 +386,7 @@ discard block |
||
386 | 386 | }break; |
387 | 387 | case '`':{ |
388 | 388 | if( '='===$line->getChar(1) ) |
389 | - { $this->parseExpressionHtmlLine($line); } |
|
390 | - else |
|
389 | + { $this->parseExpressionHtmlLine($line); } else |
|
391 | 390 | { $this->parseHtmlLine($line); } |
392 | 391 | }break; |
393 | 392 | case '=':{ |
@@ -738,9 +737,9 @@ discard block |
||
738 | 737 | |
739 | 738 | if( $level<=0 ){ |
740 | 739 | $this->closeNodes(-$level); |
741 | - }elseif( $level==1 ){ |
|
740 | + } elseif( $level==1 ){ |
|
742 | 741 | $this->level+= 1; |
743 | - }else{ |
|
742 | + } else{ |
|
744 | 743 | $this->throw('Indent error.'); |
745 | 744 | } |
746 | 745 | |
@@ -772,7 +771,9 @@ discard block |
||
772 | 771 | */ |
773 | 772 | protected function closeNodes( int$level=0 ):self |
774 | 773 | { |
775 | - if( empty($this->openedNodes) ) return $this; |
|
774 | + if( empty($this->openedNodes) ){ |
|
775 | + return $this; |
|
776 | + } |
|
776 | 777 | |
777 | 778 | while( $level-->=0 ){ |
778 | 779 | $node= array_pop($this->openedNodes); |
@@ -850,7 +851,7 @@ discard block |
||
850 | 851 | { |
851 | 852 | if( $this->currentSection ){ |
852 | 853 | $this->currentSection->append($content); |
853 | - }else{ |
|
854 | + } else{ |
|
854 | 855 | $this->content.=$content; |
855 | 856 | } |
856 | 857 |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | $this->docType= $line->content; |
265 | - $docTypeContent= $this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
265 | + $docTypeContent= $this->getConfig('doc_types') or $this->throw("doctype $this->docType is not supported"); |
|
266 | 266 | |
267 | 267 | $this->indentation= $this->htsl->getConfig('indentation',$this->docType) ?? ( function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)?$scalarOrFalse:false; } )($this->htsl->getConfig('indentation')); |
268 | 268 | |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | } |
684 | 684 | |
685 | 685 | if( isset($this->parent->sections[$section->name]) ){ |
686 | - $this->throw("Section $sectionName already defined."); |
|
686 | + $this->throw("section $sectionName already defined."); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | $this->currentSection= $section; |
@@ -90,7 +90,6 @@ discard block |
||
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 | */ |
@@ -208,7 +207,7 @@ discard block |
||
208 | 207 | /** |
209 | 208 | * Parsing #ids .classes ^titles [styles] %event{>listeners<} and {other attributes} |
210 | 209 | * |
211 | - * @return \Htsl\Parser\Node\TagNode |
|
210 | + * @return string |
|
212 | 211 | */ |
213 | 212 | protected function parseCommonAttributes():string |
214 | 213 | { |
@@ -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 | } |
@@ -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 | } |
@@ -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, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Get a line of the document. |
41 | - * @return \Htsl\ReadingBuffer\Line |
|
41 | + * @return string |
|
42 | 42 | */ |
43 | 43 | public function getFileName():string |
44 | 44 | { |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * Getting another file reference file of this buffer. |
50 | 50 | * |
51 | - * @param string $filePath |
|
52 | 51 | * |
52 | + * @param string $fileName |
|
53 | 53 | * @return \Htsl\ReadingBuffer\Contracts\ABuffer |
54 | 54 | */ |
55 | 55 | abstract public function goSide( $fileName ):self; |
@@ -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 | /** |