class HtmlElement implements ArrayAccess, IteratorAggregate

HTML helper.

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

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

Traits

Better OOP experience.

Properties

array $attrs
static bool $xhtml
static array $emptyElements
static array $inlineElements
static array $optionalEnds
static $prohibits
protected array $children

Methods

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

No description

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

No description

setName(string|null $name, bool $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.

href(string $path, array $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(HtmlElement|string $child)

Adds new element's child.

create(string $name, $attrs = null)

Creates and adds a new HtmlElement child.

insert(int|null $index, $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 82
__construct(string $name = null, $attrs = null)

Parameters

string $name
$attrs

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

Parameters

string $name
$attrs

Return Value

HtmlElement

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

Changes element's name.

Parameters

string|null $name
bool $empty

Return Value

HtmlElement

Exceptions

InvalidArgumentException

at line 118
final string|null getName()

Returns element's name.

Return Value

string|null

at line 127
final bool isEmpty()

Is element empty?

Return Value

bool

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

Overloaded setter for element's attribute.

Parameters

string $name
$value

Return Value

void

at line 145
final __get(string $name)

Overloaded getter for element's attribute.

Parameters

string $name

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

Special setter for element's attribute.

Parameters

string $path
array $query

Return Value

HtmlElement

at line 170
final HtmlElement setText(string $text)

Sets element's textual content.

Parameters

string $text

Return Value

HtmlElement

at line 185
final string|null getText()

Gets element's textual content.

Return Value

string|null

at line 202
final HtmlElement add(HtmlElement|string $child)

Adds new element's child.

Parameters

HtmlElement|string $child node

Return Value

HtmlElement

at line 212
final HtmlElement create(string $name, $attrs = null)

Creates and adds a new HtmlElement child.

Parameters

string $name
$attrs

Return Value

HtmlElement

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

Inserts child node.

Parameters

int|null $index
$child
bool $replace

Return Value

HtmlElement

Exceptions

Exception

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

Inserts (replaces) child node (ArrayAccess implementation).

Parameters

int $index
HtmlElement $child

Return Value

void

at line 258
final mixed offsetGet(int $index)

Returns child node (ArrayAccess implementation).

Parameters

int $index

Return Value

mixed

at line 268
final bool offsetExists(int $index)

Exists child node? (ArrayAccess implementation).

Parameters

int $index

Return Value

bool

at line 278
void offsetUnset(int $index)

Removes child node (ArrayAccess implementation).

Parameters

int $index

Return Value

void

at line 289
final int count()

Required by the Countable interface.

Return Value

int

at line 298
void removeChildren()

Removed all children.

Return Value

void

at line 307
final ArrayIterator getIterator()

Required by the IteratorAggregate interface.

Return Value

ArrayIterator

at line 316
final array getChildren()

Returns all of children.

Return Value

array

at line 325
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 352
final string toHtml(Texy $texy)

Renders to final HTML.

Parameters

Texy $texy

Return Value

string

at line 361
final string toText(Texy $texy)

Renders to final text.

Parameters

Texy $texy

Return Value

string

at line 370
string startTag()

Returns element's start tag.

Return Value

string

at line 436
string endTag()

Returns element's end tag.

Return Value

string

at line 448
__clone()

Clones all children too.

at line 458
final string getContentType()

Return Value

string

at line 468
final void validateAttrs(array $dtd)

Parameters

array $dtd

Return Value

void

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

Parameters

$child
array $dtd

Return Value

bool

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

Parses text as single line.

Parameters

Texy $texy
string $s

Return Value

LineParser

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

Parses text as block.

Parameters

Texy $texy
string $s
bool $indented

Return Value

void