class HtmlBuilder

Traits

Macroable

Properties

static protected array $components

The registered components.

from  Componentable
protected UrlGenerator $url

The URL generator instance.

protected Factory $view

The View Factory instance.

Methods

static void
component($name, $view, array $signature)

Register a custom component.

static bool
hasComponent($name)

Check if a component is registered.

HtmlString
renderComponent($name, array $arguments)

Render a custom component.

array
getComponentData(array $signature, array $arguments)

Prepare the component data, while respecting provided defaults.

View|mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

__construct(UrlGenerator $url = null, Factory $view)

Create a new HTML builder instance.

string
entities(string $value)

Convert an HTML string to entities.

string
decode(string $value)

Convert entities to HTML characters.

HtmlString
script(string $url, array $attributes = [], bool $secure = null)

Generate a link to a JavaScript file.

HtmlString
style(string $url, array $attributes = [], bool $secure = null)

Generate a link to a CSS file.

HtmlString
image(string $url, string $alt = null, array $attributes = [], bool $secure = null)

Generate an HTML image element.

HtmlString
favicon(string $url, array $attributes = [], bool $secure = null)

Generate a link to a Favicon file.

HtmlString
link(string $url, string $title = null, array $attributes = [], bool $secure = null, bool $escape = true)

Generate a HTML link.

HtmlString
secureLink(string $url, string $title = null, array $attributes = [])

Generate a HTTPS HTML link.

HtmlString
linkAsset(string $url, string $title = null, array $attributes = [], bool $secure = null)

Generate a HTML link to an asset.

HtmlString
linkSecureAsset(string $url, string $title = null, array $attributes = [])

Generate a HTTPS HTML link to an asset.

HtmlString
linkRoute(string $name, string $title = null, array $parameters = [], array $attributes = [])

Generate a HTML link to a named route.

HtmlString
linkAction(string $action, string $title = null, array $parameters = [], array $attributes = [])

Generate a HTML link to a controller action.

HtmlString
mailto(string $email, string $title = null, array $attributes = [], bool $escape = true)

Generate a HTML link to an email address.

string
email(string $email)

Obfuscate an e-mail address to prevent spam-bots from sniffing it.

string
nbsp(int $num = 1)

Generates non-breaking space entities based on number supplied.

HtmlString|string
ol(array $list, array $attributes = [])

Generate an ordered list of items.

HtmlString|string
ul(array $list, array $attributes = [])

Generate an un-ordered list of items.

HtmlString
dl(array $list, array $attributes = [])

Generate a description list of items.

HtmlString|string
listing(string $type, array $list, array $attributes = [])

Create a listing HTML element.

string
listingElement(mixed $key, string $type, mixed $value)

Create the HTML for a listing element.

string
nestedListing(mixed $key, string $type, mixed $value)

Create the HTML for a nested listing attribute.

string
attributes(array $attributes)

Build an HTML attribute string from an array.

string
attributeElement(string $key, string $value)

Build a single attribute element.

string
obfuscate(string $value)

Obfuscate a string to prevent spam-bots from sniffing it.

HtmlString
meta(string $name, string $content, array $attributes = [])

Generate a meta tag.

HtmlString
tag(string $tag, mixed $content, array $attributes = [])

Generate an html tag.

HtmlString
toHtmlString($html)

Transform the string to an Html serializable object

Details

in Componentable at line 26
static void component($name, $view, array $signature)

Register a custom component.

Parameters

$name
$view
array $signature

Return Value

void

in Componentable at line 38
static bool hasComponent($name)

Check if a component is registered.

Parameters

$name

Return Value

bool

in Componentable at line 51
protected HtmlString renderComponent($name, array $arguments)

Render a custom component.

Parameters

$name
array $arguments

Return Value

HtmlString

in Componentable at line 69
protected array getComponentData(array $signature, array $arguments)

Prepare the component data, while respecting provided defaults.

Parameters

array $signature
array $arguments

Return Value

array

at line 557
View|mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

View|mixed

Exceptions

BadMethodCallException

at line 38
__construct(UrlGenerator $url = null, Factory $view)

Create a new HTML builder instance.

Parameters

UrlGenerator $url
Factory $view

at line 51
string entities(string $value)

Convert an HTML string to entities.

Parameters

string $value

Return Value

string

at line 63
string decode(string $value)

Convert entities to HTML characters.

Parameters

string $value

Return Value

string

at line 77
HtmlString script(string $url, array $attributes = [], bool $secure = null)

