@@ -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 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @var array |
| 32 | 32 | */ |
| 33 | - private $attributes=[]; |
|
| 33 | + private $attributes=[ ]; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Real constructor. |
@@ -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 | - $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); }); |
|
| 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); }); |
|
| 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']) ) |
|
| 63 | - { return $this->config['opener']; } |
|
| 62 | + if( isset($this->config[ 'opener' ]) ) |
|
| 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 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function close( Line$Line ):string |
| 98 | 98 | { |
| 99 | - return $this->isEmpty ? '' : $this->config['closer']??"</{$this->tagName}>"; |
|
| 99 | + return $this->isEmpty? '' : $this->config[ 'closer' ]??"</{$this->tagName}>"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function getEmbed():string |
| 108 | 108 | { |
| 109 | - return $this->config['embedding']??''; |
|
| 109 | + return $this->config[ 'embedding' ]??''; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function getScope() |
| 118 | 118 | { |
| 119 | - return $this->config['scope']??null; |
|
| 119 | + return $this->config[ 'scope' ]??null; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -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); |
|
| 159 | + $link=$this->line->pregGet('/ @((?!\()(?:[^ ]| (?=[a-zA-Z0-9]))+|(?<exp>\((?:[^()]+|(?&exp)?)+?\)))(?= |$)/', 1); |
|
| 160 | 160 | |
| 161 | 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); |
|
| 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 | 166 | }elseif( '\\\\'===$firstTwoLetters ){ |
| 167 | - $this->setAttribute($this->config['link'],'https://'.substr($link,2)); |
|
| 167 | + $this->setAttribute($this->config[ 'link' ], 'https://'.substr($link, 2)); |
|
| 168 | 168 | }else{ |
| 169 | - $this->setAttribute($this->config['link'],$this->checkExpression($link)); |
|
| 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 | 185 | if( strlen($target) ){ |
| 186 | - $this->setAttribute($this->config['target'],$this->checkExpression($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 | 201 | if( strlen($alt) ){ |
| 202 | - $this->setAttribute($this->config['alt'],$this->checkExpression($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('/(?<=\{).*?(?=;\}( |$))/') |
|
| 236 | + $other=$this->line->pregGet('/(?<=\{).*?(?=;\}( |$))/') |
|
| 237 | 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); |
|
| 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 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 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'])? |
|
| 268 | - "<?php if( {$data['condition']} ){?> $key=\"{$data['value']}\"<?php }?>" |
|
| 266 | + return implode('', array_map(static function( string$key, array$data ){ |
|
| 267 | + return (isset($data[ 'condition' ]) && strlen($data[ 'condition' ])? |
|
| 268 | + "<?php if( {$data[ 'condition' ]} ){?> $key=\"{$data[ 'value' ]}\"<?php }?>" |
|
| 269 | 269 | : |
| 270 | - " $key=\"{$data['value']}\"" |
|
| 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 | /** |
@@ -281,10 +281,10 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 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 | - $this->attributes[$key]=[ |
|
| 287 | + $this->attributes[ $key ]=[ |
|
| 288 | 288 | 'value'=> $value, |
| 289 | 289 | 'condition'=> $condition, |
| 290 | 290 | ]; |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | public function offsetExists( $offset ):bool |
| 308 | 308 | { |
| 309 | - return isset($this->attributes[$offset]); |
|
| 309 | + return isset($this->attributes[ $offset ]); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | public function offsetGet( $offset ) |
| 320 | 320 | { |
| 321 | - return $this->attributes[$offset]??null; |
|
| 321 | + return $this->attributes[ $offset ]??null; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | */ |
| 330 | 330 | public function offsetSet( $offset, $value ) |
| 331 | 331 | { |
| 332 | - $this->setAttribute($offset,$value); |
|
| 332 | + $this->setAttribute($offset, $value); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | public function offsetUnset( $offset ) |
| 341 | 341 | { |
| 342 | - if( isset($this->attributes[$offset]) ) |
|
| 343 | - { unset($this->attributes[$offset]); } |
|
| 342 | + if( isset($this->attributes[ $offset ]) ) |
|
| 343 | + { unset($this->attributes[ $offset ]); } |
|
| 344 | 344 | } |
| 345 | 345 | } |
@@ -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 | } |