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
Afficher le fichier Open project: jyxo/php

Méthodes publiques

Méthode 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

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

Method Details

__call() public méthode

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

__get() public méthode

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

__toString() public méthode

Renders the HTML element.
public __toString ( ) : string
Résultat string

addChild() public méthode

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

addChildren() public méthode

Adds multiple child elements.
public addChildren ( array $elements ) : self
$elements array Array of child elements
Résultat self

close() public méthode

Creates and returns the closing tag.
public close ( ) : string
Résultat string

content() public méthode

Creates and returns element's contents.
public content ( ) : string
Résultat string

create() public static méthode

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

createFromSource() public static méthode

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
Résultat self

open() public méthode

Creates and returns the opening tag.
public open ( ) : string
Résultat string

render() public méthode

Renders the element.
public render ( ) : string
Résultat string

setAttributes() public méthode

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

setContentOnly() public méthode

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

setNoEncode() public méthode

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