Generate a link to a JavaScript file.

Parameters

string $url
array $attributes
bool $secure

Return Value

HtmlString

at line 93
HtmlString style(string $url, array $attributes = [], bool $secure = null)

Generate a link to a CSS file.

Parameters

string $url
array $attributes
bool $secure

Return Value

HtmlString

at line 114
HtmlString image(string $url, string $alt = null, array $attributes = [], bool $secure = null)

Generate an HTML image element.

Parameters

string $url
string $alt
array $attributes
bool $secure

Return Value

HtmlString

at line 131
HtmlString favicon(string $url, array $attributes = [], bool $secure = null)

Generate a link to a Favicon file.

Parameters

string $url
array $attributes
bool $secure

Return Value

HtmlString

Generate a HTML link.

Parameters

string $url
string $title
array $attributes
bool $secure
bool $escape

Return Value

HtmlString

Generate a HTTPS HTML link.

Parameters

string $url
string $title
array $attributes

Return Value

HtmlString

at line 192
HtmlString linkAsset(string $url, string $title = null, array $attributes = [], bool $secure = null)

Generate a HTML link to an asset.

Parameters

string $url
string $title
array $attributes
bool $secure

Return Value

HtmlString

at line 208
HtmlString linkSecureAsset(string $url, string $title = null, array $attributes = [])

Generate a HTTPS HTML link to an asset.

Parameters

string $url
string $title
array $attributes

Return Value

HtmlString

at line 223
HtmlString linkRoute(string $name, string $title = null, array $parameters = [], array $attributes = [])

Generate a HTML link to a named route.

Parameters

string $name
string $title
array $parameters
array $attributes

Return Value

HtmlString

at line 238
HtmlString linkAction(string $action, string $title = null, array $parameters = [], array $attributes = [])

Generate a HTML link to a controller action.

Parameters

string $action
string $title
array $parameters
array $attributes

Return Value

HtmlString

at line 253
HtmlString mailto(string $email, string $title = null, array $attributes = [], bool $escape = true)

Generate a HTML link to an email address.

Parameters

string $email
string $title
array $attributes
bool $escape

Return Value

HtmlString

at line 275
string email(string $email)

Obfuscate an e-mail address to prevent spam-bots from sniffing it.

Parameters

string $email

Return Value

string

at line 287
string nbsp(int $num = 1)

Generates non-breaking space entities based on number supplied.

Parameters

int $num

Return Value

string

at line 300
HtmlString|string ol(array $list, array $attributes = [])

Generate an ordered list of items.

Parameters

array $list
array $attributes

Return Value

HtmlString|string

at line 313
HtmlString|string ul(array $list, array $attributes = [])

Generate an un-ordered list of items.

Parameters

array $list
array $attributes

Return Value

HtmlString|string

at line 326
HtmlString dl(array $list, array $attributes = [])

Generate a description list of items.

Parameters

array $list
array $attributes

Return Value

HtmlString

at line 356
protected HtmlString|string listing(string $type, array $list, array $attributes = [])

Create a listing HTML element.

Parameters

string $type
array $list
array $attributes

Return Value

HtmlString|string

at line 385
protected string listingElement(mixed $key, string $type, mixed $value)

Create the HTML for a listing element.

Parameters

mixed $key
string $type
mixed $value

Return Value

string

at line 404
protected string nestedListing(mixed $key, string $type, mixed $value)

Create the HTML for a nested listing attribute.

Parameters

mixed $key
string $type
mixed $value

Return Value

string

at line 421
string attributes(array $attributes)

Build an HTML attribute string from an array.

Parameters

array $attributes

Return Value

string

at line 444
protected string attributeElement(string $key, string $value)

Build a single attribute element.

Parameters

string $key
string $value

Return Value

string

at line 472
string obfuscate(string $value)

Obfuscate a string to prevent spam-bots from sniffing it.

Parameters

string $value

Return Value

string

at line 510
HtmlString meta(string $name, string $content, array $attributes = [])

Generate a meta tag.

Parameters

string $name
string $content
array $attributes

Return Value

HtmlString

at line 528
HtmlString tag(string $tag, mixed $content, array $attributes = [])

Generate an html tag.

Parameters

string $tag
mixed $content
array $attributes

Return Value

HtmlString

at line 542
protected HtmlString toHtmlString($html)

Transform the string to an Html serializable object

Parameters

$html

Return Value

HtmlString