@@ -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 | { |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @return \Htsl\Embedment\Contracts |
| 18 | 18 | */ |
| 19 | - public function parseLine( Line$line ):parent |
|
| 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 | { |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @return \Htsl\Embedment\Contracts |
| 18 | 18 | */ |
| 19 | - public function parseLine( Line$line ):parent |
|
| 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 | { |
@@ -24,9 +24,9 @@ |
||
| 24 | 24 | * |
| 25 | 25 | * @return \Htsl\Embedment\Contracts |
| 26 | 26 | */ |
| 27 | - public function parseLine( Line$line ):parent |
|
| 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 | { |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @return \Htsl\Embedment\Contracts |
| 18 | 18 | */ |
| 19 | - public function parseLine( Line$line ):parent |
|
| 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 | { |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @return \Htsl\Embedment\Contracts |
| 18 | 18 | */ |
| 19 | - public function parseLine( Line$line ):parent |
|
| 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 | */ |
@@ -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 | /** |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | - public function parse( string$content ):string |
|
| 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 | /** |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @return int|string |
| 61 | 61 | */ |
| 62 | - public function compile( string$fromFile, string$toFile=null ) |
|
| 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 | - if( $toFile ){ |
|
| 69 | - return file_put_contents($toFile,$result); |
|
| 70 | - }else{ |
|
| 68 | + if ($toFile) { |
|
| 69 | + return file_put_contents($toFile, $result); |
|
| 70 | + }else { |
|
| 71 | 71 | return $result; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @param callable $fileGetter |
| 79 | 79 | */ |
| 80 | - public function setFileGetter( callable$fileGetter ):self |
|
| 80 | + public function setFileGetter(callable$fileGetter):self |
|
| 81 | 81 | { |
| 82 | 82 | $this->fileGetter=$fileGetter; |
| 83 | 83 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * @return self |
| 93 | 93 | */ |
| 94 | - public function setBasePath( string$basePath ):self |
|
| 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 | } |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | - protected function execute( ABuffer$buffer ):string |
|
| 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 | /** |
@@ -127,15 +127,15 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
| 130 | - public function getConfig( string...$keys ) |
|
| 130 | + public function getConfig(string...$keys) |
|
| 131 | 131 | { |
| 132 | - $result= $this->config; |
|
| 132 | + $result=$this->config; |
|
| 133 | 133 | |
| 134 | - foreach( $keys as $key ){ |
|
| 135 | - if( !isset($result[$key]) ) |
|
| 134 | + foreach ($keys as $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; |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @return string |
| 151 | 151 | */ |
| 152 | - public function getFilePath( string$filePath, string$path=null ):string |
|
| 152 | + public function getFilePath(string$filePath, string$path=null):string |
|
| 153 | 153 | { |
| 154 | - if( !isset($this->basePath) ) |
|
| 154 | + if (!isset($this->basePath)) |
|
| 155 | 155 | { throw new \Exception('BasePath musbe set.'); } |
| 156 | 156 | |
| 157 | - if( !strlen($filePath) ) |
|
| 157 | + if (!strlen($filePath)) |
|
| 158 | 158 | { throw new \Exception('FilePath cannot be empty.'); } |
| 159 | 159 | |
| 160 | - if( '/'===$filePath{0} ){ |
|
| 161 | - if( is_null($path) ) |
|
| 160 | + if ('/'===$filePath{0} ) { |
|
| 161 | + if (is_null($path)) |
|
| 162 | 162 | { return $filePath; } |
| 163 | 163 | else |
| 164 | 164 | { return $this->basePath.$filePath; } |
| 165 | - }else{ |
|
| 166 | - if( !strlen($path) ) |
|
| 165 | + }else { |
|
| 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; } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param string $filePath |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - public function getFileContent( string$filePath ):string |
|
| 182 | + public function getFileContent(string$filePath):string |
|
| 183 | 183 | { |
| 184 | 184 | return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath); |
| 185 | 185 | } |
@@ -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 | |
@@ -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. |
@@ -140,16 +140,16 @@ discard block |
||
| 140 | 140 | * @param \Htsl\ReadingBuffer\Contracts\ABuffer $buffer |
| 141 | 141 | * @param \Htsl\Parser\Document | null $parent |
| 142 | 142 | */ |
| 143 | - public function __construct( Htsl$htsl, Buffer$buffer, self$parent=null ) |
|
| 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 | - if( $parent ){ |
|
| 149 | - $this->parent= $parent; |
|
| 150 | - $this->docType= $parent->docType; |
|
| 151 | - $this->indentation= $parent->indentation; |
|
| 152 | - }else{ |
|
| 148 | + if ($parent) { |
|
| 149 | + $this->parent=$parent; |
|
| 150 | + $this->docType=$parent->docType; |
|
| 151 | + $this->indentation=$parent->indentation; |
|
| 152 | + }else { |
|
| 153 | 153 | $this->parseFirstLine(); |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function execute():self |
| 163 | 163 | { |
| 164 | - if( $this->isExecuted ){ |
|
| 164 | + if ($this->isExecuted) { |
|
| 165 | 165 | return $this; |
| 166 | 166 | } |
| 167 | 167 | return $this->lineByLine() |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | protected function getContent():string |
| 188 | 188 | { |
| 189 | - if( $this->parent ){ |
|
| 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 | } |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | protected function getLine():Line |
| 202 | 202 | { |
| 203 | - do{ |
|
| 204 | - $line= $this->buffer->getLine(); |
|
| 205 | - }while( $line->isEmpty() && $line->hasMore() ); |
|
| 203 | + do { |
|
| 204 | + $line=$this->buffer->getLine(); |
|
| 205 | + } while ($line->isEmpty() && $line->hasMore()); |
|
| 206 | 206 | |
| 207 | 207 | return $line; |
| 208 | 208 | } |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | * @param [ string, ] ...$keys |
| 214 | 214 | * @return mixed |
| 215 | 215 | */ |
| 216 | - public function getConfig( string...$keys ) |
|
| 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 | - if( '@'===$line->getChar(0) ){ |
|
| 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 | |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @param \Htsl\ReadingBuffer\Line $firstLine |
| 278 | 278 | */ |
| 279 | - protected function setExtending( Line$firstLine ):self |
|
| 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,12 +302,12 @@ 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 | - if( $this->embedment ){ |
|
| 308 | + if ($this->embedment) { |
|
| 309 | 309 | $this->embeddingParse($line); |
| 310 | - }else{ |
|
| 310 | + }else { |
|
| 311 | 311 | $this->parseLine($line); |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -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 | } |
@@ -328,11 +328,11 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @return \Htsl\Parser\Document |
| 330 | 330 | */ |
| 331 | - protected function embeddingParse( Line$line ):self |
|
| 331 | + protected function embeddingParse(Line$line):self |
|
| 332 | 332 | { |
| 333 | - if( $line->content==='<}' ){ |
|
| 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; |
@@ -345,12 +345,12 @@ discard block |
||
| 345 | 345 | * |
| 346 | 346 | * @return \Htsl\Parser\Document |
| 347 | 347 | */ |
| 348 | - protected function startEmbedding( string$embedType ):self |
|
| 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 | } |
@@ -375,17 +375,17 @@ discard block |
||
| 375 | 375 | * |
| 376 | 376 | * @return \Htsl\Parser\Document |
| 377 | 377 | */ |
| 378 | - protected function parseLine( Line$line ):self |
|
| 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 | - switch( $line->getChar(0) ){ |
|
| 383 | + switch ($line->getChar(0)) { |
|
| 384 | 384 | default:{ |
| 385 | 385 | $this->parseStringLine($line); |
| 386 | 386 | }break; |
| 387 | 387 | case '`':{ |
| 388 | - if( '='===$line->getChar(1) ) |
|
| 388 | + if ('='===$line->getChar(1)) |
|
| 389 | 389 | { $this->parseExpressionHtmlLine($line); } |
| 390 | 390 | else |
| 391 | 391 | { $this->parseHtmlLine($line); } |
@@ -416,9 +416,9 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @return \Htsl\Parser\Document |
| 418 | 418 | */ |
| 419 | - protected function parseHtmlLine( Line$line ):self |
|
| 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 | |
@@ -434,9 +434,9 @@ discard block |
||
| 434 | 434 | * |
| 435 | 435 | * @return \Htsl\Parser\Document |
| 436 | 436 | */ |
| 437 | - protected function parseStringLine( Line$line ):self |
|
| 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 | |
@@ -452,14 +452,14 @@ discard block |
||
| 452 | 452 | * |
| 453 | 453 | * @return \Htsl\Parser\Document |
| 454 | 454 | */ |
| 455 | - protected function parseExpressionLine( Line$line ):self |
|
| 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 | |
@@ -473,13 +473,13 @@ discard block |
||
| 473 | 473 | * |
| 474 | 474 | * @return \Htsl\Parser\Document |
| 475 | 475 | */ |
| 476 | - protected function parseExpressionHtmlLine( Line$line ):self |
|
| 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 | |
@@ -493,9 +493,9 @@ discard block |
||
| 493 | 493 | * |
| 494 | 494 | * @return \Htsl\Parser\Document |
| 495 | 495 | */ |
| 496 | - protected function parseCommentLine( Line$line ):self |
|
| 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 | |
@@ -511,9 +511,9 @@ discard block |
||
| 511 | 511 | * |
| 512 | 512 | * @return \Htsl\Parser\Document |
| 513 | 513 | */ |
| 514 | - protected function parseTagLine( Line$line ):self |
|
| 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 | |
@@ -531,9 +531,9 @@ discard block |
||
| 531 | 531 | * |
| 532 | 532 | * @return \Htsl\Parser\Document |
| 533 | 533 | */ |
| 534 | - protected function parseControlLine( Line$line ):self |
|
| 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 | |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | * |
| 550 | 550 | * @return \Htsl\Parser\Document |
| 551 | 551 | */ |
| 552 | - protected function parseDocControlLine( Line$line ):self |
|
| 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; |
@@ -579,12 +579,12 @@ discard block |
||
| 579 | 579 | * |
| 580 | 580 | * @return \Htsl\Parser\Document |
| 581 | 581 | */ |
| 582 | - protected function extend( string$fileName ):self |
|
| 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 | - if( false!==$this->indentation ){ |
|
| 604 | - $inclued= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level-$this->sectionLevel),$inclued); |
|
| 603 | + if (false!==$this->indentation) { |
|
| 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 | |
@@ -620,9 +620,9 @@ discard block |
||
| 620 | 620 | * |
| 621 | 621 | * @return \Htsl\Parser\Document |
| 622 | 622 | */ |
| 623 | - protected function defineSection( Line$line ):self |
|
| 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 | |
@@ -638,24 +638,24 @@ discard block |
||
| 638 | 638 | * |
| 639 | 639 | * @return \Htsl\Parser\Document |
| 640 | 640 | */ |
| 641 | - protected function showSection( Line$line ):self |
|
| 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 | - if( false!==$this->indentation ){ |
|
| 653 | - $content= preg_replace('/(?<=^|\\n)(?!$)/',str_repeat($this->indentation,$this->level),$content); |
|
| 652 | + if (false!==$this->indentation) { |
|
| 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 | |
@@ -669,30 +669,30 @@ discard block |
||
| 669 | 669 | * |
| 670 | 670 | * @param Section | null $section |
| 671 | 671 | */ |
| 672 | - public function setSection( Section$section=null ):self |
|
| 672 | + public function setSection(Section$section=null):self |
|
| 673 | 673 | { |
| 674 | - if( !$section ){ |
|
| 675 | - $this->sectionLevel= 0; |
|
| 676 | - $this->currentSection= null; |
|
| 674 | + if (!$section) { |
|
| 675 | + $this->sectionLevel=0; |
|
| 676 | + $this->currentSection=null; |
|
| 677 | 677 | |
| 678 | 678 | return $this; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - if( $this->currentSection ){ |
|
| 681 | + if ($this->currentSection) { |
|
| 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 | - if( $section->name ){ |
|
| 691 | + if ($section->name) { |
|
| 692 | 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 | } |
@@ -704,9 +704,9 @@ discard block |
||
| 704 | 704 | */ |
| 705 | 705 | protected function bubbleSections():self |
| 706 | 706 | { |
| 707 | - if( $this->parent ){ |
|
| 708 | - foreach( $this->sections as $name=>$section ){ |
|
| 709 | - if( !isset($this->parent->sections[$name]) ){ |
|
| 707 | + if ($this->parent) { |
|
| 708 | + foreach ($this->sections as $name=>$section) { |
|
| 709 | + if (!isset($this->parent->sections[$name])) { |
|
| 710 | 710 | $this->parent->sections[$name]=$section; |
| 711 | 711 | }; |
| 712 | 712 | } |
@@ -722,9 +722,9 @@ discard block |
||
| 722 | 722 | * |
| 723 | 723 | * @return string |
| 724 | 724 | */ |
| 725 | - public function htmlEntities( string$input ):string |
|
| 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 | /** |
@@ -732,15 +732,15 @@ discard block |
||
| 732 | 732 | * |
| 733 | 733 | * @param int $level |
| 734 | 734 | */ |
| 735 | - protected function setLevel( int$level ):self |
|
| 735 | + protected function setLevel(int$level):self |
|
| 736 | 736 | { |
| 737 | - $level-= $this->level; |
|
| 737 | + $level-=$this->level; |
|
| 738 | 738 | |
| 739 | - if( $level<=0 ){ |
|
| 739 | + if ($level <= 0) { |
|
| 740 | 740 | $this->closeNodes(-$level); |
| 741 | - }elseif( $level==1 ){ |
|
| 742 | - $this->level+= 1; |
|
| 743 | - }else{ |
|
| 741 | + }elseif ($level==1) { |
|
| 742 | + $this->level+=1; |
|
| 743 | + }else { |
|
| 744 | 744 | $this->throw('Indent error.'); |
| 745 | 745 | } |
| 746 | 746 | |
@@ -754,9 +754,9 @@ discard block |
||
| 754 | 754 | * |
| 755 | 755 | * @return \Htsl\Parser\Document |
| 756 | 756 | */ |
| 757 | - protected function openNode( Node$node ):self |
|
| 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 | |
@@ -770,18 +770,18 @@ discard block |
||
| 770 | 770 | * |
| 771 | 771 | * @return \Htsl\Parser\Document |
| 772 | 772 | */ |
| 773 | - protected function closeNodes( int$level=0 ):self |
|
| 773 | + protected function closeNodes(int$level=0):self |
|
| 774 | 774 | { |
| 775 | - if( empty($this->openedNodes) ) return $this; |
|
| 775 | + if (empty($this->openedNodes)) return $this; |
|
| 776 | 776 | |
| 777 | - while( $level-->=0 ){ |
|
| 778 | - $node= array_pop($this->openedNodes); |
|
| 777 | + while ($level-- >= 0) { |
|
| 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; |
@@ -792,9 +792,9 @@ discard block |
||
| 792 | 792 | * |
| 793 | 793 | * @param \Htsl\Parser\Node\Contracts\ANode $scope |
| 794 | 794 | */ |
| 795 | - protected function setScope( Node$scope ):int |
|
| 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 | /** |
@@ -814,9 +814,9 @@ discard block |
||
| 814 | 814 | * |
| 815 | 815 | * @return \Htsl\Parser\Document |
| 816 | 816 | */ |
| 817 | - protected function removeScope( Node$scope ):self |
|
| 817 | + protected function removeScope(Node$scope):self |
|
| 818 | 818 | { |
| 819 | - if( $scope!==array_shift($this->scopes) ){ |
|
| 819 | + if ($scope!==array_shift($this->scopes)) { |
|
| 820 | 820 | $this->throw('Scope nesting error'); |
| 821 | 821 | }; |
| 822 | 822 | |
@@ -830,10 +830,10 @@ discard block |
||
| 830 | 830 | * |
| 831 | 831 | * @return \Htsl\Parser\Document |
| 832 | 832 | */ |
| 833 | - protected function appendLine( string$content ):self |
|
| 833 | + protected function appendLine(string$content):self |
|
| 834 | 834 | { |
| 835 | - if( false!==$this->indentation ){ |
|
| 836 | - $content= str_repeat($this->indentation,$this->level-$this->sectionLevel).$content."\n"; |
|
| 835 | + if (false!==$this->indentation) { |
|
| 836 | + $content=str_repeat($this->indentation, $this->level-$this->sectionLevel).$content."\n"; |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | return $this->append($content); |
@@ -846,11 +846,11 @@ discard block |
||
| 846 | 846 | * |
| 847 | 847 | * @return \Htsl\Parser\Document |
| 848 | 848 | */ |
| 849 | - protected function append( string$content ):self |
|
| 849 | + protected function append(string$content):self |
|
| 850 | 850 | { |
| 851 | - if( $this->currentSection ){ |
|
| 851 | + if ($this->currentSection) { |
|
| 852 | 852 | $this->currentSection->append($content); |
| 853 | - }else{ |
|
| 853 | + }else { |
|
| 854 | 854 | $this->content.=$content; |
| 855 | 855 | } |
| 856 | 856 | |
@@ -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 | |
@@ -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 | { |
@@ -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 | 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); }); |
|
| 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']) ) |
|
| 62 | + if (isset($this->config['opener'])) |
|
| 63 | 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 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public function close( Line$Line ):string |
|
| 97 | + public function close(Line$Line):string |
|
| 98 | 98 | { |
| 99 | 99 | return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>"; |
| 100 | 100 | } |
@@ -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); |
|
| 160 | - |
|
| 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); |
|
| 166 | - }elseif( '\\\\'===$firstTwoLetters ){ |
|
| 167 | - $this->setAttribute($this->config['link'],'https://'.substr($link,2)); |
|
| 168 | - }else{ |
|
| 169 | - $this->setAttribute($this->config['link'],$this->checkExpression($link)); |
|
| 159 | + $link=$this->line->pregGet('/ @((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1); |
|
| 160 | + |
|
| 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); |
|
| 166 | + }elseif ('\\\\'===$firstTwoLetters) { |
|
| 167 | + $this->setAttribute($this->config['link'], 'https://'.substr($link, 2)); |
|
| 168 | + }else { |
|
| 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 | - if( strlen($target) ){ |
|
| 186 | - $this->setAttribute($this->config['target'],$this->checkExpression($target)); |
|
| 185 | + if (strlen($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 | - if( strlen($alt) ){ |
|
| 202 | - $this->setAttribute($this->config['alt'],$this->checkExpression($alt)); |
|
| 201 | + if (strlen($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('/(?<=\{).*?(?=;\}( |$))/') |
|
| 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); |
|
| 236 | + $other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
| 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); |
|
| 240 | 240 | },$keyValue); |
| 241 | - },explode(';',$other)); |
|
| 241 | + },explode(';', $other)); |
|
| 242 | 242 | |
| 243 | 243 | return $attributes; |
| 244 | 244 | } |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | - protected function checkExpression( string$value ):string |
|
| 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'])? |
|
| 266 | + return implode('', array_map(static function(string$key, array$data) { |
|
| 267 | + return (isset($data['condition']) && strlen($data['condition']) ? |
|
| 268 | 268 | "<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>" |
| 269 | 269 | : |
| 270 | 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 | /** |
@@ -279,9 +279,9 @@ discard block |
||
| 279 | 279 | * @param string $value Attribute value |
| 280 | 280 | * @param string|null $condition Optional condition, If given, attribute will seted only when condition is true. |
| 281 | 281 | */ |
| 282 | - protected function setAttribute( string$key, string$value, string$condition=null ):self |
|
| 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 | 287 | $this->attributes[$key]=[ |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | * |
| 305 | 305 | * @return bool |
| 306 | 306 | */ |
| 307 | - public function offsetExists( $offset ):bool |
|
| 307 | + public function offsetExists($offset):bool |
|
| 308 | 308 | { |
| 309 | 309 | return isset($this->attributes[$offset]); |
| 310 | 310 | } |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | * |
| 317 | 317 | * @return mixed |
| 318 | 318 | */ |
| 319 | - public function offsetGet( $offset ) |
|
| 319 | + public function offsetGet($offset) |
|
| 320 | 320 | { |
| 321 | 321 | return $this->attributes[$offset]??null; |
| 322 | 322 | } |
@@ -327,9 +327,9 @@ discard block |
||
| 327 | 327 | * @param mixed $offset |
| 328 | 328 | * @param mixed $value |
| 329 | 329 | */ |
| 330 | - public function offsetSet( $offset, $value ) |
|
| 330 | + public function offsetSet($offset, $value) |
|
| 331 | 331 | { |
| 332 | - $this->setAttribute($offset,$value); |
|
| 332 | + $this->setAttribute($offset, $value); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -337,9 +337,9 @@ discard block |
||
| 337 | 337 | * |
| 338 | 338 | * @param mixed $offset |
| 339 | 339 | */ |
| 340 | - public function offsetUnset( $offset ) |
|
| 340 | + public function offsetUnset($offset) |
|
| 341 | 341 | { |
| 342 | - if( isset($this->attributes[$offset]) ) |
|
| 342 | + if (isset($this->attributes[$offset])) |
|
| 343 | 343 | { unset($this->attributes[$offset]); } |
| 344 | 344 | } |
| 345 | 345 | } |
@@ -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 | } |
@@ -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 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @var string |
| 25 | 25 | */ |
| 26 | - protected $fileName= ''; |
|
| 26 | + protected $fileName=''; |
|
| 27 | 27 | |
| 28 | - public function __construct( Htsl$htsl ) |
|
| 28 | + public function __construct(Htsl$htsl) |
|
| 29 | 29 | { |
| 30 | - $this->htsl= $htsl; |
|
| 30 | + $this->htsl=$htsl; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -52,5 +52,5 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return \Htsl\ReadingBuffer\Contracts\ABuffer |
| 54 | 54 | */ |
| 55 | - abstract public function goSide( $fileName ):self; |
|
| 55 | + abstract public function goSide($fileName):self; |
|
| 56 | 56 | } |