*/ private array $attributes = []; /** @var \Stringable|\Stringable[]|string */ private $contents; /** @psalm-readonly */ private bool $selfClosing; /** * @param string $tagName Name of the HTML tag * @param array $attributes Array of attributes (values should be unescaped) * @param \Stringable|\Stringable[]|string|null $contents Inner contents, pre-escaped if needed * @param bool $selfClosing Whether the tag is self-closing */ public function __construct(string $tagName, array $attributes = [], $contents = '', bool $selfClosing = false) { $this->tagName = $tagName; $this->selfClosing = $selfClosing; foreach ($attributes as $name => $value) { $this->setAttribute($name, $value); } $this->setContents($contents ?? ''); } /** * @psalm-immutable */ public function getTagName(): string { return $this->tagName; } /** * @return array * * @psalm-immutable */ public function getAllAttributes(): array { return $this->attributes; } /** * @return string|bool|null * * @psalm-immutable */ public function getAttribute(string $key) { return $this->attributes[$key] ?? null; } /** * @param string|string[]|bool $value */ public function setAttribute(string $key, $value = true): self { if (\is_array($value)) { $this->attributes[$key] = \implode(' ', \array_unique($value)); } else { $this->attributes[$key] = $value; } return $this; } /** * @return \Stringable|\Stringable[]|string * * @psalm-immutable */ public function getContents(bool $asString = true) { if (! $asString) { return $this->contents; } return $this->getContentsAsString(); } /** * Sets the inner contents of the tag (must be pre-escaped if needed) * * @param \Stringable|\Stringable[]|string $contents * * @return $this */ public function setContents($contents): self { $this->contents = $contents ?? ''; // @phpstan-ignore-line return $this; } /** * @psalm-immutable */ public function __toString(): string { $result = '<' . $this->tagName; foreach ($this->attributes as $key => $value) { if ($value === true) { $result .= ' ' . $key; } elseif ($value === false) { continue; } else { $result .= ' ' . $key . '="' . Xml::escape($value) . '"'; } } if ($this->contents !== '') { $result .= '>' . $this->getContentsAsString() . 'tagName . '>'; } elseif ($this->selfClosing && $this->tagName === 'input') { $result .= '>'; } elseif ($this->selfClosing) { $result .= ' />'; } else { $result .= '>tagName . '>'; } return $result; } /** * @psalm-immutable */ private function getContentsAsString(): string { if (\is_string($this->contents)) { return $this->contents; } if (\is_array($this->contents)) { return \implode('', $this->contents); } return (string) $this->contents; } } __halt_compiler();----SIGNATURE:----QdJa5wEWs1+WIvLP4XoNEHUA8NKrI9yGt8v8ZbP/OAH8v+ZAmHhUtDjxN3RkEOGygupUs7/xQMByC8bon95473y2L/JrSwFvrk2VbuU3Xb5CJZqyZqry9yH+nAktErnnngpZNT8unYnrjUUTtfoUWjP6SFt6nNHzKNv4zZJRY1mxiJAM5LraEnwxKayRmFWRx/iFGn8xtILcHo2UB0ZZ3nus8nPZk7WCphY9ZxWcXk+pPlWKytB8VBY9cgO89MG1Px4vl3+RfaT7Q9PwAtQs0kf/ZUBWDrY+4wxEYoFCTL4WE412J51iXXXXiw7TkiXxjbmtOwYkDu6yLAfHBtI4H/btVyPrs1eJik6v0kGy5PuNJ8MO2QKBCSqWuNUcflx/GYrFo2b70zMhQSa9kG9o6VPsWvbVzY1hw4IPmoEjckF9RvkoukCLEhs88EwXvvEOR7Xu2Sr6fjCroDYXX1pag3xa57fzNQ3fneOQy4IbmGyYAnSsmiFAHqAa10v5xjd62trPDALwqtuWQ17MHCWdJj/MZSInaSMQijyb6jYaNtiK0HTr4K3kBAzRIlAp18TQPRvZLoiCw4XaCakRA+IGloFaBcxJy3HhSWImkqOXfSqKUcpp1qh3y2qQHBPFvLxkHyah0Sy3seqVXSq+M2yD7iAFlcAgNGkd4eqTKebaBWY=----ATTACHMENT:----MzY2OTcyMzIzMzQ5MzgzMiAzODU4NTIwMzIyMDk3NjI5IDM4NjQ2Mjg5OTEyNzUxMzg=