diff --git a/src/AbstractParser.php b/src/AbstractParser.php index 3c37b9a..34b73a7 100644 --- a/src/AbstractParser.php +++ b/src/AbstractParser.php @@ -5,7 +5,7 @@ namespace ByJoby\HTML; use ByJoby\HTML\Containers\Fragment; use ByJoby\HTML\Containers\FragmentInterface; use ByJoby\HTML\Containers\HtmlDocumentInterface; -use ByJoby\HTML\Html5\Enums\BooleanAttribute; +use ByJoby\HTML\Helpers\BooleanAttribute; use ByJoby\HTML\Nodes\CData; use ByJoby\HTML\Nodes\CDataInterface; use ByJoby\HTML\Nodes\Comment; diff --git a/src/ContainerInterface.php b/src/ContainerInterface.php index fc75c5e..85fc705 100644 --- a/src/ContainerInterface.php +++ b/src/ContainerInterface.php @@ -17,21 +17,21 @@ interface ContainerInterface extends Stringable NodeInterface|Stringable|string $child, bool $prepend = false, bool $skip_sanitize = false - ): static; + ): self; public function removeChild( NodeInterface|Stringable|string $child - ): static; + ): self; public function addChildBefore( NodeInterface|Stringable|string $new_child, NodeInterface|Stringable|string $before_child, bool $skip_sanitize = false - ): static; + ): self; public function addChildAfter( NodeInterface|Stringable|string $new_child, NodeInterface|Stringable|string $after_child, bool $skip_sanitize = false - ): static; + ): self; } diff --git a/src/Helpers/Attributes.php b/src/Helpers/Attributes.php index 79963e8..1445f7c 100644 --- a/src/Helpers/Attributes.php +++ b/src/Helpers/Attributes.php @@ -5,7 +5,7 @@ namespace ByJoby\HTML\Helpers; use ArrayAccess; use ArrayIterator; use BackedEnum; -use ByJoby\HTML\Html5\Enums\BooleanAttribute; +use ByJoby\HTML\Helpers\BooleanAttribute; use Exception; use IteratorAggregate; use Stringable; @@ -81,7 +81,7 @@ class Attributes implements IteratorAggregate, ArrayAccess * @param string $separator * @return static */ - public function setEnumArray(string $offset, null|BackedEnum|array $value, string $enum_class, string $separator): static + public function setEnumArray(string $offset, null|BackedEnum|array $value, string $enum_class, string $separator): self { if (is_null($value)) { $value = []; diff --git a/src/Html5/Enums/BooleanAttribute.php b/src/Helpers/BooleanAttribute.php similarity index 92% rename from src/Html5/Enums/BooleanAttribute.php rename to src/Helpers/BooleanAttribute.php index f1f206c..3815377 100644 --- a/src/Html5/Enums/BooleanAttribute.php +++ b/src/Helpers/BooleanAttribute.php @@ -1,6 +1,6 @@ classes; } - public function add(string|Stringable $class, bool $no_exception = false): static + public function add(string|Stringable $class, bool $no_exception = false): self { try { $class = static::sanitizeClassName($class, true); @@ -77,7 +77,7 @@ class Classes implements Countable return $this; } - public function remove(string|Stringable $class): static + public function remove(string|Stringable $class): self { $class = static::sanitizeClassName($class); $this->classes = array_values(array_filter( diff --git a/src/Html5/DocumentTags/TitleTag.php b/src/Html5/DocumentTags/TitleTag.php index 8bbe385..0b7424d 100644 --- a/src/Html5/DocumentTags/TitleTag.php +++ b/src/Html5/DocumentTags/TitleTag.php @@ -20,7 +20,7 @@ class TitleTag extends AbstractContentTag implements TitleTagInterface protected $content = 'Untitled'; protected $inline = true; - public function setContent(string|Stringable $content): static + public function setContent(string|Stringable $content): self { parent::setContent(trim(strip_tags($content))); return $this; diff --git a/src/Html5/Enums/Type_list.php b/src/Html5/Enums/ListTypeValue.php similarity index 85% rename from src/Html5/Enums/Type_list.php rename to src/Html5/Enums/ListTypeValue.php index b2dbbbe..1f7f731 100644 --- a/src/Html5/Enums/Type_list.php +++ b/src/Html5/Enums/ListTypeValue.php @@ -2,7 +2,7 @@ namespace ByJoby\HTML\Html5\Enums; -enum Type_list: string { +enum ListTypeValue: string { case letterLower = 'a'; case letterUpper = 'A'; case romanLower = 'i'; diff --git a/src/Html5/Enums/Spellcheck.php b/src/Html5/Enums/SpellcheckValue.php similarity index 76% rename from src/Html5/Enums/Spellcheck.php rename to src/Html5/Enums/SpellcheckValue.php index 28c5ede..16896f9 100644 --- a/src/Html5/Enums/Spellcheck.php +++ b/src/Html5/Enums/SpellcheckValue.php @@ -2,7 +2,7 @@ namespace ByJoby\HTML\Html5\Enums; -enum Spellcheck: string +enum SpellcheckValue: string { case true = "true"; case false = "false"; diff --git a/src/Html5/Enums/Translate.php b/src/Html5/Enums/TranslateValue.php similarity index 94% rename from src/Html5/Enums/Translate.php rename to src/Html5/Enums/TranslateValue.php index 3e26b87..10443de 100644 --- a/src/Html5/Enums/Translate.php +++ b/src/Html5/Enums/TranslateValue.php @@ -11,7 +11,7 @@ namespace ByJoby\HTML\Html5\Enums; * Description by Mozilla Contributors licensed under CC-BY-SA 2.5 * https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/translate */ -enum Translate: string +enum TranslateValue: string { case true = "yes"; case false = "no"; diff --git a/src/Html5/Html5Parser.php b/src/Html5/Html5Parser.php index ade235c..c2732fc 100644 --- a/src/Html5/Html5Parser.php +++ b/src/Html5/Html5Parser.php @@ -12,11 +12,12 @@ class Html5Parser extends AbstractParser { /** @var array */ protected $tag_namespaces = [ - '\\ByJoby\\HTML\\Html5\\Tags\\', - '\\ByJoby\\HTML\\Html5\\InlineTextSemantics\\', - '\\ByJoby\\HTML\\Html5\\TextContentTags\\', '\\ByJoby\\HTML\\Html5\\ContentSectioningTags\\', '\\ByJoby\\HTML\\Html5\\DocumentTags\\', + '\\ByJoby\\HTML\\Html5\\InlineTextSemantics\\', + '\\ByJoby\\HTML\\Html5\\Multimedia\\', + '\\ByJoby\\HTML\\Html5\\Tags\\', + '\\ByJoby\\HTML\\Html5\\TextContentTags\\', ]; /** @var class-string */ diff --git a/src/Html5/InlineTextSemantics/ATag.php b/src/Html5/InlineTextSemantics/ATag.php index 1784825..1b604f7 100644 --- a/src/Html5/InlineTextSemantics/ATag.php +++ b/src/Html5/InlineTextSemantics/ATag.php @@ -2,10 +2,11 @@ namespace ByJoby\HTML\Html5\InlineTextSemantics; -use ByJoby\HTML\Html5\Enums\BooleanAttribute; +use ByJoby\HTML\Helpers\BooleanAttribute; use ByJoby\HTML\Html5\Enums\BrowsingContext; -use ByJoby\HTML\Html5\Enums\ReferrerPolicy_a; -use ByJoby\HTML\Html5\Enums\Rel_a; +use ByJoby\HTML\Html5\InlineTextSemantics\ATag\ReferrerPolicyValue; +use ByJoby\HTML\Html5\InlineTextSemantics\ATag\RelValue; +use ByJoby\HTML\Html5\Traits\HyperlinkTrait; use ByJoby\HTML\Tags\AbstractContainerTag; use Stringable; @@ -19,308 +20,6 @@ use Stringable; */ class ATag extends AbstractContainerTag { + use HyperlinkTrait; const TAG = 'a'; - - /** - * Causes the browser to treat the linked URL as a download. Can be used - * with or without a filename value. - * - * @return null|string|Stringable|BooleanAttribute::true - */ - public function download(): null|string|Stringable|BooleanAttribute - { - if ($this->attributes()['download'] === BooleanAttribute::true) return BooleanAttribute::true; - else return $this->attributes()->asString('download'); - } - - /** - * Causes the browser to treat the linked URL as a download. Can be used - * with or without a filename value. - * - * @param null|string|Stringable|BooleanAttribute $download - * @return static - */ - public function setDownload(null|string|Stringable|BooleanAttribute $download): static - { - if ($download === BooleanAttribute::true) $this->attributes()['download'] = BooleanAttribute::true; - elseif ($download === BooleanAttribute::false) $this->unsetDownload(); - elseif ($download) $this->attributes()['download'] = $download; - else $this->unsetDownload(); - return $this; - } - - /** - * Causes the browser to treat the linked URL as a download. Can be used - * with or without a filename value. - * - * @return static - */ - public function unsetDownload(): static - { - unset($this->attributes()['download']); - return $this; - } - - /** - * The URL that the hyperlink points to. Links are not restricted to - * HTTP-based URLs — they can use any URL scheme supported by browsers - * - * @return null|string|Stringable - */ - public function href(): null|string|Stringable - { - return $this->attributes()->asString('href'); - } - - /** - * The URL that the hyperlink points to. Links are not restricted to - * HTTP-based URLs — they can use any URL scheme supported by browsers - * - * @param null|string|Stringable $href - * @return static - */ - public function setHref(null|string|Stringable $href): static - { - if ($href) $this->attributes()['href'] = $href; - else $this->unsetHref(); - return $this; - } - - /** - * The URL that the hyperlink points to. Links are not restricted to - * HTTP-based URLs — they can use any URL scheme supported by browsers - * - * @return static - */ - public function unsetHref(): static - { - $this->unsetHreflang(); - unset($this->attributes()['href']); - return $this; - } - - /** - * Hints at the human language of the linked URL. No built-in functionality. - * Allowed values are the same as the global lang attribute. - * - * @return null|string|Stringable - */ - public function hreflang(): null|string|Stringable - { - return $this->attributes()->asString('hreflang'); - } - - /** - * Hints at the human language of the linked URL. No built-in functionality. - * Allowed values are the same as the global lang attribute. - * - * @param null|string|Stringable $hreflang - * @return static - */ - public function setHreflang(null|string|Stringable $hreflang): static - { - if ($hreflang) $this->attributes()['hreflang'] = $hreflang; - else $this->unsetHreflang(); - return $this; - } - - /** - * Hints at the human language of the linked URL. No built-in functionality. - * Allowed values are the same as the global lang attribute. - * - * @return static - */ - public function unsetHreflang(): static - { - unset($this->attributes()['hreflang']); - return $this; - } - - /** - * A space-separated list of URLs. When the link is followed, the browser - * will send POST requests with the body PING to the URLs. Typically for - * tracking. - * - * @return null|string|Stringable - */ - public function ping(): null|string|Stringable - { - return $this->attributes()->asString('ping'); - } - - /** - * A space-separated list of URLs. When the link is followed, the browser - * will send POST requests with the body PING to the URLs. Typically for - * tracking. - * - * @param null|string|Stringable $ping - * @return static - */ - public function setPing(null|string|Stringable $ping): static - { - if ($ping) $this->attributes()['ping'] = $ping; - else $this->unsetPing(); - return $this; - } - - /** - * A space-separated list of URLs. When the link is followed, the browser - * will send POST requests with the body PING to the URLs. Typically for - * tracking. - * - * @return static - */ - public function unsetPing(): static - { - unset($this->attributes()['ping']); - return $this; - } - - /** - * An enum indicating which referrer to use when fetching the resource. - * - * @return null|ReferrerPolicy_a - */ - public function referrerpolicy(): null|ReferrerPolicy_a - { - return $this->attributes()->asEnum('referrerpolicy', ReferrerPolicy_a::class); - } - - /** - * An enum indicating which referrer to use when fetching the resource. - * - * @param null|ReferrerPolicy_a $referrerpolicy - * @return static - */ - public function setReferrerpolicy(null|ReferrerPolicy_a $referrerpolicy): static - { - if ($referrerpolicy) $this->attributes()['referrerpolicy'] = $referrerpolicy->value; - else $this->unsetReferrerpolicy(); - return $this; - } - - /** - * An enum indicating which referrer to use when fetching the resource. - * - * @return static - */ - public function unsetReferrerpolicy(): static - { - unset($this->attributes()['referrerpolicy']); - return $this; - } - - /** - * The relationship of the linked URL as space-separated link types. - * - * @return Rel_a[] - */ - public function rel(): array - { - return $this->attributes()->asEnumArray('rel', Rel_a::class, ' '); - } - - /** - * The relationship of the linked URL as space-separated link types. - * - * @param null|Rel_a|array $rel - * @return static - */ - public function setRel(null|Rel_a|array $rel): static - { - if ($rel) $this->attributes()->setEnumArray('rel', $rel, Rel_a::class, ' '); - else $this->unsetRel(); - return $this; - } - - /** - * The relationship of the linked URL as space-separated link types. - * - * @return static - */ - public function unsetRel(): static - { - unset($this->attributes()['rel']); - return $this; - } - - /** - * Where to display the linked URL, as the name for a browsing context (a - * tab, window, or