@@ -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 | /** |
@@ -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); |
@@ -136,9 +136,9 @@ |
||
| 136 | 136 | } |
| 137 | 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'])) ){ |
|
| 139 | + } elseif( isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope,$config['only_in'])) ){ |
|
| 140 | 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'])) ){ |
|
| 141 | + } elseif( isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope,$config['not_in'])) ){ |
|
| 142 | 142 | $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',',$config['not_in'])); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -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 | } |
@@ -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 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @var array |
| 52 | 52 | */ |
| 53 | - private $attributes=[]; |
|
| 53 | + private $attributes=[ ]; |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Real constructor. |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | protected function construct():parent |
| 63 | 63 | { |
| 64 | 64 | |
| 65 | - $name= $this->line->pregGet('/(?<=^-)[\w-:]+/'); |
|
| 65 | + $name=$this->line->pregGet('/(?<=^-)[\w-:]+/'); |
|
| 66 | 66 | $this->name=$name; |
| 67 | 67 | |
| 68 | - $this->loadConfig($name,$this->document); |
|
| 68 | + $this->loadConfig($name, $this->document); |
|
| 69 | 69 | |
| 70 | - $this->tagName=$this->config['name']??$name; |
|
| 71 | - $this->isEmpty= $this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags',$this->tagName); |
|
| 72 | - isset($this->config['default_attributes']) and array_walk($this->config['default_attributes'],function( $value,$key ){ $this->setAttribute($key,$value); }); |
|
| 70 | + $this->tagName=$this->config[ 'name' ]??$name; |
|
| 71 | + $this->isEmpty=$this->line->getChar(-1)==='/' || $this->document->getConfig('empty_tags', $this->tagName); |
|
| 72 | + isset($this->config[ 'default_attributes' ]) and array_walk($this->config[ 'default_attributes' ], function( $value, $key ){ $this->setAttribute($key, $value); }); |
|
| 73 | 73 | |
| 74 | 74 | return $this; |
| 75 | 75 | } |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function open():string |
| 85 | 85 | { |
| 86 | - if( isset($this->config['opener']) ) |
|
| 87 | - { return $this->config['opener']; } |
|
| 86 | + if( isset($this->config[ 'opener' ]) ) |
|
| 87 | + { return $this->config[ 'opener' ]; } |
|
| 88 | 88 | |
| 89 | 89 | $this->parsePrivateAttributes(); |
| 90 | 90 | $this->parseCommonAttributes(); |
| 91 | 91 | |
| 92 | - if( isset($this->config['in_scope']) && isset($this->config['scope_function']) && is_callable($this->config['scope_function']) ) |
|
| 93 | - { $this->config['scope_function']->call($this,$this->document->scope); } |
|
| 92 | + if( isset($this->config[ 'in_scope' ]) && isset($this->config[ 'scope_function' ]) && is_callable($this->config[ 'scope_function' ]) ) |
|
| 93 | + { $this->config[ 'scope_function' ]->call($this, $this->document->scope); } |
|
| 94 | 94 | |
| 95 | - $finisher= $this->isEmpty ? ' />' : '>'; |
|
| 95 | + $finisher=$this->isEmpty? ' />' : '>'; |
|
| 96 | 96 | |
| 97 | 97 | return "<{$this->tagName}{$this->attributesString}{$finisher}"; |
| 98 | 98 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function close( Line$closerLine ):string |
| 110 | 110 | { |
| 111 | - return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>"; |
|
| 111 | + return $this->isEmpty? '' : $this->config[ 'closer' ]??"</{$this->tagName}>"; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function getEmbed():string |
| 122 | 122 | { |
| 123 | - return $this->config['embedding']??''; |
|
| 123 | + return $this->config[ 'embedding' ]??''; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public function getScope() |
| 134 | 134 | { |
| 135 | - return $this->config['scope']??null; |
|
| 135 | + return $this->config[ 'scope' ]??null; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | protected function parsePrivateAttributes():self |
| 146 | 146 | { |
| 147 | 147 | foreach( self::PRIVATE_ATTRIBUTES as $attribute ){ |
| 148 | - isset($this->config[$attribute]) and $this->{'parse'.Helper\camel_case($attribute)}(); |
|
| 148 | + isset($this->config[ $attribute ]) and $this->{'parse'.Helper\camel_case($attribute)}(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | return $this; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @todo Make this const private when php 7.1 |
| 162 | 162 | */ |
| 163 | - const PRIVATE_ATTRIBUTES= [ |
|
| 163 | + const PRIVATE_ATTRIBUTES=[ |
|
| 164 | 164 | 'params', |
| 165 | 165 | 'name_value', |
| 166 | 166 | 'link', |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | protected function parseParams():self |
| 179 | 179 | { |
| 180 | - $params= preg_split('/(?<!\\\\)\\|/',$this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/',1)); |
|
| 180 | + $params=preg_split('/(?<!\\\\)\\|/', $this->line->pregGet('/^-[\w-:]+\((.*?)\)(?= |(\\{>)?$)/', 1)); |
|
| 181 | 181 | |
| 182 | - if( ($m= count($params)) != ($n= count($this->config['params'])) ){$this->document->throw("Tag $this->name has $n parameters $m given.");} |
|
| 182 | + if( ($m=count($params))!=($n=count($this->config[ 'params' ])) ){$this->document->throw("Tag $this->name has $n parameters $m given."); } |
|
| 183 | 183 | |
| 184 | - array_map(function( $key, $value ){return $this->setAttribute($key,str_replace('\\|','|',$value));},$this->config['params'],$params); |
|
| 184 | + array_map(function( $key, $value ){return $this->setAttribute($key, str_replace('\\|', '|', $value)); },$this->config[ 'params' ], $params); |
|
| 185 | 185 | |
| 186 | 186 | return $this; |
| 187 | 187 | } |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | protected function parseNameValue():self |
| 197 | 197 | { |
| 198 | - $params= $this->line->pregGet('/ <(.*?)>(?= |$)/',1) |
|
| 199 | - and $params= preg_split('/(?<!\\\\)\\|/',$params) |
|
| 200 | - and array_map(function( $key, $value ){return isset($key)&&isset($value) ? $this->setAttribute($key,$this->checkExpression(str_replace('\\|','|',$value))) : '';},$this->config['name_value'],$params); |
|
| 198 | + $params=$this->line->pregGet('/ <(.*?)>(?= |$)/', 1) |
|
| 199 | + and $params=preg_split('/(?<!\\\\)\\|/', $params) |
|
| 200 | + and array_map(function( $key, $value ){return isset($key) && isset($value)? $this->setAttribute($key, $this->checkExpression(str_replace('\\|', '|', $value))) : ''; },$this->config[ 'name_value' ], $params); |
|
| 201 | 201 | |
| 202 | 202 | return $this; |
| 203 | 203 | } |
@@ -239,13 +239,13 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | protected function parseLink():self |
| 241 | 241 | { |
| 242 | - return $this->setMultinameAttribute('link',$this->sectionLedBy('@',true),function( string$link ){ |
|
| 243 | - if( isset($this->config['target']) && ':'===$link{0} ){ |
|
| 242 | + return $this->setMultinameAttribute('link', $this->sectionLedBy('@', true), function( string$link ){ |
|
| 243 | + if( isset($this->config[ 'target' ]) && ':'===$link{0} ){ |
|
| 244 | 244 | return 'javascript'.$link; |
| 245 | - }elseif( '//'===($firstTwoLetters=substr($link,0,2)) ){ |
|
| 245 | + }elseif( '//'===($firstTwoLetters=substr($link, 0, 2)) ){ |
|
| 246 | 246 | return 'http:'.$link; |
| 247 | 247 | }elseif( '\\\\'===$firstTwoLetters ){ |
| 248 | - return 'https://'.substr($link,2); |
|
| 248 | + return 'https://'.substr($link, 2); |
|
| 249 | 249 | }else{ |
| 250 | 250 | return $this->checkExpression($link); |
| 251 | 251 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | protected function parseTarget():self |
| 263 | 263 | { |
| 264 | - return $this->setMultinameAttribute('target',$this->sectionLedBy('>',true)); |
|
| 264 | + return $this->setMultinameAttribute('target', $this->sectionLedBy('>', true)); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | protected function parseAlt():self |
| 275 | 275 | { |
| 276 | - return $this->setMultinameAttribute('alt',$this->sectionLedBy('_',true)); |
|
| 276 | + return $this->setMultinameAttribute('alt', $this->sectionLedBy('_', true)); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | */ |
| 290 | 290 | private function setMultinameAttribute( string$name, string$value, callable$processer=null ):self |
| 291 | 291 | { |
| 292 | - if( strlen($value) && !empty($this->config[$name]) ){ |
|
| 293 | - return $this->setAttribute($this->config[$name],call_user_func($processer??[$this,'checkExpression',],$value)); |
|
| 292 | + if( strlen($value) && !empty($this->config[ $name ]) ){ |
|
| 293 | + return $this->setAttribute($this->config[ $name ], call_user_func($processer??[ $this, 'checkExpression', ], $value)); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | return $this; |
@@ -305,33 +305,33 @@ discard block |
||
| 305 | 305 | */ |
| 306 | 306 | protected function parseCommonAttributes():string |
| 307 | 307 | { |
| 308 | - $attributes= ''; |
|
| 308 | + $attributes=''; |
|
| 309 | 309 | |
| 310 | - $id= $this->sectionLedBy('#') |
|
| 311 | - and $this->setAttribute('id',$id); |
|
| 310 | + $id=$this->sectionLedBy('#') |
|
| 311 | + and $this->setAttribute('id', $id); |
|
| 312 | 312 | |
| 313 | - $classes= $this->line->pregGet('/ \.[^ ]+(?= |$)/') |
|
| 314 | - and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/',$classes,$matches) |
|
| 315 | - and $classes= implode(' ',array_filter(array_map(function( $className ){return $this->checkExpression($className);},$matches[1]))) |
|
| 316 | - and $this->setAttribute('class',$classes); |
|
| 313 | + $classes=$this->line->pregGet('/ \.[^ ]+(?= |$)/') |
|
| 314 | + and preg_match_all('/\.((?(?!\()[^.]+|(?<exp>\((?:[^()]+|(?&exp)?)+?\))))/', $classes, $matches) |
|
| 315 | + and $classes=implode(' ', array_filter(array_map(function( $className ){return $this->checkExpression($className); },$matches[ 1 ]))) |
|
| 316 | + and $this->setAttribute('class', $classes); |
|
| 317 | 317 | |
| 318 | - $title= $this->sectionLedBy('^',true) |
|
| 319 | - and $this->setAttribute('title',$title); |
|
| 318 | + $title=$this->sectionLedBy('^', true) |
|
| 319 | + and $this->setAttribute('title', $title); |
|
| 320 | 320 | |
| 321 | - $style= $this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/',1) |
|
| 322 | - and $this->setAttribute('style',$style); |
|
| 321 | + $style=$this->line->pregGet('/ \[([^\]]+;)(?=\]( |$))/', 1) |
|
| 322 | + and $this->setAttribute('style', $style); |
|
| 323 | 323 | |
| 324 | - $eventListeners= $this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/',function( $string, $name, $code ){ |
|
| 325 | - $this->setAttribute('on'.$name,str_replace('"','"',$code)); |
|
| 324 | + $eventListeners=$this->line->pregMap('/ %(\w+)\{>(.*?)<\}(?= |$)/', function( $string, $name, $code ){ |
|
| 325 | + $this->setAttribute('on'.$name, str_replace('"', '"', $code)); |
|
| 326 | 326 | }) |
| 327 | - and implode('',$eventListeners); |
|
| 327 | + and implode('', $eventListeners); |
|
| 328 | 328 | |
| 329 | - $other= $this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
| 329 | + $other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
| 330 | 330 | and array_map(function( $keyValue ){ |
| 331 | - preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/',function($matches){ |
|
| 332 | - $this->setAttribute($matches[1],(isset($matches[3])? $this->checkExpression($matches[3]) : $matches[1]),$matches[2]??null); |
|
| 331 | + preg_replace_callback('/^([\w-:]+)(?:\?(.+?))?(?:\=(.*))?$/', function( $matches ){ |
|
| 332 | + $this->setAttribute($matches[ 1 ], (isset($matches[ 3 ])? $this->checkExpression($matches[ 3 ]) : $matches[ 1 ]), $matches[ 2 ]??null); |
|
| 333 | 333 | },$keyValue); |
| 334 | - },explode(';',$other)); |
|
| 334 | + },explode(';', $other)); |
|
| 335 | 335 | |
| 336 | 336 | return $attributes; |
| 337 | 337 | } |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | protected function checkExpression( string$value ):string |
| 349 | 349 | { |
| 350 | - return preg_match('/^\(.*\)$/',$value) ? '<?=str_replace(\'"\',\'"\','.substr($value,1,-1).')?>' : str_replace('"','"',$value); |
|
| 350 | + return preg_match('/^\(.*\)$/', $value)? '<?=str_replace(\'"\',\'"\','.substr($value, 1, -1).')?>' : str_replace('"', '"', $value); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -360,13 +360,13 @@ discard block |
||
| 360 | 360 | protected function getAttributesString():string |
| 361 | 361 | { |
| 362 | 362 | ksort($this->attributes); |
| 363 | - return implode('',array_map(static function( string$key, array$data ){ |
|
| 364 | - return (isset($data['condition'])&&strlen($data['condition'])? |
|
| 365 | - "<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>" |
|
| 363 | + return implode('', array_map(static function( string$key, array$data ){ |
|
| 364 | + return (isset($data[ 'condition' ]) && strlen($data[ 'condition' ])? |
|
| 365 | + "<?php if( {$data[ 'condition' ]} ){?> $key=\"{$data[ 'value' ]}\"<?php }?>" |
|
| 366 | 366 | : |
| 367 | - " $key=\"{$data['value']}\"" |
|
| 367 | + " $key=\"{$data[ 'value' ]}\"" |
|
| 368 | 368 | ); |
| 369 | - },array_keys($this->attributes),$this->attributes)); |
|
| 369 | + },array_keys($this->attributes), $this->attributes)); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -380,10 +380,10 @@ discard block |
||
| 380 | 380 | */ |
| 381 | 381 | protected function setAttribute( string$key, string$value, string$condition=null ):self |
| 382 | 382 | { |
| 383 | - if( isset($this->attributes[$key]) ) |
|
| 383 | + if( isset($this->attributes[ $key ]) ) |
|
| 384 | 384 | { $this->document->throw("Attribute $key of $this->name cannot redeclare."); } |
| 385 | 385 | |
| 386 | - $this->attributes[$key]=[ |
|
| 386 | + $this->attributes[ $key ]=[ |
|
| 387 | 387 | 'value'=> $value, |
| 388 | 388 | 'condition'=> $condition, |
| 389 | 389 | ]; |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | */ |
| 408 | 408 | public function offsetExists( $offset ):bool |
| 409 | 409 | { |
| 410 | - return isset($this->attributes[$offset]); |
|
| 410 | + return isset($this->attributes[ $offset ]); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | */ |
| 422 | 422 | public function offsetGet( $offset ) |
| 423 | 423 | { |
| 424 | - return $this->attributes[$offset]??null; |
|
| 424 | + return $this->attributes[ $offset ]??null; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | */ |
| 435 | 435 | public function offsetSet( $offset, $value ) |
| 436 | 436 | { |
| 437 | - $this->setAttribute($offset,$value); |
|
| 437 | + $this->setAttribute($offset, $value); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | public function offsetUnset( $offset ) |
| 448 | 448 | { |
| 449 | - if( isset($this->attributes[$offset]) ) |
|
| 450 | - { unset($this->attributes[$offset]); } |
|
| 449 | + if( isset($this->attributes[ $offset ]) ) |
|
| 450 | + { unset($this->attributes[ $offset ]); } |
|
| 451 | 451 | } |
| 452 | 452 | } |
@@ -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); |
@@ -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 | } |
@@ -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 | /** |
@@ -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 | } |