October\Rain\Html\HtmlBuilder

Overview

HtmlBuilder builds HTML elements


Protected Properties

protected Illuminate\Routing\UrlGenerator $url

url generator instance.

protected static array $macros

The registered string macros.


Public Methods

public __call()

public __call(string $method, array $parameters): mixed 

Dynamically handle calls to the class.

public static __callStatic()

public static __callStatic(string $method, array $parameters): mixed 

Dynamically handle calls to the class.

public __construct()

public __construct(Illuminate\Routing\UrlGenerator $url = null): void 

__construct a new HTML builder instance.

public attributes()

public attributes(array $attributes): string 

Build an HTML attribute string from an array.

public static clean()

public static clean(string $html): string 

clean HTML to prevent most XSS attacks.

public static cleanVector()

public static cleanVector($html): string 

clean XML to prevent most XSS attacks in vector files (SVGs). Same as clean except:

  • allowed tags: xml, title, style
  • allowed attributes: xmlns, style

public decode()

public decode(string $value): string 

decode converts entities to HTML characters.

public email()

public email(string $email): string 

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

public entities()

public entities(string $value): string 

entities converts an HTML string to entities.

public static flushMacros()

public static flushMacros(): void 

Flush the existing macros.

public static hasMacro()

public static hasMacro(string $name): bool 

Checks if macro is registered.

public image()

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

image generates an HTML image element.

public isValidColor()

public isValidColor($value): bool 

isValidColor determines if a given string is a valid CSS color value

public static limit()

public static limit(
    string $html,
    int $maxLength = 100,
    string $end = '...'
): string 

limit HTML with specific length with a proper tag handling.

public link()

public link(
    string $url,
    string $title = null,
    array $attributes = [],
    bool $secure = null
): string 

link generates a HTML link.

public linkAction()

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

linkAction generates a HTML link to a controller action.

public linkAsset()

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

linkAsset generates a HTML link to an asset.

public linkRoute()

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

linkRoute generates a HTML link to a named route.

public linkSecureAsset()

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

linkSecureAsset generates a HTTPS HTML link to an asset.

public static macro()

public static macro(string $name, object|callable $macro): void 

Register a custom macro.

public mailto()

public mailto(
    string $email,
    string $title = null,
    array $attributes = []
): string 

mailto generates a HTML link to an email address.

public static minify()

public static minify($html): void

minify makes HTML more compact

public static mixin()

public static mixin(object $mixin, bool $replace = true): void 

Mix another object into the class.

public obfuscate()

public obfuscate(string $value): string 

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

public ol()

public ol(array $list, array $attributes = []): string 

ol generate an ordered list of items.

public script()

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

script generates a link to a JavaScript file.

public secureLink()

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

secureLink generates a HTTPS HTML link.

public static strip()

public static strip($string $string, $allow $allow = ''): string 

strip removes HTML from a string, with allowed tags, e.g.

public style()

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

style generates a link to a CSS file.

public ul()

public ul(array $list, array $attributes = []): string 

ul generates an un-ordered list of items.

Protected Methods

protected attributeElement()

protected attributeElement(string $key, string $value): string 

attributeElement builds a single attribute element.

protected listing()

protected listing(
    string $type,
    array $list,
    array $attributes = []
): string 

listing HTML element.

protected listingElement()

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

listingElement creates the HTML for a listing element.

protected nestedListing()

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

nestedListing creates the HTML for a nested listing attribute.