PHP Class 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.
Author: Roman Řáha
Author: Štěpán Svoboda
Datei anzeigen Open project: jyxo/php

Public Methods

Method Description
__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.

Private Methods

Method Description
__construct ( string $tag ) Constructor.
isRequiredAttr ( string $tag, string $attr ) : boolean Returns if the given attribute is mandatory.

Method Details

__call() public method

Sets or returns the attribute.
public __call ( string $method, array $args ) : mixed
$method string Method name
$args array Method attributes
return mixed string|Jyxo_HtmlTag

__get() public method

Returns an attribute value.
public __get ( string $name ) : mixed
$name string Attribute name
return mixed string|null

__toString() public method

Renders the HTML element.
public __toString ( ) : string
return string

addChild() public method

Adds a child element.
public addChild ( HtmlTag $element ) : self
$element HtmlTag Child element to be added
return self

addChildren() public method

Adds multiple child elements.
public addChildren ( array $elements ) : self
$elements array Array of child elements
return self

close() public method

Creates and returns the closing tag.
public close ( ) : string
return string

content() public method

Creates and returns element's contents.
public content ( ) : string
return string

create() public static method

Creates an element instance.
public static create ( string $tag ) : self
$tag string HTML element name
return self

createFromSource() public static method

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
return self

open() public method

Creates and returns the opening tag.
public open ( ) : string
return string

render() public method

Renders the element.
public render ( ) : string
return string

setAttributes() public method

Imports attributes from the given array.
public setAttributes ( array $attributes ) : self
$attributes array Associative array of attributes and their values
return self

setContentOnly() public method

Sets if only the contents should be rendered.
public setContentOnly ( boolean $contentOnly ) : selfs
$contentOnly boolean Should only the contents be rendered
return selfs

setNoEncode() public method

Sets an attribute to not be espaced on output.
public setNoEncode ( string $attribute ) : self
$attribute string Attribute name
return self