@@ -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 | { |
@@ -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 | } |
@@ -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 | /** |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | /** |
| 124 | 124 | * Getting the config of Htsl. |
| 125 | 125 | * |
| 126 | - * @param string $keys |
|
| 126 | + * @param string[] $keys |
|
| 127 | 127 | * |
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
@@ -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 | } |
@@ -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); |
@@ -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 | |
@@ -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; |
@@ -212,7 +212,7 @@ |
||
| 212 | 212 | * |
| 213 | 213 | * @param [ string, ] ...$keys |
| 214 | 214 | * |
| 215 | - * @return mixed |
|
| 215 | + * @return string |
|
| 216 | 216 | */ |
| 217 | 217 | public function getConfig( string...$keys ) |
| 218 | 218 | { |
@@ -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 | } |