@@ -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; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function getConfig( string...$keys ) |
| 218 | 218 | { |
| 219 | - return $this->htsl->getConfig(array_shift($keys),$this->docType,...$keys); |
|
| 219 | + return $this->htsl->getConfig(array_shift($keys), $this->docType, ...$keys); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -256,16 +256,16 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | protected function parseFirstLine():self |
| 258 | 258 | { |
| 259 | - $line= $this->getLine(); |
|
| 259 | + $line=$this->getLine(); |
|
| 260 | 260 | |
| 261 | 261 | if( '@'===$line->getChar(0) ){ |
| 262 | 262 | return $this->setExtending($line); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - $this->docType= $line->content; |
|
| 266 | - $docTypeContent= $this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
| 265 | + $this->docType=$line->content; |
|
| 266 | + $docTypeContent=$this->getConfig('doc_types') or $this->throw("DocType $this->docType is not supported"); |
|
| 267 | 267 | |
| 268 | - $this->indentation= $this->htsl->getConfig('indentation',$this->docType) ?? ( function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)?$scalarOrFalse:false; } )($this->htsl->getConfig('indentation')); |
|
| 268 | + $this->indentation=$this->htsl->getConfig('indentation', $this->docType) ?? (function( $scalarOrFalse ){ return is_scalar($scalarOrFalse)? $scalarOrFalse : false; } )($this->htsl->getConfig('indentation')); |
|
| 269 | 269 | |
| 270 | 270 | $this->appendLine($docTypeContent); |
| 271 | 271 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | protected function setExtending( Line$firstLine ):self |
| 281 | 281 | { |
| 282 | - switch( $name= $firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 282 | + switch( $name=$firstLine->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 283 | 283 | default:{ |
| 284 | 284 | $this->throw("The @$name is not supported."); |
| 285 | 285 | }break; |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | protected function lineByLine():self |
| 305 | 305 | { |
| 306 | - while( ($line= $this->getLine())->hasMore() ){ |
|
| 307 | - $this->lineNumber+= 1; |
|
| 306 | + while( ($line=$this->getLine())->hasMore() ){ |
|
| 307 | + $this->lineNumber+=1; |
|
| 308 | 308 | |
| 309 | 309 | if( $this->embedment ){ |
| 310 | 310 | $this->embeddingParse($line); |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | $this->closeNodes($this->level); |
| 319 | 319 | |
| 320 | - $this->isExecuted= true; |
|
| 320 | + $this->isExecuted=true; |
|
| 321 | 321 | |
| 322 | 322 | return $this; |
| 323 | 323 | } |
@@ -348,10 +348,10 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | protected function startEmbedding( string$embedType ):self |
| 350 | 350 | { |
| 351 | - $embedmentClass= '\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
|
| 351 | + $embedmentClass='\\Htsl\\Embedment\\'.ucfirst($embedType).'Embedment'; |
|
| 352 | 352 | class_exists($embedmentClass) or $this->throw("Embed type $embedType not exists."); |
| 353 | 353 | |
| 354 | - $this->embedment= new $embedmentClass($this); |
|
| 354 | + $this->embedment=new $embedmentClass($this); |
|
| 355 | 355 | |
| 356 | 356 | return $this; |
| 357 | 357 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | public function breakEmbedding():self |
| 365 | 365 | { |
| 366 | 366 | $this->append($this->embedment->getContent()); |
| 367 | - $this->embedment= null; |
|
| 367 | + $this->embedment=null; |
|
| 368 | 368 | |
| 369 | 369 | return $this; |
| 370 | 370 | } |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | protected function parseLine( Line$line ):self |
| 380 | 380 | { |
| 381 | - $this->currentLine= $line; |
|
| 381 | + $this->currentLine=$line; |
|
| 382 | 382 | $this->setLevel($line->getIndentLevel()); |
| 383 | 383 | |
| 384 | 384 | switch( $line->getChar(0) ){ |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | protected function parseHtmlLine( Line$line ):self |
| 421 | 421 | { |
| 422 | - $node= new StringNode($this,$line); |
|
| 422 | + $node=new StringNode($this, $line); |
|
| 423 | 423 | |
| 424 | 424 | $this->openNode($node); |
| 425 | 425 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | protected function parseStringLine( Line$line ):self |
| 439 | 439 | { |
| 440 | - $node= new StringNode($this,$line); |
|
| 440 | + $node=new StringNode($this, $line); |
|
| 441 | 441 | |
| 442 | 442 | $this->openNode($node); |
| 443 | 443 | |
@@ -455,13 +455,13 @@ discard block |
||
| 455 | 455 | */ |
| 456 | 456 | protected function parseExpressionLine( Line$line ):self |
| 457 | 457 | { |
| 458 | - $node= new StringNode($this,$line); |
|
| 458 | + $node=new StringNode($this, $line); |
|
| 459 | 459 | |
| 460 | 460 | $this->openNode($node); |
| 461 | 461 | |
| 462 | - $content= $line->slice(1); |
|
| 463 | - $ent_flag= var_export($this->htsl->getConfig('ENT_flags',$this->docType),true); |
|
| 464 | - $charset= var_export($this->htsl->getConfig('charset'),true); |
|
| 462 | + $content=$line->slice(1); |
|
| 463 | + $ent_flag=var_export($this->htsl->getConfig('ENT_flags', $this->docType), true); |
|
| 464 | + $charset=var_export($this->htsl->getConfig('charset'), true); |
|
| 465 | 465 | |
| 466 | 466 | $this->appendLine("<?=htmlentities($content,$ent_flag,$charset,false)?>"); |
| 467 | 467 | |
@@ -477,11 +477,11 @@ discard block |
||
| 477 | 477 | */ |
| 478 | 478 | protected function parseExpressionHtmlLine( Line$line ):self |
| 479 | 479 | { |
| 480 | - $node= new StringNode($this,$line); |
|
| 480 | + $node=new StringNode($this, $line); |
|
| 481 | 481 | |
| 482 | 482 | $this->openNode($node); |
| 483 | 483 | |
| 484 | - $content= $line->slice(1); |
|
| 484 | + $content=$line->slice(1); |
|
| 485 | 485 | |
| 486 | 486 | $this->appendLine("<?$content?>"); |
| 487 | 487 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | */ |
| 498 | 498 | protected function parseCommentLine( Line$line ):self |
| 499 | 499 | { |
| 500 | - $node= new CommentNode($this,$line); |
|
| 500 | + $node=new CommentNode($this, $line); |
|
| 501 | 501 | |
| 502 | 502 | $this->openNode($node); |
| 503 | 503 | |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | protected function parseTagLine( Line$line ):self |
| 517 | 517 | { |
| 518 | - $tag= new TagNode($this,$line); |
|
| 518 | + $tag=new TagNode($this, $line); |
|
| 519 | 519 | |
| 520 | 520 | $this->appendLine($tag->open()); |
| 521 | 521 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | */ |
| 536 | 536 | protected function parseControlLine( Line$line ):self |
| 537 | 537 | { |
| 538 | - $controlStructure= new ControlNode($this,$line); |
|
| 538 | + $controlStructure=new ControlNode($this, $line); |
|
| 539 | 539 | |
| 540 | 540 | $this->appendLine($controlStructure->open()); |
| 541 | 541 | |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | protected function parseDocControlLine( Line$line ):self |
| 555 | 555 | { |
| 556 | - switch( $name= $line->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 556 | + switch( $name=$line->pregGet('/(?<=^@)[\w-:]+/') ){ |
|
| 557 | 557 | default:{ |
| 558 | 558 | $this->throw("The @$name is not supported."); |
| 559 | 559 | }break; |
@@ -583,10 +583,10 @@ discard block |
||
| 583 | 583 | */ |
| 584 | 584 | protected function extend( string$fileName ):self |
| 585 | 585 | { |
| 586 | - $this->parent= new static($this->htsl,$this->buffer->goSide($fileName),null,$this->indentation); |
|
| 586 | + $this->parent=new static($this->htsl, $this->buffer->goSide($fileName), null, $this->indentation); |
|
| 587 | 587 | |
| 588 | - $this->docType= $this->parent->docType; |
|
| 589 | - $this->indentation= $this->parent->indentation; |
|
| 588 | + $this->docType=$this->parent->docType; |
|
| 589 | + $this->indentation=$this->parent->indentation; |
|
| 590 | 590 | |
| 591 | 591 | return $this; |
| 592 | 592 | } |
@@ -598,15 +598,15 @@ discard block |
||
| 598 | 598 | * |
| 599 | 599 | * @return \Htsl\Parser\Document |
| 600 | 600 | */ |
| 601 | - protected function include( Line$line ):self |
|
| 601 | + protected function include(Line$line):self |
|
| 602 | 602 | { |
| 603 | - $inclued= (new static($this->htsl,$this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')),$this,$this->indentation))->execute()->content; |
|
| 603 | + $inclued=(new static($this->htsl, $this->buffer->goSide($line->pregGet('/(?<=\( ).*(?= \))/')), $this, $this->indentation))->execute()->content; |
|
| 604 | 604 | |
| 605 | 605 | if( false!==$this->indentation ){ |
| 606 | - $inclued= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level-$this->sectionLevel),$inclued); |
|
| 606 | + $inclued=preg_replace('/(?<=^|\\n)(?!$)/', str_repeat($this->indentation, $this->level-$this->sectionLevel), $inclued); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - $node= new StringNode($this,$line); |
|
| 609 | + $node=new StringNode($this, $line); |
|
| 610 | 610 | |
| 611 | 611 | $this->openNode($node); |
| 612 | 612 | |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | */ |
| 625 | 625 | protected function defineSection( Line$line ):self |
| 626 | 626 | { |
| 627 | - $node= new SectionNode($this,$line); |
|
| 627 | + $node=new SectionNode($this, $line); |
|
| 628 | 628 | |
| 629 | 629 | $node->open(); |
| 630 | 630 | |
@@ -642,22 +642,22 @@ discard block |
||
| 642 | 642 | */ |
| 643 | 643 | protected function showSection( Line$line ):self |
| 644 | 644 | { |
| 645 | - $sectionName= $line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 645 | + $sectionName=$line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 646 | 646 | |
| 647 | - if( !isset($this->sections[$sectionName]) ){ |
|
| 648 | - $this->openNode(new StringNode($this,$line)); |
|
| 647 | + if( !isset($this->sections[ $sectionName ]) ){ |
|
| 648 | + $this->openNode(new StringNode($this, $line)); |
|
| 649 | 649 | |
| 650 | 650 | return $this; |
| 651 | 651 | } |
| 652 | - $content= $this->sections[$sectionName]->content; |
|
| 652 | + $content=$this->sections[ $sectionName ]->content; |
|
| 653 | 653 | |
| 654 | 654 | if( false!==$this->indentation ){ |
| 655 | - $content= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level),$content); |
|
| 655 | + $content=preg_replace('/(?<=^|\\n)(?!$)/', str_repeat($this->indentation, $this->level), $content); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | $this->append($content); |
| 659 | 659 | |
| 660 | - $node= new NamelessSectionNode($this,$line); |
|
| 660 | + $node=new NamelessSectionNode($this, $line); |
|
| 661 | 661 | |
| 662 | 662 | $node->open(); |
| 663 | 663 | |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | public function setSection( Section$section=null ):self |
| 675 | 675 | { |
| 676 | 676 | if( !$section ){ |
| 677 | - $this->sectionLevel= 0; |
|
| 678 | - $this->currentSection= null; |
|
| 677 | + $this->sectionLevel=0; |
|
| 678 | + $this->currentSection=null; |
|
| 679 | 679 | |
| 680 | 680 | return $this; |
| 681 | 681 | } |
@@ -684,17 +684,17 @@ discard block |
||
| 684 | 684 | $this->throw('Nesting definition of section is forbidden.'); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if( isset($this->parent->sections[$section->name]) ){ |
|
| 687 | + if( isset($this->parent->sections[ $section->name ]) ){ |
|
| 688 | 688 | $this->throw("Section $sectionName already defined."); |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - $this->currentSection= $section; |
|
| 691 | + $this->currentSection=$section; |
|
| 692 | 692 | |
| 693 | 693 | if( $section->name ){ |
| 694 | - $this->parent->sections[$section->name]=$section; |
|
| 694 | + $this->parent->sections[ $section->name ]=$section; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - $this->sectionLevel= $this->level+1; |
|
| 697 | + $this->sectionLevel=$this->level+1; |
|
| 698 | 698 | |
| 699 | 699 | return $this; |
| 700 | 700 | } |
@@ -708,8 +708,8 @@ discard block |
||
| 708 | 708 | { |
| 709 | 709 | if( $this->parent ){ |
| 710 | 710 | foreach( $this->sections as $name=>$section ){ |
| 711 | - if( !isset($this->parent->sections[$name]) ){ |
|
| 712 | - $this->parent->sections[$name]=$section; |
|
| 711 | + if( !isset($this->parent->sections[ $name ]) ){ |
|
| 712 | + $this->parent->sections[ $name ]=$section; |
|
| 713 | 713 | }; |
| 714 | 714 | } |
| 715 | 715 | } |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | */ |
| 727 | 727 | public function htmlEntities( string$input ):string |
| 728 | 728 | { |
| 729 | - return htmlentities($input,$this->htsl->getConfig('ENT_flags',$this->docType),$this->htsl->getConfig('charset'),false); |
|
| 729 | + return htmlentities($input, $this->htsl->getConfig('ENT_flags', $this->docType), $this->htsl->getConfig('charset'), false); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -736,12 +736,12 @@ discard block |
||
| 736 | 736 | */ |
| 737 | 737 | protected function setLevel( int$level ):self |
| 738 | 738 | { |
| 739 | - $level-= $this->level; |
|
| 739 | + $level-=$this->level; |
|
| 740 | 740 | |
| 741 | 741 | if( $level<=0 ){ |
| 742 | 742 | $this->closeNodes(-$level); |
| 743 | 743 | }elseif( $level==1 ){ |
| 744 | - $this->level+= 1; |
|
| 744 | + $this->level+=1; |
|
| 745 | 745 | }else{ |
| 746 | 746 | $this->throw('Indent error.'); |
| 747 | 747 | } |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | */ |
| 759 | 759 | protected function openNode( Node$node ):self |
| 760 | 760 | { |
| 761 | - array_push($this->openedNodes,$node); |
|
| 761 | + array_push($this->openedNodes, $node); |
|
| 762 | 762 | |
| 763 | 763 | $node->scope and $this->setScope($node); |
| 764 | 764 | |
@@ -777,13 +777,13 @@ discard block |
||
| 777 | 777 | if( empty($this->openedNodes) ) return $this; |
| 778 | 778 | |
| 779 | 779 | while( $level-->=0 ){ |
| 780 | - $node= array_pop($this->openedNodes); |
|
| 780 | + $node=array_pop($this->openedNodes); |
|
| 781 | 781 | |
| 782 | 782 | $node->scope and $this->removeScope($node); |
| 783 | 783 | |
| 784 | 784 | $closer=$node->close($this->currentLine) and $this->appendLine($closer); |
| 785 | 785 | |
| 786 | - $this->level-= $level>=0 ?1:0; |
|
| 786 | + $this->level-=$level>=0? 1 : 0; |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | return $this; |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | */ |
| 797 | 797 | protected function setScope( Node$scope ):int |
| 798 | 798 | { |
| 799 | - return array_unshift($this->scopes,$scope); |
|
| 799 | + return array_unshift($this->scopes, $scope); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | */ |
| 807 | 807 | public function getScope() |
| 808 | 808 | { |
| 809 | - return $this->scopes[0]??null; |
|
| 809 | + return $this->scopes[ 0 ]??null; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | protected function appendLine( string$content ):self |
| 836 | 836 | { |
| 837 | 837 | if( false!==$this->indentation ){ |
| 838 | - $content= str_repeat($this->indentation,$this->level-$this->sectionLevel).$content."\n"; |
|
| 838 | + $content=str_repeat($this->indentation, $this->level-$this->sectionLevel).$content."\n"; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | return $this->append($content); |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * |
| 877 | 877 | * @throw \Htsl\Parser\HtslParsingException |
| 878 | 878 | */ |
| 879 | - public function throw( string$message ) |
|
| 879 | + public function throw(string$message) |
|
| 880 | 880 | { |
| 881 | 881 | throw new HtslParsingException("$message at file {$this->buffer->fileName} line $this->lineNumber"); |
| 882 | 882 | } |
@@ -36,8 +36,8 @@ |
||
| 36 | 36 | public function open():string |
| 37 | 37 | { |
| 38 | 38 | return $this->htmlComment ? |
| 39 | - '<!--'.str_replace('-->','--'.chr(0xC).'>',substr($this->line->getContent(),1)): |
|
| 40 | - '<?php /* '.substr($this->line->getContent(),2); |
|
| 39 | + '<!--'.str_replace('-->','--'.chr(0xC).'>',substr($this->line->getContent(),1)): |
|
| 40 | + '<?php /* '.substr($this->line->getContent(),2); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | protected function construct():parent |
| 26 | 26 | { |
| 27 | - $this->htmlComment= '!'!==$this->line->getChar(1); |
|
| 27 | + $this->htmlComment='!'!==$this->line->getChar(1); |
|
| 28 | 28 | return $this; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -35,9 +35,8 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function open():string |
| 37 | 37 | { |
| 38 | - return $this->htmlComment ? |
|
| 39 | - '<!--'.str_replace('-->','--'.chr(0xC).'>',substr($this->line->getContent(),1)): |
|
| 40 | - '<?php /* '.substr($this->line->getContent(),2); |
|
| 38 | + return $this->htmlComment? |
|
| 39 | + '<!--'.str_replace('-->', '--'.chr(0xC).'>', substr($this->line->getContent(), 1)) : '<?php /* '.substr($this->line->getContent(), 2); |
|
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | /** |
@@ -49,6 +48,6 @@ discard block |
||
| 49 | 48 | */ |
| 50 | 49 | public function close( Line$closerLine ):string |
| 51 | 50 | { |
| 52 | - return $this->htmlComment ? '-->' : ' */ ?>'; |
|
| 51 | + return $this->htmlComment? '-->' : ' */ ?>'; |
|
| 53 | 52 | } |
| 54 | 53 | } |
@@ -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); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | public function __set( $attribute, $value ) |
| 16 | 16 | { |
| 17 | - if( is_callable([static::class, $setter= 'set'.implode('',array_map('ucfirst',explode('_',$attribute))),]) ){ |
|
| 17 | + if( is_callable([ static::class, $setter='set'.implode('', array_map('ucfirst', explode('_', $attribute))), ]) ){ |
|
| 18 | 18 | return static::$setter($value); |
| 19 | 19 | }else{ |
| 20 | 20 | throw new \Exception(static::class.' has no attribute named '.$attribute); |
@@ -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 | /** |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | final public function __construct( Document$document, Line$line ) |
| 53 | 53 | { |
| 54 | - $this->htsl= $document->htsl; |
|
| 55 | - $this->document= $document; |
|
| 56 | - $this->line= $line; |
|
| 54 | + $this->htsl=$document->htsl; |
|
| 55 | + $this->document=$document; |
|
| 56 | + $this->line=$line; |
|
| 57 | 57 | |
| 58 | 58 | $this->construct(); |
| 59 | 59 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | public function getNodeType() |
| 100 | 100 | { |
| 101 | 101 | static $nodeType; |
| 102 | - return $nodeType??$nodeType= $this->nodeType??(static function($className){return strtolower(preg_replace('/(?<=\\w)([A-Z])/','_$1',preg_replace('/^(?:\\w+\\\\)*(\\w+)Node$/','$1',$className)));})(get_class($this)); |
|
| 102 | + return $nodeType??$nodeType=$this->nodeType??(static function( $className ){return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_$1', preg_replace('/^(?:\\w+\\\\)*(\\w+)Node$/', '$1', $className))); })(get_class($this)); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -112,39 +112,39 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | protected function loadConfig( string$name, IConfigProvider$configProvider ) |
| 114 | 114 | { |
| 115 | - $config= $configProvider->getConfig($this->nodeType.'_nodes',$name) ?: $configProvider->getConfig($this->nodeType.'_nodes','*'); |
|
| 115 | + $config=$configProvider->getConfig($this->nodeType.'_nodes', $name)?: $configProvider->getConfig($this->nodeType.'_nodes', '*'); |
|
| 116 | 116 | |
| 117 | - if( isset($config['multiple']) ){ |
|
| 118 | - foreach( $config['multiple'] as $value ){ |
|
| 119 | - if( $this->line->pregGet($value['pattern']) ){ |
|
| 120 | - $config= $value; |
|
| 117 | + if( isset($config[ 'multiple' ]) ){ |
|
| 118 | + foreach( $config[ 'multiple' ] as $value ){ |
|
| 119 | + if( $this->line->pregGet($value[ 'pattern' ]) ){ |
|
| 120 | + $config=$value; |
|
| 121 | 121 | break; |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if( isset($config['in']) ){ |
|
| 126 | + if( isset($config[ 'in' ]) ){ |
|
| 127 | 127 | $config=(function( array$config )use($name){ |
| 128 | - foreach( $config['in'] as $key=>$value ){ |
|
| 128 | + foreach( $config[ 'in' ] as $key=>$value ){ |
|
| 129 | 129 | if( $this->document->scope && $this->document->scope->scope===$key ){ |
| 130 | - $value['in_scope']= $key; |
|
| 130 | + $value[ 'in_scope' ]=$key; |
|
| 131 | 131 | return $value; |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | - if( !isset($config['out']) ){ |
|
| 135 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',',array_keys($config['in']))); |
|
| 134 | + if( !isset($config[ 'out' ]) ){ |
|
| 135 | + $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config[ 'in' ]))); |
|
| 136 | 136 | } |
| 137 | - return $config['out']; |
|
| 137 | + return $config[ 'out' ]; |
|
| 138 | 138 | })($config); |
| 139 | - }elseif( isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope,$config['only_in'])) ){ |
|
| 140 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',',$config['only_in'])); |
|
| 141 | - }elseif( isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope,$config['not_in'])) ){ |
|
| 142 | - $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',',$config['not_in'])); |
|
| 139 | + }elseif( isset($config[ 'only_in' ]) && (!$this->document->scope || !in_array($this->document->scope->scope, $config[ 'only_in' ])) ){ |
|
| 140 | + $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config[ 'only_in' ])); |
|
| 141 | + }elseif( isset($config[ 'not_in' ]) && (!$this->document->scope || !in_array($this->document->scope->scope, $config[ 'not_in' ])) ){ |
|
| 142 | + $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config[ 'not_in' ])); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if( !is_array($config) ){$this->document->throw("The $this->nodeType node $name is not supported.");} |
|
| 145 | + if( !is_array($config) ){$this->document->throw("The $this->nodeType node $name is not supported."); } |
|
| 146 | 146 | |
| 147 | - $this->config= $config; |
|
| 147 | + $this->config=$config; |
|
| 148 | 148 | |
| 149 | 149 | return $this; |
| 150 | 150 | } |
@@ -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 | } |