diff --git a/CHANGELOG.md b/CHANGELOG.md
index 02acf384..7e291fb7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
- New #260: Add `$attributes` parameter to `Html::li()` method (@gauravkumar2525)
- Enh #261: Enhance `RadioList::addRadioWrapClass()` method for cleaner class addition (@vjik)
- Enh #263: Explicitly import classes and constants in "use" section (@mspirkov)
+- Chg #243: Deprecate static constructors such as `TagName::tag()` in favor of `new TagName()` (@razvbir)
## 3.12.0 December 13, 2025
diff --git a/README.md b/README.md
index 1ff9daaf..bcf73c33 100644
--- a/README.md
+++ b/README.md
@@ -85,9 +85,9 @@ Tag classes allow working with a tag as an object and then get an HTML code by u
to string. For example, the following code:
```php
-echo \Yiisoft\Html\Tag\Div::tag()
+echo new \Yiisoft\Html\Tag\Div()
->content(
- \Yiisoft\Html\Tag\A::tag()
+ new \Yiisoft\Html\Tag\A()
->mailto('info@example.com')
->content('contact us')
->render()
@@ -108,7 +108,7 @@ echo \Yiisoft\Html\Tag\Div::tag()
To generate custom tags, use the `CustomTag` class. For example, the following code:
```php
-echo \Yiisoft\Html\Tag\CustomTag::name('b')
+echo new \Yiisoft\Html\Tag\CustomTag('b')
->content('text')
->attribute('title', 'Important');
```
@@ -166,7 +166,7 @@ complex HTML in simple PHP.
Represents a group of buttons.
```php
-echo \Yiisoft\Html\Widget\ButtonGroup::create()
+echo new \Yiisoft\Html\Widget\ButtonGroup()
->buttons(
\Yiisoft\Html\Html::resetButton('Reset Data'),
\Yiisoft\Html\Html::resetButton('Send'),
@@ -189,7 +189,7 @@ Result will be:
Represents a list of checkboxes.
```php
-echo \Yiisoft\Html\Widget\CheckboxList\CheckboxList::create('count')
+echo new \Yiisoft\Html\Widget\CheckboxList\CheckboxList('count')
->items([1 => 'One', 2 => 'Two', 5 => 'Five'])
->uncheckValue(0)
->value(2, 5)
@@ -212,7 +212,7 @@ Result will be:
Represents a list of radio buttons.
```php
-echo \Yiisoft\Html\Widget\RadioList\RadioList::create('count')
+echo new \Yiisoft\Html\Widget\RadioList\RadioList('count')
->items([1 => 'One', 2 => 'Two', 5 => 'Five'])
->uncheckValue(0)
->value(2)
diff --git a/src/Html.php b/src/Html.php
index c14daf29..a1393ae7 100644
--- a/src/Html.php
+++ b/src/Html.php
@@ -307,7 +307,7 @@ public static function escapeJavaScriptStringValue(mixed $value): string
*/
public static function tag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag
{
- $tag = CustomTag::name($name);
+ $tag = new CustomTag($name);
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -330,7 +330,7 @@ public static function tag(string $name, string|Stringable $content = '', array
*/
public static function normalTag(string $name, string|Stringable $content = '', array $attributes = []): CustomTag
{
- $tag = CustomTag::name($name)->normal();
+ $tag = (new CustomTag($name))->normal();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -352,7 +352,7 @@ public static function normalTag(string $name, string|Stringable $content = '',
*/
public static function voidTag(string $name, array $attributes = []): CustomTag
{
- $tag = CustomTag::name($name)->void();
+ $tag = (new CustomTag($name))->void();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -392,7 +392,7 @@ public static function closeTag(string $name): string
*/
public static function style(string $content = '', array $attributes = []): Style
{
- $tag = Style::tag();
+ $tag = new Style();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -410,7 +410,7 @@ public static function style(string $content = '', array $attributes = []): Styl
*/
public static function script(string $content = '', array $attributes = []): Script
{
- $tag = Script::tag();
+ $tag = new Script();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -427,7 +427,7 @@ public static function script(string $content = '', array $attributes = []): Scr
*/
public static function noscript(string|Stringable $content = ''): Noscript
{
- $tag = Noscript::tag();
+ $tag = new Noscript();
return $content === '' ? $tag : $tag->content($content);
}
@@ -439,7 +439,7 @@ public static function noscript(string|Stringable $content = ''): Noscript
*/
public static function title(string|Stringable $content = '', array $attributes = []): Title
{
- $tag = Title::tag();
+ $tag = new Title();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -453,7 +453,7 @@ public static function title(string|Stringable $content = '', array $attributes
*/
public static function meta(array $attributes = []): Meta
{
- $tag = Meta::tag();
+ $tag = new Meta();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -468,7 +468,7 @@ public static function meta(array $attributes = []): Meta
*/
public static function link(?string $url = null, array $attributes = []): Link
{
- $tag = Link::tag();
+ $tag = new Link();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -501,7 +501,7 @@ public static function cssFile(string $url, array $attributes = []): Link
*/
public static function javaScriptFile(string $url, array $attributes = []): Script
{
- $tag = Script::tag()->url($url);
+ $tag = (new Script())->url($url);
if (!empty($attributes)) {
$tag = $tag->addAttributes($attributes);
}
@@ -518,7 +518,7 @@ public static function javaScriptFile(string $url, array $attributes = []): Scri
*/
public static function a(string|Stringable $content = '', ?string $url = null, array $attributes = []): A
{
- $tag = A::tag();
+ $tag = new A();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -540,7 +540,7 @@ public static function a(string|Stringable $content = '', ?string $url = null, a
*/
public static function mailto(string $content, ?string $mail = null, array $attributes = []): A
{
- $tag = A::tag()
+ $tag = (new A())
->content($content)
->mailto($mail ?? $content);
if (!empty($attributes)) {
@@ -558,7 +558,7 @@ public static function mailto(string $content, ?string $mail = null, array $attr
*/
public static function img(?string $url = null, ?string $alt = '', array $attributes = []): Img
{
- $tag = Img::tag();
+ $tag = new Img();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -578,7 +578,7 @@ public static function img(?string $url = null, ?string $alt = '', array $attrib
*/
public static function fieldset(array $attributes = []): Fieldset
{
- $tag = Fieldset::tag();
+ $tag = new Fieldset();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -594,7 +594,7 @@ public static function fieldset(array $attributes = []): Fieldset
*/
public static function form(?string $action = null, ?string $method = null, array $attributes = []): Form
{
- $tag = Form::tag();
+ $tag = new Form();
if ($action !== null) {
$attributes['action'] = $action;
}
@@ -616,7 +616,7 @@ public static function form(?string $action = null, ?string $method = null, arra
*/
public static function label(string|Stringable $content = '', ?string $for = null): Label
{
- $tag = Label::tag();
+ $tag = new Label();
if ($for !== null) {
$tag = $tag->forId($for);
}
@@ -634,7 +634,7 @@ public static function label(string|Stringable $content = '', ?string $for = nul
*/
public static function legend(string|Stringable $content = '', array $attributes = []): Legend
{
- $tag = Legend::tag();
+ $tag = new Legend();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -710,7 +710,7 @@ public static function input(
bool|float|int|string|Stringable|null $value = null,
array $attributes = [],
): Input {
- $tag = Input::tag()->type($type);
+ $tag = (new Input())->type($type);
if ($name !== null) {
$tag = $tag->name($name);
}
@@ -929,7 +929,7 @@ public static function checkbox(
*/
public static function textarea(?string $name = null, string|Stringable|array|null $value = null, array $attributes = []): Textarea
{
- $tag = Textarea::tag();
+ $tag = new Textarea();
if ($name !== null) {
$tag = $tag->name($name);
}
@@ -946,7 +946,7 @@ public static function textarea(?string $name = null, string|Stringable|array|nu
*/
public static function select(?string $name = null): Select
{
- $tag = Select::tag();
+ $tag = new Select();
if ($name !== null) {
$tag = $tag->name($name);
}
@@ -958,7 +958,7 @@ public static function select(?string $name = null): Select
*/
public static function optgroup(): Optgroup
{
- return Optgroup::tag();
+ return new Optgroup();
}
/**
@@ -971,7 +971,7 @@ public static function option(
string|Stringable $content = '',
bool|float|int|string|Stringable|null $value = null,
): Option {
- $tag = Option::tag();
+ $tag = new Option();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -988,7 +988,7 @@ public static function option(
*/
public static function checkboxList(string $name): CheckboxList
{
- return CheckboxList::create($name);
+ return new CheckboxList($name);
}
/**
@@ -998,7 +998,7 @@ public static function checkboxList(string $name): CheckboxList
*/
public static function radioList(string $name): RadioList
{
- return RadioList::create($name);
+ return new RadioList($name);
}
/**
@@ -1009,7 +1009,7 @@ public static function radioList(string $name): RadioList
*/
public static function div(string|Stringable $content = '', array $attributes = []): Div
{
- $tag = Div::tag();
+ $tag = new Div();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1026,7 +1026,7 @@ public static function div(string|Stringable $content = '', array $attributes =
*/
public static function code(string|Stringable $content = '', array $attributes = []): Code
{
- $tag = Code::tag();
+ $tag = new Code();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1043,7 +1043,7 @@ public static function code(string|Stringable $content = '', array $attributes =
*/
public static function pre(string|Stringable $content = '', array $attributes = []): Pre
{
- $tag = Pre::tag();
+ $tag = new Pre();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1058,7 +1058,7 @@ public static function pre(string|Stringable $content = '', array $attributes =
*/
public static function span(string|Stringable $content = '', array $attributes = []): Span
{
- $tag = Span::tag();
+ $tag = new Span();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1073,7 +1073,7 @@ public static function span(string|Stringable $content = '', array $attributes =
*/
public static function em(string|Stringable $content = '', array $attributes = []): Em
{
- $tag = Em::tag();
+ $tag = new Em();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1088,7 +1088,7 @@ public static function em(string|Stringable $content = '', array $attributes = [
*/
public static function strong(string|Stringable $content = '', array $attributes = []): Strong
{
- $tag = Strong::tag();
+ $tag = new Strong();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1103,7 +1103,7 @@ public static function strong(string|Stringable $content = '', array $attributes
*/
public static function small(string|Stringable $content = '', array $attributes = []): Small
{
- $tag = Small::tag();
+ $tag = new Small();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1118,7 +1118,7 @@ public static function small(string|Stringable $content = '', array $attributes
*/
public static function b(string|Stringable $content = '', array $attributes = []): B
{
- $tag = B::tag();
+ $tag = new B();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1133,7 +1133,7 @@ public static function b(string|Stringable $content = '', array $attributes = []
*/
public static function i(string|Stringable $content = '', array $attributes = []): I
{
- $tag = I::tag();
+ $tag = new I();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1148,7 +1148,7 @@ public static function i(string|Stringable $content = '', array $attributes = []
*/
public static function h1(string|Stringable $content = '', array $attributes = []): H1
{
- $tag = H1::tag();
+ $tag = new H1();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1163,7 +1163,7 @@ public static function h1(string|Stringable $content = '', array $attributes = [
*/
public static function h2(string|Stringable $content = '', array $attributes = []): H2
{
- $tag = H2::tag();
+ $tag = new H2();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1178,7 +1178,7 @@ public static function h2(string|Stringable $content = '', array $attributes = [
*/
public static function h3(string|Stringable $content = '', array $attributes = []): H3
{
- $tag = H3::tag();
+ $tag = new H3();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1193,7 +1193,7 @@ public static function h3(string|Stringable $content = '', array $attributes = [
*/
public static function h4(string|Stringable $content = '', array $attributes = []): H4
{
- $tag = H4::tag();
+ $tag = new H4();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1208,7 +1208,7 @@ public static function h4(string|Stringable $content = '', array $attributes = [
*/
public static function h5(string|Stringable $content = '', array $attributes = []): H5
{
- $tag = H5::tag();
+ $tag = new H5();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1223,7 +1223,7 @@ public static function h5(string|Stringable $content = '', array $attributes = [
*/
public static function h6(string|Stringable $content = '', array $attributes = []): H6
{
- $tag = H6::tag();
+ $tag = new H6();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1238,7 +1238,7 @@ public static function h6(string|Stringable $content = '', array $attributes = [
*/
public static function p(string|Stringable $content = '', array $attributes = []): P
{
- $tag = P::tag();
+ $tag = new P();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1252,7 +1252,7 @@ public static function p(string|Stringable $content = '', array $attributes = []
*/
public static function ul(array $attributes = []): Ul
{
- $tag = Ul::tag();
+ $tag = new Ul();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1266,7 +1266,7 @@ public static function ul(array $attributes = []): Ul
*/
public static function ol(array $attributes = []): Ol
{
- $tag = Ol::tag();
+ $tag = new Ol();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1281,7 +1281,7 @@ public static function ol(array $attributes = []): Ol
*/
public static function li(string|Stringable $content = '', array $attributes = []): Li
{
- $tag = Li::tag();
+ $tag = new Li();
if ($attributes !== []) {
$tag = $tag->attributes($attributes);
@@ -1297,7 +1297,7 @@ public static function li(string|Stringable $content = '', array $attributes = [
*/
public static function datalist(array $attributes = []): Datalist
{
- $tag = Datalist::tag();
+ $tag = new Datalist();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1312,7 +1312,7 @@ public static function datalist(array $attributes = []): Datalist
*/
public static function caption(string|Stringable $content = '', array $attributes = []): Caption
{
- $tag = Caption::tag();
+ $tag = new Caption();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -1329,7 +1329,7 @@ public static function caption(string|Stringable $content = '', array $attribute
*/
public static function col(array $attributes = []): Col
{
- $tag = Col::tag();
+ $tag = new Col();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1340,7 +1340,7 @@ public static function col(array $attributes = []): Col
*/
public static function colgroup(array $attributes = []): Colgroup
{
- $tag = Colgroup::tag();
+ $tag = new Colgroup();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1351,7 +1351,7 @@ public static function colgroup(array $attributes = []): Colgroup
*/
public static function table(array $attributes = []): Table
{
- $tag = Table::tag();
+ $tag = new Table();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1362,7 +1362,7 @@ public static function table(array $attributes = []): Table
*/
public static function thead(array $attributes = []): Thead
{
- $tag = Thead::tag();
+ $tag = new Thead();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1373,7 +1373,7 @@ public static function thead(array $attributes = []): Thead
*/
public static function tbody(array $attributes = []): Tbody
{
- $tag = Tbody::tag();
+ $tag = new Tbody();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1384,7 +1384,7 @@ public static function tbody(array $attributes = []): Tbody
*/
public static function tfoot(array $attributes = []): Tfoot
{
- $tag = Tfoot::tag();
+ $tag = new Tfoot();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1395,7 +1395,7 @@ public static function tfoot(array $attributes = []): Tfoot
*/
public static function tr(array $attributes = []): Tr
{
- $tag = Tr::tag();
+ $tag = new Tr();
return $attributes === [] ? $tag : $tag->attributes($attributes);
}
@@ -1407,7 +1407,7 @@ public static function tr(array $attributes = []): Tr
*/
public static function td(string|Stringable $content = '', array $attributes = []): Td
{
- $tag = Td::tag();
+ $tag = new Td();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -1425,7 +1425,7 @@ public static function td(string|Stringable $content = '', array $attributes = [
*/
public static function th(string|Stringable $content = '', array $attributes = []): Th
{
- $tag = Th::tag();
+ $tag = new Th();
if ($content !== '') {
$tag = $tag->content($content);
}
@@ -1440,7 +1440,7 @@ public static function th(string|Stringable $content = '', array $attributes = [
*/
public static function br(): Br
{
- return Br::tag();
+ return new Br();
}
/**
@@ -1448,7 +1448,7 @@ public static function br(): Br
*/
public static function video(): Video
{
- return Video::tag();
+ return new Video();
}
/**
@@ -1456,7 +1456,7 @@ public static function video(): Video
*/
public static function audio(): Audio
{
- return Audio::tag();
+ return new Audio();
}
/**
@@ -1464,7 +1464,7 @@ public static function audio(): Audio
*/
public static function track(?string $src = null): Track
{
- $tag = Track::tag();
+ $tag = new Track();
return $src === null ? $tag : $tag->src($src);
}
@@ -1473,7 +1473,7 @@ public static function track(?string $src = null): Track
*/
public static function picture(): Picture
{
- return Picture::tag();
+ return new Picture();
}
/**
@@ -1481,7 +1481,7 @@ public static function picture(): Picture
*/
public static function source(): Source
{
- return Source::tag();
+ return new Source();
}
/**
@@ -1493,7 +1493,7 @@ public static function source(): Source
*/
public static function html(string|Stringable $content = '', ?string $lang = null, array $attributes = []): Tag\Html
{
- $tag = Tag\Html::tag();
+ $tag = new Tag\Html();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1514,7 +1514,7 @@ public static function html(string|Stringable $content = '', ?string $lang = nul
*/
public static function body(string|Stringable $content = '', array $attributes = []): Body
{
- $tag = Body::tag();
+ $tag = new Body();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1529,7 +1529,7 @@ public static function body(string|Stringable $content = '', array $attributes =
*/
public static function article(string|Stringable $content = '', array $attributes = []): Article
{
- $tag = Article::tag();
+ $tag = new Article();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1544,7 +1544,7 @@ public static function article(string|Stringable $content = '', array $attribute
*/
public static function section(string|Stringable $content = '', array $attributes = []): Section
{
- $tag = Section::tag();
+ $tag = new Section();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1559,7 +1559,7 @@ public static function section(string|Stringable $content = '', array $attribute
*/
public static function nav(string|Stringable $content = '', array $attributes = []): Nav
{
- $tag = Nav::tag();
+ $tag = new Nav();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1574,7 +1574,7 @@ public static function nav(string|Stringable $content = '', array $attributes =
*/
public static function aside(string|Stringable $content = '', array $attributes = []): Aside
{
- $tag = Aside::tag();
+ $tag = new Aside();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1589,7 +1589,7 @@ public static function aside(string|Stringable $content = '', array $attributes
*/
public static function hgroup(string|Stringable $content = '', array $attributes = []): Hgroup
{
- $tag = Hgroup::tag();
+ $tag = new Hgroup();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1604,7 +1604,7 @@ public static function hgroup(string|Stringable $content = '', array $attributes
*/
public static function header(string|Stringable $content = '', array $attributes = []): Header
{
- $tag = Header::tag();
+ $tag = new Header();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1616,7 +1616,7 @@ public static function header(string|Stringable $content = '', array $attributes
*/
public static function hr(array $attributes = []): Hr
{
- $tag = Hr::tag();
+ $tag = new Hr();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1631,7 +1631,7 @@ public static function hr(array $attributes = []): Hr
*/
public static function footer(string|Stringable $content = '', array $attributes = []): Footer
{
- $tag = Footer::tag();
+ $tag = new Footer();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
@@ -1646,7 +1646,7 @@ public static function footer(string|Stringable $content = '', array $attributes
*/
public static function address(string|Stringable $content = '', array $attributes = []): Address
{
- $tag = Address::tag();
+ $tag = new Address();
if (!empty($attributes)) {
$tag = $tag->attributes($attributes);
}
diff --git a/src/Tag/Base/ListTag.php b/src/Tag/Base/ListTag.php
index d6f34e82..f4cc2052 100644
--- a/src/Tag/Base/ListTag.php
+++ b/src/Tag/Base/ListTag.php
@@ -34,7 +34,7 @@ public function items(Li ...$items): static
public function strings(array $strings, array $attributes = [], bool $encode = true): static
{
$items = array_map(
- static fn(string $string) => Li::tag()
+ static fn(string $string) => (new Li())
->content($string)
->attributes($attributes)
->encode($encode),
diff --git a/src/Tag/Base/NormalTag.php b/src/Tag/Base/NormalTag.php
index ab8ac07c..cf05ce0e 100644
--- a/src/Tag/Base/NormalTag.php
+++ b/src/Tag/Base/NormalTag.php
@@ -9,8 +9,11 @@
*/
abstract class NormalTag extends Tag
{
- final private function __construct() {}
+ final public function __construct() {}
+ /**
+ * @deprecated Use the constructor instead.
+ */
final public static function tag(): static
{
return new static();
diff --git a/src/Tag/Base/VoidTag.php b/src/Tag/Base/VoidTag.php
index 34012b14..77a87305 100644
--- a/src/Tag/Base/VoidTag.php
+++ b/src/Tag/Base/VoidTag.php
@@ -10,8 +10,11 @@
*/
abstract class VoidTag extends Tag
{
- final private function __construct() {}
+ final public function __construct() {}
+ /**
+ * @deprecated Use the constructor instead.
+ */
final public static function tag(): static
{
return new static();
diff --git a/src/Tag/Button.php b/src/Tag/Button.php
index ba59169a..c370eb5a 100644
--- a/src/Tag/Button.php
+++ b/src/Tag/Button.php
@@ -16,21 +16,21 @@ final class Button extends NormalTag
public static function button(string $content = ''): self
{
- $button = self::tag()->content($content);
+ $button = (new self())->content($content);
$button->attributes['type'] = 'button';
return $button;
}
public static function submit(string $content = ''): self
{
- $button = self::tag()->content($content);
+ $button = (new self())->content($content);
$button->attributes['type'] = 'submit';
return $button;
}
public static function reset(string $content = ''): self
{
- $button = self::tag()->content($content);
+ $button = (new self())->content($content);
$button->attributes['type'] = 'reset';
return $button;
}
diff --git a/src/Tag/CustomTag.php b/src/Tag/CustomTag.php
index 933d0d31..a7d02036 100644
--- a/src/Tag/CustomTag.php
+++ b/src/Tag/CustomTag.php
@@ -44,7 +44,7 @@ final class CustomTag extends Tag
private int $type = self::TYPE_AUTO;
- private function __construct(
+ public function __construct(
private string $name,
) {}
@@ -54,6 +54,8 @@ private function __construct(
* @param string $name Name of the tag.
*
* @psalm-param non-empty-string $name
+ *
+ * @deprecated Use the constructor instead.
*/
public static function name(string $name): self
{
diff --git a/src/Tag/Input.php b/src/Tag/Input.php
index 9e50aeb5..412a9a19 100644
--- a/src/Tag/Input.php
+++ b/src/Tag/Input.php
@@ -29,7 +29,7 @@ final class Input extends InputTag
*/
public static function hidden(?string $name = null, bool|float|int|string|Stringable|null $value = null): self
{
- $input = self::tag();
+ $input = new self();
$input->attributes['type'] = 'hidden';
$input->attributes['name'] = $name;
$input->attributes['value'] = $value;
@@ -46,7 +46,7 @@ public static function hidden(?string $name = null, bool|float|int|string|String
*/
public static function text(?string $name = null, bool|float|int|string|Stringable|null $value = null): self
{
- $input = self::tag();
+ $input = new self();
$input->attributes['type'] = 'text';
$input->attributes['name'] = $name;
$input->attributes['value'] = $value;
@@ -63,7 +63,7 @@ public static function text(?string $name = null, bool|float|int|string|Stringab
*/
public static function password(?string $name = null, bool|float|int|string|Stringable|null $value = null): self
{
- $input = self::tag();
+ $input = new self();
$input->attributes['type'] = 'password';
$input->attributes['name'] = $name;
$input->attributes['value'] = $value;
@@ -80,7 +80,7 @@ public static function password(?string $name = null, bool|float|int|string|Stri
*/
public static function file(?string $name = null, bool|float|int|string|Stringable|null $value = null): File
{
- $input = File::tag();
+ $input = new File();
if ($name !== null) {
$input = $input->name($name);
}
@@ -100,7 +100,7 @@ public static function file(?string $name = null, bool|float|int|string|Stringab
*/
public static function checkbox(?string $name = null, bool|float|int|string|Stringable|null $value = null): Checkbox
{
- $input = Checkbox::tag();
+ $input = new Checkbox();
if ($name !== null) {
$input = $input->name($name);
}
@@ -120,7 +120,7 @@ public static function checkbox(?string $name = null, bool|float|int|string|Stri
*/
public static function radio(?string $name = null, bool|float|int|string|Stringable|null $value = null): Radio
{
- $input = Radio::tag();
+ $input = new Radio();
if ($name !== null) {
$input = $input->name($name);
}
@@ -140,7 +140,7 @@ public static function radio(?string $name = null, bool|float|int|string|Stringa
*/
public static function range(?string $name = null, float|int|string|Stringable|null $value = null): Range
{
- $input = Range::tag();
+ $input = new Range();
if ($name !== null) {
$input = $input->name($name);
}
@@ -160,7 +160,7 @@ public static function range(?string $name = null, float|int|string|Stringable|n
*/
public static function color(?string $name = null, string|Stringable|null $value = null): Color
{
- $input = Color::tag();
+ $input = new Color();
if ($name !== null) {
$input = $input->name($name);
}
@@ -179,7 +179,7 @@ public static function color(?string $name = null, string|Stringable|null $value
*/
public static function button(?string $label = null): self
{
- $input = self::tag();
+ $input = new self();
$input->attributes['type'] = 'button';
$input->attributes['value'] = $label;
return $input;
@@ -194,7 +194,7 @@ public static function button(?string $label = null): self
*/
public static function submitButton(?string $label = null): self
{
- $input = self::tag();
+ $input = new self();
$input->attributes['type'] = 'submit';
$input->attributes['value'] = $label;
return $input;
@@ -209,7 +209,7 @@ public static function submitButton(?string $label = null): self
*/
public static function resetButton(?string $label = null): self
{
- $input = self::tag();
+ $input = new self();
$input->attributes['type'] = 'reset';
$input->attributes['value'] = $label;
return $input;
diff --git a/src/Tag/Input/Range.php b/src/Tag/Input/Range.php
index 48df6046..e3d63d20 100644
--- a/src/Tag/Input/Range.php
+++ b/src/Tag/Input/Range.php
@@ -126,7 +126,7 @@ protected function after(): string
return '';
}
- return "\n" . CustomTag::name($this->outputTag)
+ return "\n" . (new CustomTag($this->outputTag))
->attributes($this->outputAttributes)
->content((string) ($this->attributes['value'] ?? '-'))
->id($this->outputId)
diff --git a/src/Tag/Link.php b/src/Tag/Link.php
index 93d056ec..710af8f1 100644
--- a/src/Tag/Link.php
+++ b/src/Tag/Link.php
@@ -13,7 +13,7 @@ final class Link extends VoidTag
{
public static function toCssFile(string $url): self
{
- $link = self::tag();
+ $link = new self();
$link->attributes['rel'] = 'stylesheet';
$link->attributes['href'] = $url;
return $link;
diff --git a/src/Tag/Meta.php b/src/Tag/Meta.php
index c04f40a4..ef4303bf 100644
--- a/src/Tag/Meta.php
+++ b/src/Tag/Meta.php
@@ -16,7 +16,7 @@ final class Meta extends VoidTag
*/
public static function data(string $name, string $content): self
{
- $tag = self::tag();
+ $tag = new self();
$tag->attributes['name'] = $name;
$tag->attributes['content'] = $content;
return $tag;
@@ -27,7 +27,7 @@ public static function data(string $name, string $content): self
*/
public static function pragmaDirective(string $name, string $content): self
{
- $tag = self::tag();
+ $tag = new self();
$tag->attributes['http-equiv'] = $name;
$tag->attributes['content'] = $content;
return $tag;
@@ -38,7 +38,7 @@ public static function pragmaDirective(string $name, string $content): self
*/
public static function documentEncoding(string $encoding): self
{
- $tag = self::tag();
+ $tag = new self();
$tag->attributes['charset'] = $encoding;
return $tag;
}
@@ -48,7 +48,7 @@ public static function documentEncoding(string $encoding): self
*/
public static function description(string $content): self
{
- $tag = self::tag();
+ $tag = new self();
$tag->attributes['name'] = 'description';
$tag->attributes['content'] = $content;
return $tag;
diff --git a/src/Tag/Optgroup.php b/src/Tag/Optgroup.php
index 5fae1709..83f9cbe5 100644
--- a/src/Tag/Optgroup.php
+++ b/src/Tag/Optgroup.php
@@ -35,7 +35,7 @@ public function optionsData(array $data, bool $encode = true, array $optionsAttr
{
$options = [];
foreach ($data as $value => $content) {
- $options[] = Option::tag()
+ $options[] = (new Option())
->attributes($optionsAttributes[$value] ?? [])
->value($value)
->content($content)
diff --git a/src/Tag/Script.php b/src/Tag/Script.php
index 220b6783..4716c01c 100644
--- a/src/Tag/Script.php
+++ b/src/Tag/Script.php
@@ -130,7 +130,7 @@ public function defer(bool $defer = true): self
public function noscript(string|Stringable|null $content): self
{
$new = clone $this;
- $new->noscript = $content === null ? null : Noscript::tag()->content($content);
+ $new->noscript = $content === null ? null : (new Noscript())->content($content);
return $new;
}
diff --git a/src/Tag/Select.php b/src/Tag/Select.php
index d5e45bcb..1d81dc0d 100644
--- a/src/Tag/Select.php
+++ b/src/Tag/Select.php
@@ -152,12 +152,12 @@ public function optionsData(
$items = [];
foreach ($data as $value => $content) {
if (is_array($content)) {
- $items[] = Optgroup::tag()
+ $items[] = (new Optgroup())
->label((string) $value)
->addAttributes($groupsAttributes[$value] ?? [])
->optionsData($content, $encode, $optionsAttributes);
} else {
- $items[] = Option::tag()
+ $items[] = (new Option())
->attributes($optionsAttributes[$value] ?? [])
->value($value)
->content($content)
@@ -174,7 +174,7 @@ public function optionsData(
public function prompt(?string $text): self
{
$new = clone $this;
- $new->prompt = $text === null ? null : Option::tag()
+ $new->prompt = $text === null ? null : (new Option())
->value('')
->content($text);
return $new;
diff --git a/src/Tag/Table.php b/src/Tag/Table.php
index 94c07009..28a11d2e 100644
--- a/src/Tag/Table.php
+++ b/src/Tag/Table.php
@@ -46,7 +46,7 @@ public function caption(?Caption $caption): self
public function captionString(string $content, bool $encode = true): self
{
- $caption = Caption::tag()->content($content);
+ $caption = (new Caption())->content($content);
if (!$encode) {
$caption = $caption->encode(false);
}
diff --git a/src/Tag/Tr.php b/src/Tag/Tr.php
index ce8ed00f..7179dcd6 100644
--- a/src/Tag/Tr.php
+++ b/src/Tag/Tr.php
@@ -97,7 +97,7 @@ protected function getName(): string
private function makeDataCells(array $strings, array $attributes, bool $encode): array
{
return array_map(
- static fn(string $string) => Td::tag()
+ static fn(string $string) => (new Td())
->content($string)
->attributes($attributes)
->encode($encode),
@@ -113,7 +113,7 @@ private function makeDataCells(array $strings, array $attributes, bool $encode):
private function makeHeaderCells(array $strings, array $attributes, bool $encode): array
{
return array_map(
- static fn(string $string) => Th::tag()
+ static fn(string $string) => (new Th())
->content($string)
->attributes($attributes)
->encode($encode),
diff --git a/src/Widget/ButtonGroup.php b/src/Widget/ButtonGroup.php
index 2b1ae41c..76eb0b63 100644
--- a/src/Widget/ButtonGroup.php
+++ b/src/Widget/ButtonGroup.php
@@ -27,13 +27,16 @@ final class ButtonGroup implements NoEncodeStringableInterface
private array $buttonAttributes = [];
private string $separator = "\n";
- private function __construct() {}
+ public function __construct() {}
public function __toString(): string
{
return $this->render();
}
+ /**
+ * @deprecated Use the constructor instead.
+ */
public static function create(): self
{
return new self();
diff --git a/src/Widget/CheckboxList/CheckboxList.php b/src/Widget/CheckboxList/CheckboxList.php
index 79648351..87a198f8 100644
--- a/src/Widget/CheckboxList/CheckboxList.php
+++ b/src/Widget/CheckboxList/CheckboxList.php
@@ -53,7 +53,7 @@ final class CheckboxList implements NoEncodeStringableInterface
*/
private ?Closure $itemFormatter = null;
- private function __construct(
+ public function __construct(
private string $name,
) {}
@@ -62,6 +62,9 @@ public function __toString(): string
return $this->render();
}
+ /**
+ * @deprecated Use the constructor instead.
+ */
public static function create(string $name): self
{
return new self($name);
diff --git a/src/Widget/RadioList/RadioList.php b/src/Widget/RadioList/RadioList.php
index e9b22269..6d5c6103 100644
--- a/src/Widget/RadioList/RadioList.php
+++ b/src/Widget/RadioList/RadioList.php
@@ -47,7 +47,7 @@ final class RadioList implements NoEncodeStringableInterface
*/
private ?Closure $itemFormatter = null;
- private function __construct(
+ public function __construct(
private string $name,
) {}
@@ -56,6 +56,9 @@ public function __toString(): string
return $this->render();
}
+ /**
+ * @deprecated Use the constructor instead.
+ */
public static function create(string $name): self
{
return new self($name);
diff --git a/tests/HtmlTest.php b/tests/HtmlTest.php
index 6a604742..b1256397 100644
--- a/tests/HtmlTest.php
+++ b/tests/HtmlTest.php
@@ -122,7 +122,7 @@ public function testNoscript(): void
{
$this->assertSame('', Html::noscript()->render());
$this->assertSame('', Html::noscript('hello')->render());
- $this->assertSame('', Html::noscript(Div::tag())->render());
+ $this->assertSame('', Html::noscript(new Div())->render());
}
public function testTitle(): void
diff --git a/tests/Tag/ATest.php b/tests/Tag/ATest.php
index ea7eb326..63c10e18 100644
--- a/tests/Tag/ATest.php
+++ b/tests/Tag/ATest.php
@@ -14,7 +14,7 @@ public function testBase(): void
{
$this->assertSame(
'Link',
- (string) A::tag()
+ (string) (new A())
->url('https://example.com')
->content('Link'),
);
@@ -31,7 +31,7 @@ public static function dataHref(): array
#[DataProvider('dataHref')]
public function testHref(string $expected, ?string $href): void
{
- $this->assertSame($expected, (string) A::tag()->href($href));
+ $this->assertSame($expected, (string) (new A())->href($href));
}
public static function dataUrl(): array
@@ -45,7 +45,7 @@ public static function dataUrl(): array
#[DataProvider('dataUrl')]
public function testUrl(string $expected, ?string $url): void
{
- $this->assertSame($expected, (string) A::tag()->url($url));
+ $this->assertSame($expected, (string) (new A())->url($url));
}
public static function dataMailto(): array
@@ -59,7 +59,7 @@ public static function dataMailto(): array
#[DataProvider('dataMailto')]
public function testMailto(string $expected, ?string $url): void
{
- $this->assertSame($expected, (string) A::tag()->mailto($url));
+ $this->assertSame($expected, (string) (new A())->mailto($url));
}
public static function dataRel(): array
@@ -76,12 +76,12 @@ public static function dataRel(): array
#[DataProvider('dataRel')]
public function testRel(string $expected, ?string $rel): void
{
- $this->assertSame($expected, (string) A::tag()->rel($rel));
+ $this->assertSame($expected, (string) (new A())->rel($rel));
}
public function testNofollow(): void
{
- $this->assertSame('', (string) A::tag()->nofollow());
+ $this->assertSame('', (string) (new A())->nofollow());
}
public static function dataTarget(): array
@@ -95,12 +95,12 @@ public static function dataTarget(): array
#[DataProvider('dataTarget')]
public function testTarget(string $expected, ?string $contextName): void
{
- $this->assertSame($expected, (string) A::tag()->target($contextName));
+ $this->assertSame($expected, (string) (new A())->target($contextName));
}
public function testImmutability(): void
{
- $tag = A::tag();
+ $tag = new A();
$this->assertNotSame($tag, $tag->content(''));
$this->assertNotSame($tag, $tag->href(null));
$this->assertNotSame($tag, $tag->url(null));
diff --git a/tests/Tag/AddressTest.php b/tests/Tag/AddressTest.php
index 0ed2adef..a1ccf7de 100644
--- a/tests/Tag/AddressTest.php
+++ b/tests/Tag/AddressTest.php
@@ -14,10 +14,10 @@ public function testBase(): void
{
$this->assertSame(
'
Street 111, Mount View Town. Contact: xx-xx-xxxx',
- (string) Address::tag()
+ (string) (new Address())
->content(
'Street 111, Mount View Town. Contact: '
- . A::tag()
+ . (new A())
->href('tel:xx-xx-xxxx')
->content('xx-xx-xxxx'),
)
diff --git a/tests/Tag/ArticleTest.php b/tests/Tag/ArticleTest.php
index 6c07f2ca..dc4e3fd3 100644
--- a/tests/Tag/ArticleTest.php
+++ b/tests/Tag/ArticleTest.php
@@ -17,11 +17,11 @@ public function testBase(): void
{
$this->assertSame(
'Article content
',
- (string) Article::tag()
+ (string) (new Article())
->content(
- Header::tag()->content(H1::tag()->content('Heading 1'))
- . P::tag()->content('Article content')
- . Footer::tag()->content('Footer'),
+ (new Header())->content((new H1())->content('Heading 1'))
+ . (new P())->content('Article content')
+ . (new Footer())->content('Footer'),
)
->encode(false),
);
diff --git a/tests/Tag/AsideTest.php b/tests/Tag/AsideTest.php
index 4f3157d6..698dc809 100644
--- a/tests/Tag/AsideTest.php
+++ b/tests/Tag/AsideTest.php
@@ -15,10 +15,10 @@ public function testBase(): void
{
$this->assertSame(
'',
- (string) Aside::tag()
+ (string) (new Aside())
->content(
- H2::tag()->content('Hello')
- . P::tag()->content('Aside Tag Content'),
+ (new H2())->content('Hello')
+ . (new P())->content('Aside Tag Content'),
)
->encode(false),
);
diff --git a/tests/Tag/AudioTest.php b/tests/Tag/AudioTest.php
index ee49d906..8ebd0d91 100644
--- a/tests/Tag/AudioTest.php
+++ b/tests/Tag/AudioTest.php
@@ -20,10 +20,10 @@ public function testBase(): void
. '