Download the PHP package jtolj/html-attributes without Composer
On this page you can find all versions of the php package jtolj/html-attributes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jtolj/html-attributes
More information about jtolj/html-attributes
Files in jtolj/html-attributes
Package html-attributes
Short Description A Fluent Interface for Handling HTML Attributes in PHP.
License MIT
Homepage https://github.com/jtolj/html-attributes
Informations about the package html-attributes
This project has been archived. If you are using Laravel, see Illuminate\View\ComponentAttributeBag.
A Fluent Interface for Handling HTML Attributes in PHP
The package provides a simple class, inspired by Drupal's Drupal\Core\Template\Attribute, to help manage HTML attributes in a structured way.
I use it primarily in Laravel, so the pseudocode examples below use Laravel conventions. The package, however, is not specific to Laravel and can be used without it.
Examples
In a Controller
Output
Using the example Trait with a Eloquent model and Blade template:
Output
Escaping and Filtering
Escaping of attribute names and values is done using the laminas/laminas-escaper package. Attribute keys are escaped using the escapeHtmlAttr() method. As of 2.0, attribute values are escaped using the escapeHtml() method.
Additionally, by default attribute names starting with 'on' (javascript event handlers) are not output.
You can set your own list of stripped prefixes with the setUnsafePrefixes(array $prefixes)
method. Attribute names beginning with those prefixes are stripped on output.
You can also turn this behavior off by calling allowUnsafe()
. This will not filter the list of attribute names before output and will output the value of 'unsafe' attributes fully unescaped (as of 2.0). Be extremely careful with this behavior to prevent XSS.