diff --git a/src/Common/UiElement.php b/src/Common/UiElement.php index b3f3aff..c271ca3 100644 --- a/src/Common/UiElement.php +++ b/src/Common/UiElement.php @@ -26,9 +26,9 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable { * tag-type single Only render a single tag. Cannot contains any childrens * force-tag-open tag Control the way the opening tag is rendered * force-tag-close tag-close " " " " closing " " " - * no-attr Attributes will not be rendered - * no-id ID is not automatically given (* may be removed *) - * escape-tag-end If you need to echo the Node inside another string, it may be useful to escape the "/" char using "\/" + * no-attr true Attributes will not be rendered + * no-id true ID is not automatically given (* may be removed *) + * escape-tag-end true If you need to echo the Node inside another string, it may be useful to escape the "/" char using "\/" */ public array $options = []; @@ -148,7 +148,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable { return $this; } - public function option(string $var, $value = 1) : self + public function option(string $var, mixed $value = true) : self { $this->options[$var] = $value; @@ -200,14 +200,14 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable { } } - if ( in_array('no-tag', $this->options, true) ) { + if ( $this->options['no-tag'] ?? false ) { return $this->content . $content; } else { - $compiledAttributes = (count($attributesList) && ! in_array('no-attr', $this->options, true) ? " " . implode(" ", $attributesList) : ""); + $compiledAttributes = $this->options['no-attr'] ?? false ? "" : " " . implode(" ", $attributesList); # Force the node to contain a certain opening tag (php is a good example) - if ( in_array('force-tag-open', $this->options, true) ) { + if ( $this->options['force-tag-open'] ?? false ) { $opentag = $this->options['force-tag-open'] . $compiledAttributes; } else { @@ -219,11 +219,11 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable { $closetag = ""; } } - elseif ( in_array('force-tag-close', $this->options, true) ) { + elseif ( $this->options['force-tag-close'] ?? false ) { $closetag = $this->options['force-tag-close']; } else { - $closetag = $this->tag ? "<" . (in_array('escape-tag-end', $this->options) ? "\/" : "/" ) . "{$this->tag}>" : ""; + $closetag = $this->tag ? "<" . ( $this->options['escape-tag-end'] ?? false ? "\/" : "/" ) . "{$this->tag}>" : ""; } return $opentag . $this->content . $content . $closetag; @@ -259,7 +259,6 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable { { return $this->insert( static::INSERT_MODE_PREPEND, ...( is_array($arguments) ? array_reverse($arguments) : $arguments) ); } - protected function insert(int $mode, ...$elements) : self {