PHP Класс Jyxo\HtmlTag

Allows creating HTML tags and its attributes. Example: $p = \Jyxo\HtmlTag::create('p')->setClass('buttons'); The magic __call() method ensures attributes settings. $p->render(); The render() method creates the HTML output.
Автор: Roman Řáha
Автор: Štěpán Svoboda
Показать файл Открыть проект

Открытые методы

Метод Описание
__call ( string $method, array $args ) : mixed Sets or returns the attribute.
__get ( string $name ) : mixed Returns an attribute value.
__toString ( ) : string Renders the HTML element.
addChild ( HtmlTag $element ) : self Adds a child element.
addChildren ( array $elements ) : self Adds multiple child elements.
close ( ) : string Creates and returns the closing tag.
content ( ) : string Creates and returns element's contents.
create ( string $tag ) : self Creates an element instance.
createFromSource ( string $html ) : self Returns an element instance from the given source.
open ( ) : string Creates and returns the opening tag.
render ( ) : string Renders the element.
setAttributes ( array $attributes ) : self Imports attributes from the given array.
setContentOnly ( boolean $contentOnly ) : selfs Sets if only the contents should be rendered.
setNoEncode ( string $attribute ) : self Sets an attribute to not be espaced on output.

Приватные методы

Метод Описание
__construct ( string $tag ) Constructor.
isRequiredAttr ( string $tag, string $attr ) : boolean Returns if the given attribute is mandatory.

Описание методов

__call() публичный Метод

Sets or returns the attribute.
public __call ( string $method, array $args ) : mixed
$method string Method name
$args array Method attributes
Результат mixed string|Jyxo_HtmlTag

__get() публичный Метод

Returns an attribute value.
public __get ( string $name ) : mixed
$name string Attribute name
Результат mixed string|null

__toString() публичный Метод

Renders the HTML element.
public __toString ( ) : string
Результат string

addChild() публичный Метод

Adds a child element.
public addChild ( HtmlTag $element ) : self
$element HtmlTag Child element to be added
Результат self

addChildren() публичный Метод

Adds multiple child elements.
public addChildren ( array $elements ) : self
$elements array Array of child elements
Результат self

close() публичный Метод

Creates and returns the closing tag.
public close ( ) : string
Результат string

content() публичный Метод

Creates and returns element's contents.
public content ( ) : string
Результат string

create() публичный статический Метод

Creates an element instance.
public static create ( string $tag ) : self
$tag string HTML element name
Результат self

createFromSource() публичный статический Метод

The first and last tag will be used as the opening and closing tag respectively. Anything between those tags will be used as contents.
public static createFromSource ( string $html ) : self
$html string HTML source code
Результат self

open() публичный Метод

Creates and returns the opening tag.
public open ( ) : string
Результат string

render() публичный Метод

Renders the element.
public render ( ) : string
Результат string

setAttributes() публичный Метод

Imports attributes from the given array.
public setAttributes ( array $attributes ) : self
$attributes array Associative array of attributes and their values
Результат self

setContentOnly() публичный Метод

Sets if only the contents should be rendered.
public setContentOnly ( boolean $contentOnly ) : selfs
$contentOnly boolean Should only the contents be rendered
Результат selfs

setNoEncode() публичный Метод

Sets an attribute to not be espaced on output.
public setNoEncode ( string $attribute ) : self
$attribute string Attribute name
Результат self