class HtmlElement implements ArrayAccess, IteratorAggregate

HTML helper.

usage: $anchor = (new HtmlElement('a'))->href($link)->setText('Texy'); $el->class = 'myclass';

echo $el->startTag(), $el->endTag();

Constants

InnerText

InnerTransparent

Properties

bool $transparent
array<string,string|int|bool|string[]|null> $attrs
static array<string,int> $emptyElements
static array<string,int> $inlineElements
static array<string,int> $optionalEnds
static array<string,array<int,string>> $prohibits
protected HtmlElement|string> $children

Methods

__construct(string|null $name = null, array|string|null $attrs = null)

No description

static HtmlElement
el(string|null $name = null, $attrs = null)

No description

setName(string|null $name, bool|null $empty = null)

Changes element's name.

string|null
getName()

Returns element's name.

bool
isEmpty()

Is element empty?

void
__set(string $name, $value)

Overloaded setter for element's attribute.

__get(string $name)

Overloaded getter for element's attribute.

setAttribute(string $name, $value)

Sets element's attribute.

string|int|bool|string[]|null
getAttribute(string $name)

Returns element's attribute.

href(string $path, array|null $query = null)

Special setter for element's attribute.

setText(string $text)

Sets element's textual content.

string|null
getText()

Gets element's textual content.

add(self|string $child)

Adds new element's child.

create(string $name, array|string|null $attrs = null)

Creates and adds a new HtmlElement child.

insert(int|null $index, self|string $child, bool $replace = false)

Inserts child node.

void
offsetSet(int $index, HtmlElement $child)

Inserts (replaces) child node (ArrayAccess implementation).

mixed
offsetGet(int $index)

Returns child node (ArrayAccess implementation).

bool
offsetExists(int $index)

Exists child node? (ArrayAccess implementation).

void
offsetUnset(int $index)

Removes child node (ArrayAccess implementation).

int
count()

Required by the Countable interface.

void
removeChildren()

Removed all children.

getIterator()

Required by the IteratorAggregate interface.

array
getChildren()

Returns all of children.

string
toString(Texy $texy)

Renders element's start tag, content and end tag to internal string representation.

string
toHtml(Texy $texy)

Renders to final HTML.

string
toText(Texy $texy)

Renders to final text.

string
startTag()

Returns element's start tag.

string
endTag()

Returns element's end tag.

__clone()

Clones all children too.

string
getContentType()

No description

void
validateAttrs(array $dtd)

No description

bool
validateChild($child, array $dtd)

No description

parseLine(Texy $texy, string $s)

Parses text as single line.

void
parseBlock(Texy $texy, string $s, bool $indented = false)

Parses text as block.

Details

at line 101
__construct(string|null $name = null, array|string|null $attrs = null)

No description

Parameters

string|null $name
array|string|null $attrs

element's attributes (or textual content)

at line 112
static HtmlElement el(string|null $name = null, $attrs = null)

No description

Parameters

string|null $name
$attrs

Return Value

HtmlElement

at line 121
final HtmlElement setName(string|null $name, bool|null $empty = null)

Changes element's name.

Parameters

string|null $name
bool|null $empty

Return Value

HtmlElement

at line 134
final string|null getName()

Returns element's name.

Return Value

string|null

at line 143
final bool isEmpty()

Is element empty?

Return Value

bool

at line 152
final void __set(string $name, $value)

Overloaded setter for element's attribute.

Parameters

string $name
$value

Return Value

void

at line 161
final __get(string $name)

Overloaded getter for element's attribute.

Parameters

string $name

at line 170
final HtmlElement setAttribute(string $name, $value)

Sets element's attribute.

Parameters

string $name
$value

Return Value

HtmlElement

at line 181
final string|int|bool|string[]|null getAttribute(string $name)

Returns element's attribute.

Parameters

string $name

Return Value

string|int|bool|string[]|null

at line 190
final HtmlElement href(string $path, array|null $query = null)

Special setter for element's attribute.

Parameters

string $path
array|null $query

Return Value

HtmlElement

at line 207
final HtmlElement setText(string $text)

Sets element's textual content.

Parameters

string $text

Return Value

HtmlElement

at line 218
final string|null getText()

Gets element's textual content.

Return Value

string|null

at line 236
final HtmlElement add(self|string $child)

Adds new element's child.

Parameters

self|string $child

Return Value

HtmlElement

at line 245
final HtmlElement create(string $name, array|string|null $attrs = null)

Creates and adds a new HtmlElement child.

Parameters

string $name
array|string|null $attrs

Return Value

HtmlElement

at line 255
HtmlElement insert(int|null $index, self|string $child, bool $replace = false)

Inserts child node.

Parameters

int|null $index
self|string $child
bool $replace

Return Value

HtmlElement

at line 273
final void offsetSet(int $index, HtmlElement $child)

Inserts (replaces) child node (ArrayAccess implementation).

Parameters

int $index
HtmlElement $child

Return Value

void

at line 283
final mixed offsetGet(int $index)

Returns child node (ArrayAccess implementation).

Parameters

int $index

Return Value

mixed

at line 293
final bool offsetExists(int $index)

Exists child node? (ArrayAccess implementation).

Parameters

int $index

Return Value

bool

at line 303
void offsetUnset(int $index)

Removes child node (ArrayAccess implementation).

Parameters

int $index

Return Value

void

at line 314
final int count()

Required by the Countable interface.

Return Value

int

at line 323
void removeChildren()

Removed all children.

Return Value

void

at line 332
final ArrayIterator getIterator()

Required by the IteratorAggregate interface.

Return Value

ArrayIterator

at line 341
final array getChildren()

Returns all of children.

Return Value

array

at line 350
final string toString(Texy $texy)

Renders element's start tag, content and end tag to internal string representation.

Parameters

Texy $texy

Return Value

string

at line 377
final string toHtml(Texy $texy)

Renders to final HTML.

Parameters

Texy $texy

Return Value

string

at line 386
final string toText(Texy $texy)

Renders to final text.

Parameters

Texy $texy

Return Value

string

at line 395
string startTag()

Returns element's start tag.

Return Value

string

at line 445
string endTag()

Returns element's end tag.

Return Value

string

at line 458
__clone()

Clones all children too.

at line 468
final string getContentType()

No description

Return Value

string

at line 477
final void validateAttrs(array $dtd)

No description

Parameters

array $dtd

Return Value

void

at line 494
bool validateChild($child, array $dtd)

No description

Parameters

$child
array $dtd

Return Value

bool

at line 511
final LineParser parseLine(Texy $texy, string $s)

Parses text as single line.

Parameters

Texy $texy
string $s

Return Value

LineParser

at line 522
final void parseBlock(Texy $texy, string $s, bool $indented = false)

Parses text as block.

Parameters

Texy $texy
string $s
bool $indented

Return Value

void

Traits

Better OOP experience.