@@ -8,5 +8,5 @@ |
||
| 8 | 8 | |
| 9 | 9 | class HtslParsingException extends Exception |
| 10 | 10 | { |
| 11 | - // |
|
| 11 | + // |
|
| 12 | 12 | } |
@@ -10,48 +10,48 @@ |
||
| 10 | 10 | |
| 11 | 11 | class NamelessSectionNode extends ANode |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The name of the section. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - private $name; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Real constructor. |
|
| 22 | - * |
|
| 23 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 24 | - */ |
|
| 25 | - protected function construct():parent |
|
| 26 | - { |
|
| 27 | - $this->name = null; |
|
| 28 | - |
|
| 29 | - return $this; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Opening this node, and returning node opener. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function open():string |
|
| 38 | - { |
|
| 39 | - $this->document->setSection(new Section($this->name)); |
|
| 40 | - |
|
| 41 | - return ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Close this node, and returning node closer. |
|
| 46 | - * |
|
| 47 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function close(Line $closerLine):string |
|
| 52 | - { |
|
| 53 | - $this->document->setSection(null); |
|
| 54 | - |
|
| 55 | - return ''; |
|
| 56 | - } |
|
| 13 | + /** |
|
| 14 | + * The name of the section. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + private $name; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Real constructor. |
|
| 22 | + * |
|
| 23 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 24 | + */ |
|
| 25 | + protected function construct():parent |
|
| 26 | + { |
|
| 27 | + $this->name = null; |
|
| 28 | + |
|
| 29 | + return $this; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Opening this node, and returning node opener. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function open():string |
|
| 38 | + { |
|
| 39 | + $this->document->setSection(new Section($this->name)); |
|
| 40 | + |
|
| 41 | + return ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Close this node, and returning node closer. |
|
| 46 | + * |
|
| 47 | + * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function close(Line $closerLine):string |
|
| 52 | + { |
|
| 53 | + $this->document->setSection(null); |
|
| 54 | + |
|
| 55 | + return ''; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | protected function construct():parent |
| 26 | 26 | { |
| 27 | - $this->name = null; |
|
| 27 | + $this->name=null; |
|
| 28 | 28 | |
| 29 | 29 | return $this; |
| 30 | 30 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | - public function close(Line $closerLine):string |
|
| 51 | + public function close( Line $closerLine ):string |
|
| 52 | 52 | { |
| 53 | 53 | $this->document->setSection(null); |
| 54 | 54 | |
@@ -12,145 +12,145 @@ |
||
| 12 | 12 | |
| 13 | 13 | abstract class ANode |
| 14 | 14 | { |
| 15 | - use TGetter; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * Htsl main object. |
|
| 19 | - * |
|
| 20 | - * @var \Htsl\Htsl |
|
| 21 | - */ |
|
| 22 | - protected $htsl; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * The document. |
|
| 26 | - * |
|
| 27 | - * @var \Htsl\Parser\Document |
|
| 28 | - */ |
|
| 29 | - protected $document; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The document. |
|
| 33 | - * |
|
| 34 | - * @var \Htsl\ReadingBuffer\Line |
|
| 35 | - */ |
|
| 36 | - protected $line; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * The config. |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $config; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Fake contructor of Node. |
|
| 47 | - * |
|
| 48 | - * @param \Htsl\Parser\Document $document |
|
| 49 | - * @param \Htsl\ReadingBuffer\Line $line |
|
| 50 | - */ |
|
| 51 | - final public function __construct(Document $document, Line $line) |
|
| 52 | - { |
|
| 53 | - $this->htsl = $document->htsl; |
|
| 54 | - $this->document = $document; |
|
| 55 | - $this->line = $line; |
|
| 56 | - |
|
| 57 | - $this->construct(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Real contructor to be rewrite. |
|
| 62 | - * |
|
| 63 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 64 | - */ |
|
| 65 | - abstract protected function construct():self; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Opening this node, and returning node opener. |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - abstract public function open():string; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Close this node, and returning node closer. |
|
| 76 | - * |
|
| 77 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 78 | - * |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - abstract public function close(Line $closerLine):string; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Getting whether this node contains a scope and scope name. |
|
| 85 | - * |
|
| 86 | - * @return string | null |
|
| 87 | - */ |
|
| 88 | - public function getScope() |
|
| 89 | - { |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Getting the type of this node. |
|
| 94 | - * |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function getNodeType() |
|
| 98 | - { |
|
| 99 | - static $nodeType; |
|
| 100 | - |
|
| 101 | - return $nodeType ?? $nodeType = $this->nodeType ?? (static function ($className) { |
|
| 102 | - return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_$1', preg_replace('/^(?:\\w+\\\\)*(\\w+)Node$/', '$1', $className))); |
|
| 103 | - })(get_class($this)); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Loading node configuration. |
|
| 108 | - * |
|
| 109 | - * @param string $name |
|
| 110 | - * @param \Htsl\Helper\IConfigProvider $configProvider |
|
| 111 | - * |
|
| 112 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 113 | - */ |
|
| 114 | - protected function loadConfig(string $name, IConfigProvider $configProvider) |
|
| 115 | - { |
|
| 116 | - $config = $configProvider->getConfig($this->nodeType.'_nodes', $name) ?: $configProvider->getConfig($this->nodeType.'_nodes', '*'); |
|
| 117 | - |
|
| 118 | - if (isset($config['multiple'])) { |
|
| 119 | - foreach ($config['multiple'] as $value) { |
|
| 120 | - if ($this->line->pregGet($value['pattern'])) { |
|
| 121 | - $config = $value; |
|
| 122 | - break; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if (isset($config['in'])) { |
|
| 128 | - $config = (function (array $config) use ($name) { |
|
| 129 | - foreach ($config['in'] as $key => $value) { |
|
| 130 | - if ($this->document->scope && $this->document->scope->scope === $key) { |
|
| 131 | - $value['in_scope'] = $key; |
|
| 132 | - |
|
| 133 | - return $value; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - if (!isset($config['out'])) { |
|
| 137 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config['in']))); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $config['out']; |
|
| 141 | - })($config); |
|
| 142 | - } elseif (isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['only_in']))) { |
|
| 143 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config['only_in'])); |
|
| 144 | - } elseif (isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['not_in']))) { |
|
| 145 | - $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config['not_in'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - if (!is_array($config)) { |
|
| 149 | - $this->document->throw("The $this->nodeType node $name is not supported."); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $this->config = $config; |
|
| 153 | - |
|
| 154 | - return $this; |
|
| 155 | - } |
|
| 15 | + use TGetter; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * Htsl main object. |
|
| 19 | + * |
|
| 20 | + * @var \Htsl\Htsl |
|
| 21 | + */ |
|
| 22 | + protected $htsl; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * The document. |
|
| 26 | + * |
|
| 27 | + * @var \Htsl\Parser\Document |
|
| 28 | + */ |
|
| 29 | + protected $document; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The document. |
|
| 33 | + * |
|
| 34 | + * @var \Htsl\ReadingBuffer\Line |
|
| 35 | + */ |
|
| 36 | + protected $line; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * The config. |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $config; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Fake contructor of Node. |
|
| 47 | + * |
|
| 48 | + * @param \Htsl\Parser\Document $document |
|
| 49 | + * @param \Htsl\ReadingBuffer\Line $line |
|
| 50 | + */ |
|
| 51 | + final public function __construct(Document $document, Line $line) |
|
| 52 | + { |
|
| 53 | + $this->htsl = $document->htsl; |
|
| 54 | + $this->document = $document; |
|
| 55 | + $this->line = $line; |
|
| 56 | + |
|
| 57 | + $this->construct(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Real contructor to be rewrite. |
|
| 62 | + * |
|
| 63 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 64 | + */ |
|
| 65 | + abstract protected function construct():self; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Opening this node, and returning node opener. |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + abstract public function open():string; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Close this node, and returning node closer. |
|
| 76 | + * |
|
| 77 | + * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 78 | + * |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + abstract public function close(Line $closerLine):string; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Getting whether this node contains a scope and scope name. |
|
| 85 | + * |
|
| 86 | + * @return string | null |
|
| 87 | + */ |
|
| 88 | + public function getScope() |
|
| 89 | + { |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Getting the type of this node. |
|
| 94 | + * |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function getNodeType() |
|
| 98 | + { |
|
| 99 | + static $nodeType; |
|
| 100 | + |
|
| 101 | + return $nodeType ?? $nodeType = $this->nodeType ?? (static function ($className) { |
|
| 102 | + return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_$1', preg_replace('/^(?:\\w+\\\\)*(\\w+)Node$/', '$1', $className))); |
|
| 103 | + })(get_class($this)); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Loading node configuration. |
|
| 108 | + * |
|
| 109 | + * @param string $name |
|
| 110 | + * @param \Htsl\Helper\IConfigProvider $configProvider |
|
| 111 | + * |
|
| 112 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 113 | + */ |
|
| 114 | + protected function loadConfig(string $name, IConfigProvider $configProvider) |
|
| 115 | + { |
|
| 116 | + $config = $configProvider->getConfig($this->nodeType.'_nodes', $name) ?: $configProvider->getConfig($this->nodeType.'_nodes', '*'); |
|
| 117 | + |
|
| 118 | + if (isset($config['multiple'])) { |
|
| 119 | + foreach ($config['multiple'] as $value) { |
|
| 120 | + if ($this->line->pregGet($value['pattern'])) { |
|
| 121 | + $config = $value; |
|
| 122 | + break; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if (isset($config['in'])) { |
|
| 128 | + $config = (function (array $config) use ($name) { |
|
| 129 | + foreach ($config['in'] as $key => $value) { |
|
| 130 | + if ($this->document->scope && $this->document->scope->scope === $key) { |
|
| 131 | + $value['in_scope'] = $key; |
|
| 132 | + |
|
| 133 | + return $value; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + if (!isset($config['out'])) { |
|
| 137 | + $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config['in']))); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $config['out']; |
|
| 141 | + })($config); |
|
| 142 | + } elseif (isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['only_in']))) { |
|
| 143 | + $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config['only_in'])); |
|
| 144 | + } elseif (isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['not_in']))) { |
|
| 145 | + $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config['not_in'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + if (!is_array($config)) { |
|
| 149 | + $this->document->throw("The $this->nodeType node $name is not supported."); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $this->config = $config; |
|
| 153 | + |
|
| 154 | + return $this; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | * @param \Htsl\Parser\Document $document |
| 49 | 49 | * @param \Htsl\ReadingBuffer\Line $line |
| 50 | 50 | */ |
| 51 | - final public function __construct(Document $document, Line $line) |
|
| 51 | + final public function __construct( Document $document, Line $line ) |
|
| 52 | 52 | { |
| 53 | - $this->htsl = $document->htsl; |
|
| 54 | - $this->document = $document; |
|
| 55 | - $this->line = $line; |
|
| 53 | + $this->htsl=$document->htsl; |
|
| 54 | + $this->document=$document; |
|
| 55 | + $this->line=$line; |
|
| 56 | 56 | |
| 57 | 57 | $this->construct(); |
| 58 | 58 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | - abstract public function close(Line $closerLine):string; |
|
| 81 | + abstract public function close( Line $closerLine ):string; |
|
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Getting whether this node contains a scope and scope name. |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | static $nodeType; |
| 100 | 100 | |
| 101 | - return $nodeType ?? $nodeType = $this->nodeType ?? (static function ($className) { |
|
| 101 | + return $nodeType ?? $nodeType=$this->nodeType ?? (static function( $className ){ |
|
| 102 | 102 | return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_$1', preg_replace('/^(?:\\w+\\\\)*(\\w+)Node$/', '$1', $className))); |
| 103 | 103 | })(get_class($this)); |
| 104 | 104 | } |
@@ -111,45 +111,45 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return \Htsl\Parser\Node\Contracts\ANode |
| 113 | 113 | */ |
| 114 | - protected function loadConfig(string $name, IConfigProvider $configProvider) |
|
| 114 | + protected function loadConfig( string $name, IConfigProvider $configProvider ) |
|
| 115 | 115 | { |
| 116 | - $config = $configProvider->getConfig($this->nodeType.'_nodes', $name) ?: $configProvider->getConfig($this->nodeType.'_nodes', '*'); |
|
| 116 | + $config=$configProvider->getConfig($this->nodeType.'_nodes', $name)?: $configProvider->getConfig($this->nodeType.'_nodes', '*'); |
|
| 117 | 117 | |
| 118 | - if (isset($config['multiple'])) { |
|
| 119 | - foreach ($config['multiple'] as $value) { |
|
| 120 | - if ($this->line->pregGet($value['pattern'])) { |
|
| 121 | - $config = $value; |
|
| 118 | + if( isset($config[ 'multiple' ]) ){ |
|
| 119 | + foreach( $config[ 'multiple' ] as $value ){ |
|
| 120 | + if( $this->line->pregGet($value[ 'pattern' ]) ){ |
|
| 121 | + $config=$value; |
|
| 122 | 122 | break; |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if (isset($config['in'])) { |
|
| 128 | - $config = (function (array $config) use ($name) { |
|
| 129 | - foreach ($config['in'] as $key => $value) { |
|
| 130 | - if ($this->document->scope && $this->document->scope->scope === $key) { |
|
| 131 | - $value['in_scope'] = $key; |
|
| 127 | + if( isset($config[ 'in' ]) ){ |
|
| 128 | + $config=(function( array $config ) use ($name) { |
|
| 129 | + foreach( $config[ 'in' ] as $key => $value ){ |
|
| 130 | + if( $this->document->scope && $this->document->scope->scope===$key ){ |
|
| 131 | + $value[ 'in_scope' ]=$key; |
|
| 132 | 132 | |
| 133 | 133 | return $value; |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | - if (!isset($config['out'])) { |
|
| 137 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config['in']))); |
|
| 136 | + if( !isset($config[ 'out' ]) ){ |
|
| 137 | + $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config[ 'in' ]))); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - return $config['out']; |
|
| 140 | + return $config[ 'out' ]; |
|
| 141 | 141 | })($config); |
| 142 | - } elseif (isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['only_in']))) { |
|
| 143 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config['only_in'])); |
|
| 144 | - } elseif (isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['not_in']))) { |
|
| 145 | - $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config['not_in'])); |
|
| 142 | + } elseif( isset($config[ 'only_in' ]) && (!$this->document->scope || !in_array($this->document->scope->scope, $config[ 'only_in' ])) ){ |
|
| 143 | + $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config[ 'only_in' ])); |
|
| 144 | + } elseif( isset($config[ 'not_in' ]) && (!$this->document->scope || !in_array($this->document->scope->scope, $config[ 'not_in' ])) ){ |
|
| 145 | + $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config[ 'not_in' ])); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if (!is_array($config)) { |
|
| 148 | + if( !is_array($config) ){ |
|
| 149 | 149 | $this->document->throw("The $this->nodeType node $name is not supported."); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $this->config = $config; |
|
| 152 | + $this->config=$config; |
|
| 153 | 153 | |
| 154 | 154 | return $this; |
| 155 | 155 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | static $nodeType; |
| 100 | 100 | |
| 101 | - return $nodeType ?? $nodeType = $this->nodeType ?? (static function ($className) { |
|
| 101 | + return $nodeType ?? $nodeType = $this->nodeType ?? (static function ($className){ |
|
| 102 | 102 | return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_$1', preg_replace('/^(?:\\w+\\\\)*(\\w+)Node$/', '$1', $className))); |
| 103 | 103 | })(get_class($this)); |
| 104 | 104 | } |
@@ -115,37 +115,37 @@ discard block |
||
| 115 | 115 | { |
| 116 | 116 | $config = $configProvider->getConfig($this->nodeType.'_nodes', $name) ?: $configProvider->getConfig($this->nodeType.'_nodes', '*'); |
| 117 | 117 | |
| 118 | - if (isset($config['multiple'])) { |
|
| 119 | - foreach ($config['multiple'] as $value) { |
|
| 120 | - if ($this->line->pregGet($value['pattern'])) { |
|
| 118 | + if (isset($config['multiple'])){ |
|
| 119 | + foreach ($config['multiple'] as $value){ |
|
| 120 | + if ($this->line->pregGet($value['pattern'])){ |
|
| 121 | 121 | $config = $value; |
| 122 | 122 | break; |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if (isset($config['in'])) { |
|
| 128 | - $config = (function (array $config) use ($name) { |
|
| 129 | - foreach ($config['in'] as $key => $value) { |
|
| 130 | - if ($this->document->scope && $this->document->scope->scope === $key) { |
|
| 127 | + if (isset($config['in'])){ |
|
| 128 | + $config = (function (array $config) use ($name){ |
|
| 129 | + foreach ($config['in'] as $key => $value){ |
|
| 130 | + if ($this->document->scope && $this->document->scope->scope === $key){ |
|
| 131 | 131 | $value['in_scope'] = $key; |
| 132 | 132 | |
| 133 | 133 | return $value; |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | - if (!isset($config['out'])) { |
|
| 136 | + if (!isset($config['out'])){ |
|
| 137 | 137 | $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config['in']))); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | return $config['out']; |
| 141 | 141 | })($config); |
| 142 | - } elseif (isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['only_in']))) { |
|
| 142 | + } elseif (isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['only_in']))){ |
|
| 143 | 143 | $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config['only_in'])); |
| 144 | - } elseif (isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['not_in']))) { |
|
| 144 | + } elseif (isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['not_in']))){ |
|
| 145 | 145 | $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config['not_in'])); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if (!is_array($config)) { |
|
| 148 | + if (!is_array($config)){ |
|
| 149 | 149 | $this->document->throw("The $this->nodeType node $name is not supported."); |
| 150 | 150 | } |
| 151 | 151 | |
@@ -134,19 +134,19 @@ |
||
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | if (!isset($config['out'])) { |
| 137 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', array_keys($config['in']))); |
|
| 137 | + $this->document->throw("the $this->nodeType node $name only use in scope ".implode(',', array_keys($config['in']))); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | return $config['out']; |
| 141 | 141 | })($config); |
| 142 | 142 | } elseif (isset($config['only_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['only_in']))) { |
| 143 | - $this->document->throw("The $this->nodeType node $name only use in scope ".implode(',', $config['only_in'])); |
|
| 143 | + $this->document->throw("the $this->nodeType node $name only use in scope ".implode(',', $config['only_in'])); |
|
| 144 | 144 | } elseif (isset($config['not_in']) && (!$this->document->scope || !in_array($this->document->scope->scope, $config['not_in']))) { |
| 145 | - $this->document->throw("The $this->nodeType node $name not use in scope ".implode(',', $config['not_in'])); |
|
| 145 | + $this->document->throw("the $this->nodeType node $name not use in scope ".implode(',', $config['not_in'])); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | if (!is_array($config)) { |
| 149 | - $this->document->throw("The $this->nodeType node $name is not supported."); |
|
| 149 | + $this->document->throw("the $this->nodeType node $name is not supported."); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | $this->config = $config; |
@@ -9,46 +9,46 @@ |
||
| 9 | 9 | |
| 10 | 10 | class CommentNode extends ANode |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Whether the comment is html comment. |
|
| 14 | - * |
|
| 15 | - * @var bool |
|
| 16 | - */ |
|
| 17 | - private $htmlComment; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Real contructor. |
|
| 21 | - * |
|
| 22 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 23 | - */ |
|
| 24 | - protected function construct():parent |
|
| 25 | - { |
|
| 26 | - $this->htmlComment = '!' !== $this->line->getChar(1); |
|
| 27 | - |
|
| 28 | - return $this; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Opening this node, and returning node opener. |
|
| 33 | - * |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function open():string |
|
| 37 | - { |
|
| 38 | - return $this->htmlComment ? |
|
| 39 | - '<!--'.str_replace('-->', '--'.chr(0xC).'>', substr($this->line->getContent(), 1)) : |
|
| 40 | - '<?php /* '.substr($this->line->getContent(), 2); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Close this node, and returning node closer. |
|
| 45 | - * |
|
| 46 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function close(Line $closerLine):string |
|
| 51 | - { |
|
| 52 | - return $this->htmlComment ? '-->' : ' */ ?>'; |
|
| 53 | - } |
|
| 12 | + /** |
|
| 13 | + * Whether the comment is html comment. |
|
| 14 | + * |
|
| 15 | + * @var bool |
|
| 16 | + */ |
|
| 17 | + private $htmlComment; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Real contructor. |
|
| 21 | + * |
|
| 22 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 23 | + */ |
|
| 24 | + protected function construct():parent |
|
| 25 | + { |
|
| 26 | + $this->htmlComment = '!' !== $this->line->getChar(1); |
|
| 27 | + |
|
| 28 | + return $this; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Opening this node, and returning node opener. |
|
| 33 | + * |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function open():string |
|
| 37 | + { |
|
| 38 | + return $this->htmlComment ? |
|
| 39 | + '<!--'.str_replace('-->', '--'.chr(0xC).'>', substr($this->line->getContent(), 1)) : |
|
| 40 | + '<?php /* '.substr($this->line->getContent(), 2); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Close this node, and returning node closer. |
|
| 45 | + * |
|
| 46 | + * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function close(Line $closerLine):string |
|
| 51 | + { |
|
| 52 | + return $this->htmlComment ? '-->' : ' */ ?>'; |
|
| 53 | + } |
|
| 54 | 54 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | protected function construct():parent |
| 25 | 25 | { |
| 26 | - $this->htmlComment = '!' !== $this->line->getChar(1); |
|
| 26 | + $this->htmlComment='!'!==$this->line->getChar(1); |
|
| 27 | 27 | |
| 28 | 28 | return $this; |
| 29 | 29 | } |
@@ -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 | /** |
@@ -47,8 +46,8 @@ discard block |
||
| 47 | 46 | * |
| 48 | 47 | * @return string |
| 49 | 48 | */ |
| 50 | - public function close(Line $closerLine):string |
|
| 49 | + public function close( Line $closerLine ):string |
|
| 51 | 50 | { |
| 52 | - return $this->htmlComment ? '-->' : ' */ ?>'; |
|
| 51 | + return $this->htmlComment? '-->' : ' */ ?>'; |
|
| 53 | 52 | } |
| 54 | 53 | } |
@@ -10,48 +10,48 @@ |
||
| 10 | 10 | |
| 11 | 11 | class SectionNode extends ANode |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The name of the section. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - private $name; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Real constructor. |
|
| 22 | - * |
|
| 23 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 24 | - */ |
|
| 25 | - protected function construct():parent |
|
| 26 | - { |
|
| 27 | - $this->name = $this->line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 28 | - |
|
| 29 | - return $this; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Opening this node, and returning node opener. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function open():string |
|
| 38 | - { |
|
| 39 | - $this->document->setSection(new Section($this->name)); |
|
| 40 | - |
|
| 41 | - return ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Close this node, and returning node closer. |
|
| 46 | - * |
|
| 47 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function close(Line $closerLine):string |
|
| 52 | - { |
|
| 53 | - $this->document->setSection(null); |
|
| 54 | - |
|
| 55 | - return ''; |
|
| 56 | - } |
|
| 13 | + /** |
|
| 14 | + * The name of the section. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + private $name; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Real constructor. |
|
| 22 | + * |
|
| 23 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 24 | + */ |
|
| 25 | + protected function construct():parent |
|
| 26 | + { |
|
| 27 | + $this->name = $this->line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 28 | + |
|
| 29 | + return $this; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Opening this node, and returning node opener. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function open():string |
|
| 38 | + { |
|
| 39 | + $this->document->setSection(new Section($this->name)); |
|
| 40 | + |
|
| 41 | + return ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Close this node, and returning node closer. |
|
| 46 | + * |
|
| 47 | + * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function close(Line $closerLine):string |
|
| 52 | + { |
|
| 53 | + $this->document->setSection(null); |
|
| 54 | + |
|
| 55 | + return ''; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | protected function construct():parent |
| 26 | 26 | { |
| 27 | - $this->name = $this->line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 27 | + $this->name=$this->line->pregGet('/(?<=\( ).*(?= \))/'); |
|
| 28 | 28 | |
| 29 | 29 | return $this; |
| 30 | 30 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | - public function close(Line $closerLine):string |
|
| 51 | + public function close( Line $closerLine ):string |
|
| 52 | 52 | { |
| 53 | 53 | $this->document->setSection(null); |
| 54 | 54 | |
@@ -9,35 +9,35 @@ |
||
| 9 | 9 | |
| 10 | 10 | class StringNode extends ANode |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Real constructor. |
|
| 14 | - * |
|
| 15 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 16 | - */ |
|
| 17 | - protected function construct():parent |
|
| 18 | - { |
|
| 19 | - return $this; |
|
| 20 | - } |
|
| 12 | + /** |
|
| 13 | + * Real constructor. |
|
| 14 | + * |
|
| 15 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 16 | + */ |
|
| 17 | + protected function construct():parent |
|
| 18 | + { |
|
| 19 | + return $this; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Opening this node, and returning node opener. |
|
| 24 | - * |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function open():string |
|
| 28 | - { |
|
| 29 | - return ''; |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * Opening this node, and returning node opener. |
|
| 24 | + * |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function open():string |
|
| 28 | + { |
|
| 29 | + return ''; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Close this node, and returning node closer. |
|
| 34 | - * |
|
| 35 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function close(Line $closerLine):string |
|
| 40 | - { |
|
| 41 | - return ''; |
|
| 42 | - } |
|
| 32 | + /** |
|
| 33 | + * Close this node, and returning node closer. |
|
| 34 | + * |
|
| 35 | + * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function close(Line $closerLine):string |
|
| 40 | + { |
|
| 41 | + return ''; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * |
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | - public function close(Line $closerLine):string |
|
| 39 | + public function close( Line $closerLine ):string |
|
| 40 | 40 | { |
| 41 | 41 | return ''; |
| 42 | 42 | } |
@@ -10,122 +10,122 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ControlNode extends ANode |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The name of the Htsl.php control structure. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - private $name; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The name of the complied(PHP) control structure. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - private $structureName; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Parameters. |
|
| 29 | - * |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - private $param; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Real constructor. |
|
| 36 | - * |
|
| 37 | - * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 38 | - */ |
|
| 39 | - protected function construct():parent |
|
| 40 | - { |
|
| 41 | - $name = $this->line->pregGet('/(?<=^~)[\w-]*/'); |
|
| 42 | - $this->name = $name; |
|
| 43 | - |
|
| 44 | - $this->loadConfig($name, $this->htsl); |
|
| 45 | - |
|
| 46 | - $this->param = $this->line->pregGet('/^~[\w-]*\( (.*) \)/', 1); |
|
| 47 | - |
|
| 48 | - $this->structureName = $this->config['name'] ?? $name; |
|
| 49 | - |
|
| 50 | - $this->id = strtoupper(uniqid()); |
|
| 51 | - |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Opening this control node, and returning node opener. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function open():string |
|
| 61 | - { |
|
| 62 | - return $this->withParam($this->config['opener']); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Getting whether this node contains a scope and scope name. |
|
| 67 | - * |
|
| 68 | - * @return string | null |
|
| 69 | - */ |
|
| 70 | - public function getScope() |
|
| 71 | - { |
|
| 72 | - return $this->config['scope'] ?? null; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Close this control node, and returning node closer. |
|
| 77 | - * |
|
| 78 | - * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function close(Line $closerLine):string |
|
| 83 | - { |
|
| 84 | - if (isset($this->config['close_by']) && $closerLine->indentLevel == $this->line->indentLevel) { |
|
| 85 | - foreach ($this->config['close_by'] as $key => $value) { |
|
| 86 | - if ($closerLine->pregMatch($key)) { |
|
| 87 | - return $this->withParam($value); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if (isset($this->config['closer'])) { |
|
| 93 | - return $this->withParam($this->config['closer']); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return ''; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Parse opener or closer with parameters. |
|
| 101 | - * |
|
| 102 | - * @param string $input Opener or Closer |
|
| 103 | - * |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - private function withParam(string $input) |
|
| 107 | - { |
|
| 108 | - return str_replace('$_FLAG_$', "__HTSL_CTRL_FLAG_{$this->id}__", preg_replace_callback('/(?<!%)%s((?:\\/.+?(?<!\\\\)\\/.+?(?<!\\\\)\\/)+)?/', function (array $matches) { |
|
| 109 | - $param = $this->param; |
|
| 110 | - |
|
| 111 | - if (isset($matches[1])) { |
|
| 112 | - array_map(...[ |
|
| 113 | - function ($replacer) use (&$param) { |
|
| 114 | - list($pattern, $replacement) = preg_split('/(?<!\\\\)\\//', $replacer); |
|
| 115 | - $param = preg_replace(...[ |
|
| 116 | - "/$pattern/", |
|
| 117 | - preg_replace('/^\\\\_$/', '', $replacement), |
|
| 118 | - $param, |
|
| 119 | - ]); |
|
| 120 | - }, |
|
| 121 | - preg_split( |
|
| 122 | - '/(?<!\\\\)\\/\\//', |
|
| 123 | - trim($matches[1], '/') |
|
| 124 | - ), |
|
| 125 | - ]); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return $param; |
|
| 129 | - }, $input)); |
|
| 130 | - } |
|
| 13 | + /** |
|
| 14 | + * The name of the Htsl.php control structure. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + private $name; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The name of the complied(PHP) control structure. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + private $structureName; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Parameters. |
|
| 29 | + * |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + private $param; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Real constructor. |
|
| 36 | + * |
|
| 37 | + * @return \Htsl\Parser\Node\Contracts\ANode |
|
| 38 | + */ |
|
| 39 | + protected function construct():parent |
|
| 40 | + { |
|
| 41 | + $name = $this->line->pregGet('/(?<=^~)[\w-]*/'); |
|
| 42 | + $this->name = $name; |
|
| 43 | + |
|
| 44 | + $this->loadConfig($name, $this->htsl); |
|
| 45 | + |
|
| 46 | + $this->param = $this->line->pregGet('/^~[\w-]*\( (.*) \)/', 1); |
|
| 47 | + |
|
| 48 | + $this->structureName = $this->config['name'] ?? $name; |
|
| 49 | + |
|
| 50 | + $this->id = strtoupper(uniqid()); |
|
| 51 | + |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Opening this control node, and returning node opener. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function open():string |
|
| 61 | + { |
|
| 62 | + return $this->withParam($this->config['opener']); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Getting whether this node contains a scope and scope name. |
|
| 67 | + * |
|
| 68 | + * @return string | null |
|
| 69 | + */ |
|
| 70 | + public function getScope() |
|
| 71 | + { |
|
| 72 | + return $this->config['scope'] ?? null; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Close this control node, and returning node closer. |
|
| 77 | + * |
|
| 78 | + * @param \Htsl\ReadingBuffer\Line $closerLine The line when node closed. |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function close(Line $closerLine):string |
|
| 83 | + { |
|
| 84 | + if (isset($this->config['close_by']) && $closerLine->indentLevel == $this->line->indentLevel) { |
|
| 85 | + foreach ($this->config['close_by'] as $key => $value) { |
|
| 86 | + if ($closerLine->pregMatch($key)) { |
|
| 87 | + return $this->withParam($value); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if (isset($this->config['closer'])) { |
|
| 93 | + return $this->withParam($this->config['closer']); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return ''; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Parse opener or closer with parameters. |
|
| 101 | + * |
|
| 102 | + * @param string $input Opener or Closer |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + private function withParam(string $input) |
|
| 107 | + { |
|
| 108 | + return str_replace('$_FLAG_$', "__HTSL_CTRL_FLAG_{$this->id}__", preg_replace_callback('/(?<!%)%s((?:\\/.+?(?<!\\\\)\\/.+?(?<!\\\\)\\/)+)?/', function (array $matches) { |
|
| 109 | + $param = $this->param; |
|
| 110 | + |
|
| 111 | + if (isset($matches[1])) { |
|
| 112 | + array_map(...[ |
|
| 113 | + function ($replacer) use (&$param) { |
|
| 114 | + list($pattern, $replacement) = preg_split('/(?<!\\\\)\\//', $replacer); |
|
| 115 | + $param = preg_replace(...[ |
|
| 116 | + "/$pattern/", |
|
| 117 | + preg_replace('/^\\\\_$/', '', $replacement), |
|
| 118 | + $param, |
|
| 119 | + ]); |
|
| 120 | + }, |
|
| 121 | + preg_split( |
|
| 122 | + '/(?<!\\\\)\\/\\//', |
|
| 123 | + trim($matches[1], '/') |
|
| 124 | + ), |
|
| 125 | + ]); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return $param; |
|
| 129 | + }, $input)); |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function construct():parent |
| 40 | 40 | { |
| 41 | - $name = $this->line->pregGet('/(?<=^~)[\w-]*/'); |
|
| 42 | - $this->name = $name; |
|
| 41 | + $name=$this->line->pregGet('/(?<=^~)[\w-]*/'); |
|
| 42 | + $this->name=$name; |
|
| 43 | 43 | |
| 44 | 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 | - $this->id = strtoupper(uniqid()); |
|
| 50 | + $this->id=strtoupper(uniqid()); |
|
| 51 | 51 | |
| 52 | 52 | return $this; |
| 53 | 53 | } |
@@ -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 | /** |
@@ -79,18 +79,18 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | - public function close(Line $closerLine):string |
|
| 82 | + public function close( Line $closerLine ):string |
|
| 83 | 83 | { |
| 84 | - if (isset($this->config['close_by']) && $closerLine->indentLevel == $this->line->indentLevel) { |
|
| 85 | - foreach ($this->config['close_by'] as $key => $value) { |
|
| 86 | - if ($closerLine->pregMatch($key)) { |
|
| 84 | + if( isset($this->config[ 'close_by' ]) && $closerLine->indentLevel==$this->line->indentLevel ){ |
|
| 85 | + foreach( $this->config[ 'close_by' ] as $key => $value ){ |
|
| 86 | + if( $closerLine->pregMatch($key) ){ |
|
| 87 | 87 | return $this->withParam($value); |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (isset($this->config['closer'])) { |
|
| 93 | - return $this->withParam($this->config['closer']); |
|
| 92 | + if( isset($this->config[ 'closer' ]) ){ |
|
| 93 | + return $this->withParam($this->config[ 'closer' ]); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | return ''; |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | - private function withParam(string $input) |
|
| 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 | 117 | preg_replace('/^\\\\_$/', '', $replacement), |
| 118 | 118 | $param, |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | }, |
| 121 | 121 | preg_split( |
| 122 | 122 | '/(?<!\\\\)\\/\\//', |
| 123 | - trim($matches[1], '/') |
|
| 123 | + trim($matches[ 1 ], '/') |
|
| 124 | 124 | ), |
| 125 | 125 | ]); |
| 126 | 126 | } |
@@ -81,15 +81,15 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function close(Line $closerLine):string |
| 83 | 83 | { |
| 84 | - if (isset($this->config['close_by']) && $closerLine->indentLevel == $this->line->indentLevel) { |
|
| 85 | - foreach ($this->config['close_by'] as $key => $value) { |
|
| 86 | - if ($closerLine->pregMatch($key)) { |
|
| 84 | + if (isset($this->config['close_by']) && $closerLine->indentLevel == $this->line->indentLevel){ |
|
| 85 | + foreach ($this->config['close_by'] as $key => $value){ |
|
| 86 | + if ($closerLine->pregMatch($key)){ |
|
| 87 | 87 | return $this->withParam($value); |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if (isset($this->config['closer'])) { |
|
| 92 | + if (isset($this->config['closer'])){ |
|
| 93 | 93 | return $this->withParam($this->config['closer']); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -105,12 +105,12 @@ 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) { |
|
| 108 | + return str_replace('$_FLAG_$', "__HTSL_CTRL_FLAG_{$this->id}__", preg_replace_callback('/(?<!%)%s((?:\\/.+?(?<!\\\\)\\/.+?(?<!\\\\)\\/)+)?/', function (array $matches){ |
|
| 109 | 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) { |
|
| 113 | + function ($replacer) use (&$param){ |
|
| 114 | 114 | list($pattern, $replacement) = preg_split('/(?<!\\\\)\\//', $replacer); |
| 115 | 115 | $param = preg_replace(...[ |
| 116 | 116 | "/$pattern/", |
@@ -8,63 +8,63 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Section |
| 10 | 10 | { |
| 11 | - use TGetter; |
|
| 11 | + use TGetter; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Section name. |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - private $name; |
|
| 13 | + /** |
|
| 14 | + * Section name. |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + private $name; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Content. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - private $content = ''; |
|
| 20 | + /** |
|
| 21 | + * Content. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + private $content = ''; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Setting name and constructing instance of Section. |
|
| 29 | - * |
|
| 30 | - * @param string | null $name |
|
| 31 | - */ |
|
| 32 | - public function __construct(string $name = null) |
|
| 33 | - { |
|
| 34 | - $this->name = $name; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Setting name and constructing instance of Section. |
|
| 29 | + * |
|
| 30 | + * @param string | null $name |
|
| 31 | + */ |
|
| 32 | + public function __construct(string $name = null) |
|
| 33 | + { |
|
| 34 | + $this->name = $name; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Appending content to this section. |
|
| 39 | - * |
|
| 40 | - * @param string $content |
|
| 41 | - * |
|
| 42 | - * @return self |
|
| 43 | - */ |
|
| 44 | - public function append(string $content):self |
|
| 45 | - { |
|
| 46 | - $this->content .= $content; |
|
| 37 | + /** |
|
| 38 | + * Appending content to this section. |
|
| 39 | + * |
|
| 40 | + * @param string $content |
|
| 41 | + * |
|
| 42 | + * @return self |
|
| 43 | + */ |
|
| 44 | + public function append(string $content):self |
|
| 45 | + { |
|
| 46 | + $this->content .= $content; |
|
| 47 | 47 | |
| 48 | - return $this; |
|
| 49 | - } |
|
| 48 | + return $this; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Getting content of this section. |
|
| 53 | - * |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function getContent():string |
|
| 57 | - { |
|
| 58 | - return $this->content; |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * Getting content of this section. |
|
| 53 | + * |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function getContent():string |
|
| 57 | + { |
|
| 58 | + return $this->content; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Getting name of this section. |
|
| 63 | - * |
|
| 64 | - * @return string | null |
|
| 65 | - */ |
|
| 66 | - public function getName()//:string|null |
|
| 67 | - { |
|
| 68 | - return $this->name; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Getting name of this section. |
|
| 63 | + * |
|
| 64 | + * @return string | null |
|
| 65 | + */ |
|
| 66 | + public function getName()//:string|null |
|
| 67 | + { |
|
| 68 | + return $this->name; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -22,16 +22,16 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @var string |
| 24 | 24 | */ |
| 25 | - private $content = ''; |
|
| 25 | + private $content=''; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Setting name and constructing instance of Section. |
| 29 | 29 | * |
| 30 | 30 | * @param string | null $name |
| 31 | 31 | */ |
| 32 | - public function __construct(string $name = null) |
|
| 32 | + public function __construct( string $name=null ) |
|
| 33 | 33 | { |
| 34 | - $this->name = $name; |
|
| 34 | + $this->name=$name; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return self |
| 43 | 43 | */ |
| 44 | - public function append(string $content):self |
|
| 44 | + public function append( string $content ):self |
|
| 45 | 45 | { |
| 46 | - $this->content .= $content; |
|
| 46 | + $this->content.=$content; |
|
| 47 | 47 | |
| 48 | 48 | return $this; |
| 49 | 49 | } |
@@ -8,65 +8,65 @@ |
||
| 8 | 8 | |
| 9 | 9 | class FileBuffer extends Contracts\ABuffer |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * File handle. |
|
| 13 | - * |
|
| 14 | - * @var resource |
|
| 15 | - */ |
|
| 16 | - private $handle; |
|
| 11 | + /** |
|
| 12 | + * File handle. |
|
| 13 | + * |
|
| 14 | + * @var resource |
|
| 15 | + */ |
|
| 16 | + private $handle; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructing a file buffer reading HTSL content from file system. |
|
| 20 | - * |
|
| 21 | - * @param Htsl $htsl Main Htsl object |
|
| 22 | - * @param string $filePath |
|
| 23 | - */ |
|
| 24 | - public function __construct(Htsl $htsl, string $filePath) |
|
| 25 | - { |
|
| 26 | - substr($filePath, -5) === '.htsl' or $filePath .= '.htsl'; |
|
| 18 | + /** |
|
| 19 | + * Constructing a file buffer reading HTSL content from file system. |
|
| 20 | + * |
|
| 21 | + * @param Htsl $htsl Main Htsl object |
|
| 22 | + * @param string $filePath |
|
| 23 | + */ |
|
| 24 | + public function __construct(Htsl $htsl, string $filePath) |
|
| 25 | + { |
|
| 26 | + substr($filePath, -5) === '.htsl' or $filePath .= '.htsl'; |
|
| 27 | 27 | |
| 28 | - if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 29 | - throw new \Exception("File $filePath not exists.", 1); |
|
| 30 | - } |
|
| 28 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 29 | + throw new \Exception("File $filePath not exists.", 1); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $this->filePath = $filePath; |
|
| 32 | + $this->filePath = $filePath; |
|
| 33 | 33 | |
| 34 | - $this->handle = fopen($filePath, 'r'); |
|
| 34 | + $this->handle = fopen($filePath, 'r'); |
|
| 35 | 35 | |
| 36 | - parent::__construct($htsl); |
|
| 37 | - } |
|
| 36 | + parent::__construct($htsl); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Destructor. |
|
| 41 | - */ |
|
| 42 | - public function __destruct() |
|
| 43 | - { |
|
| 44 | - fclose($this->handle); |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * Destructor. |
|
| 41 | + */ |
|
| 42 | + public function __destruct() |
|
| 43 | + { |
|
| 44 | + fclose($this->handle); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Getting first line or next line. |
|
| 49 | - * |
|
| 50 | - * @return \Htsl\ReadingBuffer\Line |
|
| 51 | - */ |
|
| 52 | - public function getLine():Line |
|
| 53 | - { |
|
| 54 | - while ("\n" === $content = fgets($this->handle)); |
|
| 47 | + /** |
|
| 48 | + * Getting first line or next line. |
|
| 49 | + * |
|
| 50 | + * @return \Htsl\ReadingBuffer\Line |
|
| 51 | + */ |
|
| 52 | + public function getLine():Line |
|
| 53 | + { |
|
| 54 | + while ("\n" === $content = fgets($this->handle)); |
|
| 55 | 55 | |
| 56 | - return new Line($content); |
|
| 57 | - } |
|
| 56 | + return new Line($content); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Getting another file reference file of this buffer. |
|
| 61 | - * |
|
| 62 | - * @param string $filePath |
|
| 63 | - * |
|
| 64 | - * @return \Htsl\ReadingBuffer\Contracts\ABuffer |
|
| 65 | - */ |
|
| 66 | - public function goSide($filePath):parent |
|
| 67 | - { |
|
| 68 | - $filePath = $this->htsl->getFilePath($filePath, dirname($this->filePath)); |
|
| 59 | + /** |
|
| 60 | + * Getting another file reference file of this buffer. |
|
| 61 | + * |
|
| 62 | + * @param string $filePath |
|
| 63 | + * |
|
| 64 | + * @return \Htsl\ReadingBuffer\Contracts\ABuffer |
|
| 65 | + */ |
|
| 66 | + public function goSide($filePath):parent |
|
| 67 | + { |
|
| 68 | + $filePath = $this->htsl->getFilePath($filePath, dirname($this->filePath)); |
|
| 69 | 69 | |
| 70 | - return new static($this->htsl, $filePath); |
|
| 71 | - } |
|
| 70 | + return new static($this->htsl, $filePath); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -21,17 +21,17 @@ discard block |
||
| 21 | 21 | * @param Htsl $htsl Main Htsl object |
| 22 | 22 | * @param string $filePath |
| 23 | 23 | */ |
| 24 | - public function __construct(Htsl $htsl, string $filePath) |
|
| 24 | + public function __construct( Htsl $htsl, string $filePath ) |
|
| 25 | 25 | { |
| 26 | - substr($filePath, -5) === '.htsl' or $filePath .= '.htsl'; |
|
| 26 | + substr($filePath, -5)==='.htsl' or $filePath.='.htsl'; |
|
| 27 | 27 | |
| 28 | - if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 28 | + if( !file_exists($filePath) || !is_file($filePath) ){ |
|
| 29 | 29 | throw new \Exception("File $filePath not exists.", 1); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $this->filePath = $filePath; |
|
| 32 | + $this->filePath=$filePath; |
|
| 33 | 33 | |
| 34 | - $this->handle = fopen($filePath, 'r'); |
|
| 34 | + $this->handle=fopen($filePath, 'r'); |
|
| 35 | 35 | |
| 36 | 36 | parent::__construct($htsl); |
| 37 | 37 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function getLine():Line |
| 53 | 53 | { |
| 54 | - while ("\n" === $content = fgets($this->handle)); |
|
| 54 | + while( "\n"===$content=fgets($this->handle) ); |
|
| 55 | 55 | |
| 56 | 56 | return new Line($content); |
| 57 | 57 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return \Htsl\ReadingBuffer\Contracts\ABuffer |
| 65 | 65 | */ |
| 66 | - public function goSide($filePath):parent |
|
| 66 | + public function goSide( $filePath ):parent |
|
| 67 | 67 | { |
| 68 | - $filePath = $this->htsl->getFilePath($filePath, dirname($this->filePath)); |
|
| 68 | + $filePath=$this->htsl->getFilePath($filePath, dirname($this->filePath)); |
|
| 69 | 69 | |
| 70 | 70 | return new static($this->htsl, $filePath); |
| 71 | 71 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | { |
| 26 | 26 | substr($filePath, -5) === '.htsl' or $filePath .= '.htsl'; |
| 27 | 27 | |
| 28 | - if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 28 | + if (!file_exists($filePath) || !is_file($filePath)){ |
|
| 29 | 29 | throw new \Exception("File $filePath not exists.", 1); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | substr($filePath, -5) === '.htsl' or $filePath .= '.htsl'; |
| 27 | 27 | |
| 28 | 28 | if (!file_exists($filePath) || !is_file($filePath)) { |
| 29 | - throw new \Exception("File $filePath not exists.", 1); |
|
| 29 | + throw new \Exception("file $filePath not exists.", 1); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $this->filePath = $filePath; |