class HtmlElement implements ArrayAccess, IteratorAggregate

HTML helper.

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

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

Properties

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

Methods

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

No description

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

No description

setName($name, $empty = null)

Changes element's name.

string
getName()

Returns element's name.

bool
isEmpty()

Is element empty?

void
__set($name, $value)

Overloaded setter for element's attribute.

mixed
__get($name)

Overloaded getter for element's attribute.

href($path, $query = null)

Special setter for element's attribute.

setText($text)

Sets element's textual content.

string
getText()

Gets element's textual content.

add($child)

Adds new element's child.

create($name, $attrs = null)

Creates and adds a new HtmlElement child.

insert($index, $child, $replace = false)

Inserts child node.

void
offsetSet($index, $child)

Inserts (replaces) child node (ArrayAccess implementation).

mixed
offsetGet($index)

Returns child node (ArrayAccess implementation).

bool
offsetExists($index)

Exists child node? (ArrayAccess implementation).

void
offsetUnset($index)

Removes child node (ArrayAccess implementation).

int
count()

Required by the Countable interface.

void
removeChildren()

Removed all children.

getIterator()

Required by the IteratorAggregate interface.

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.

int
getContentType()

No description

void
validateAttrs(array $dtd)

No description

validateChild($child, $dtd)

No description

void
parseLine(Texy $texy, $s)

Parses text as single line.

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

Parses text as block.

Details

at line 83
__construct($name = null, $attrs = null)

No description

Parameters

$name
$attrs

at line 94
static el($name = null, $attrs = null)

No description

Parameters

$name
$attrs

at line 107
final HtmlElement setName($name, $empty = null)

Changes element's name.

Parameters

$name
$empty

Return Value

HtmlElement

Exceptions

InvalidArgumentException

at line 123
final string getName()

Returns element's name.

Return Value

string

at line 133
final bool isEmpty()

Is element empty?

Return Value

bool

at line 145
final void __set($name, $value)

Overloaded setter for element's attribute.

Parameters

$name
$value

Return Value

void

at line 156
final mixed __get($name)

Overloaded getter for element's attribute.

Parameters

$name

Return Value

mixed

property value

at line 186
final HtmlElement href($path, $query = null)

Special setter for element's attribute.

Parameters

$path
$query

Return Value

HtmlElement

at line 204
final HtmlElement setText($text)

Sets element's textual content.

Parameters

$text

Return Value

HtmlElement

at line 220
final string getText()

Gets element's textual content.

Return Value

string

at line 238
final HtmlElement add($child)

Adds new element's child.

Parameters

$child

Return Value

HtmlElement

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

Creates and adds a new HtmlElement child.

Parameters

$name
$attrs

Return Value

HtmlElement

created element

at line 265
HtmlElement insert($index, $child, $replace = false)

Inserts child node.

Parameters

$index
$child
$replace

Return Value

HtmlElement

Exceptions

Exception

at line 289
final void offsetSet($index, $child)

Inserts (replaces) child node (ArrayAccess implementation).

Parameters

$index
$child

Return Value

void

at line 300
final mixed offsetGet($index)

Returns child node (ArrayAccess implementation).

Parameters

$index

Return Value

mixed

at line 311
final bool offsetExists($index)

Exists child node? (ArrayAccess implementation).

Parameters

$index

Return Value

bool

at line 322
void offsetUnset($index)

Removes child node (ArrayAccess implementation).

Parameters

$index

Return Value

void

at line 334
final int count()

Required by the Countable interface.

Return Value

int

at line 344
void removeChildren()

Removed all children.

Return Value

void

at line 354
final ArrayIterator getIterator()

Required by the IteratorAggregate interface.

Return Value

ArrayIterator

at line 364
final getChildren()

Returns all of children.

return array

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

Renders to final HTML.

Parameters

Texy $texy

Return Value

string

at line 412
final string toText(Texy $texy)

Renders to final text.

Parameters

Texy $texy

Return Value

string

at line 422
string startTag()

Returns element's start tag.

Return Value

string

at line 489
string endTag()

Returns element's end tag.

Return Value

string

at line 501
__clone()

Clones all children too.

at line 514
final int getContentType()

No description

Return Value

int

at line 527
final void validateAttrs(array $dtd)

No description

Parameters

array $dtd

Return Value

void

at line 542
validateChild($child, $dtd)

No description

Parameters

$child
$dtd

at line 561
final void parseLine(Texy $texy, $s)

Parses text as single line.

Parameters

Texy $texy
$s

Return Value

void

at line 576
final void parseBlock(Texy $texy, $s, $indented = false)

Parses text as block.

Parameters

Texy $texy
$s
$indented

Return Value

void

Traits

Better OOP experience.