| @@ -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 | } | 
| @@ -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 | } | 
| @@ -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 | } | 
| @@ -33,7 +33,7 @@ discard block | ||
| 33 | 33 |  	{ | 
| 34 | 34 | false===$content and $this->isLast=true; | 
| 35 | 35 | |
| 36 | - $this->content= rtrim($content,"\n"); | |
| 36 | + $this->content=rtrim($content, "\n"); | |
| 37 | 37 | } | 
| 38 | 38 | |
| 39 | 39 | /** | 
| @@ -43,7 +43,7 @@ discard block | ||
| 43 | 43 | */ | 
| 44 | 44 | public function getContent():string | 
| 45 | 45 |  	{ | 
| 46 | - return ltrim($this->content,"\t"); | |
| 46 | + return ltrim($this->content, "\t"); | |
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | /** | 
| @@ -66,7 +66,7 @@ discard block | ||
| 66 | 66 | */ | 
| 67 | 67 | public function slice( int$start=0, int...$lengths ):string | 
| 68 | 68 |  	{ | 
| 69 | - return substr($this->getContent(),$start,...array_slice($lengths,0,1)); | |
| 69 | + return substr($this->getContent(), $start, ...array_slice($lengths, 0, 1)); | |
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | 72 | /** | 
| @@ -78,7 +78,7 @@ discard block | ||
| 78 | 78 | */ | 
| 79 | 79 | public function getChar( int$offset ):string | 
| 80 | 80 |  	{ | 
| 81 | - return substr($this->getcontent(),$offset,1); | |
| 81 | + return substr($this->getcontent(), $offset, 1); | |
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | 84 | /** | 
| @@ -90,7 +90,7 @@ discard block | ||
| 90 | 90 | */ | 
| 91 | 91 | public function pregMatch( string$pattern ):bool | 
| 92 | 92 |  	{ | 
| 93 | - return !!preg_match($pattern,ltrim($this->content,"\t")); | |
| 93 | + return !!preg_match($pattern, ltrim($this->content, "\t")); | |
| 94 | 94 | } | 
| 95 | 95 | |
| 96 | 96 | /** | 
| @@ -103,8 +103,8 @@ discard block | ||
| 103 | 103 | */ | 
| 104 | 104 | public function pregGet( string$pattern, /*int|string*/$match=0 ):string | 
| 105 | 105 |  	{ | 
| 106 | - preg_match($pattern,ltrim($this->content,"\t"),$matches); | |
| 107 | - return $matches[$match]??''; | |
| 106 | + preg_match($pattern, ltrim($this->content, "\t"), $matches); | |
| 107 | + return $matches[ $match ]??''; | |
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 | /** | 
| @@ -117,8 +117,8 @@ discard block | ||
| 117 | 117 | */ | 
| 118 | 118 | public function pregMap( string$pattern, callable$callback ):array | 
| 119 | 119 |  	{ | 
| 120 | - preg_match_all($pattern,ltrim($this->content,"\t"),$matches); | |
| 121 | - return array_map($callback,...$matches); | |
| 120 | + preg_match_all($pattern, ltrim($this->content, "\t"), $matches); | |
| 121 | + return array_map($callback, ...$matches); | |
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | /** | 
| @@ -130,7 +130,7 @@ discard block | ||
| 130 | 130 |  	{ | 
| 131 | 131 |  		// return (static function( $a ):int{$i=0;while($a{$i}==="\t")++$i;return $i;})($this->content); | 
| 132 | 132 | |
| 133 | - return strlen($this->content)-strlen(ltrim($this->content,"\t")); | |
| 133 | + return strlen($this->content)-strlen(ltrim($this->content, "\t")); | |
| 134 | 134 | } | 
| 135 | 135 | |
| 136 | 136 | /** | 
| @@ -190,6 +190,6 @@ discard block | ||
| 190 | 190 | */ | 
| 191 | 191 | public function getSubIndentLine():self | 
| 192 | 192 |  	{ | 
| 193 | - return new static(ltrim($this->getContent(),' ')); | |
| 193 | + return new static(ltrim($this->getContent(), ' ')); | |
| 194 | 194 | } | 
| 195 | 195 | } |