Download the PHP package hexmakina/marker without Composer
On this page you can find all versions of the php package hexmakina/marker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package marker
Marker
HTML generation classes for PHP.
Hommage to Christian François Bouche-Villeneuve aka Chris Marker.
Installation
All classes live in the HexMakina\Marker namespace:
Contents
Element— the core HTML builder.Marker— ergonomic shortcuts for<img>and<a>.Form— labelled form fields.- Accessibility helper — note on the removed
WCAGElement.
Class Element
Element builds a single HTML element. Its __toString() renders the tag, its
attributes, and its inner content. You can construct it directly or use the
static shorthand.
Static shorthand
Any undefined static call is treated as a tag name. The first argument is the inner content, the second the attributes array:
Escaped text versus trusted HTML
By default, inner content and attribute values are escaped with
htmlspecialchars(..., ENT_QUOTES). This is the safe default: any value coming
from user input is neutralised.
The escaping behaviour is controlled by the fourth constructor argument,
$formatter:
$formatter value |
Effect |
|---|---|
null (default) or omitted |
Escapes with htmlspecialchars(..., ENT_QUOTES). |
false |
Trusted mode: content and attributes are emitted verbatim. |
a callable |
Custom formatter applied to every value. |
Use false only when the content is already safe markup that you produced
yourself. This is what lets you nest elements:
⚠️ Nesting pitfall. If you concatenate a child element into a parent that uses the default (escaping) formatter, the child's tags are escaped:
To nest safely, pass
falseas the formatter on the parent (as above), so the parent trusts the already-escaped child. Do not usefalseon an element whose own content is untrusted user data.
Void elements
Void elements (area, base, br, col, embed, hr, img, input,
link, meta, param, source, track, wbr) are rendered without a
closing tag. Pass null as the content:
Any content passed to a void element is ignored — a void tag never has a body.
Boolean attributes
In the attributes array, an entry with an integer key (i.e. a bare value
with no =>) is rendered as a boolean attribute — just its name, no value.
String-keyed entries render as name="value".
Attribute and tag name validation
Tag and attribute names must match ^[a-zA-Z][a-zA-Z0-9-]*$. An invalid name
throws \InvalidArgumentException:
Attributes can also be read, set, checked, and removed as properties:
Class Marker
Marker extends Element with two shortcuts whose argument order reads more
naturally than the generic form.
Both accept an optional fourth $formatter argument with the same meaning as on
Element (null to escape, false to trust).
Class Form
Form builds form controls, each optionally paired with a <label>. Field
values and attributes are always escaped; only the assembled label+field
markup is treated as trusted so its own tags are not double-escaped.
Inputs
The id defaults to the field name. If there is no name/id, no empty id
attribute is emitted.
Any input type is available through the static shorthand — the method name
becomes the type:
A type you pass explicitly is respected — including on disabled fields:
Form labels
A label entry in the attributes array attaches a label. Two layouts:
Sibling label (default) — a <label for="id"> next to the field:
Wrapping label — set label-wrap to nest the field inside the <label>.
This is also used automatically when the field has no id to bind a sibling
label to:
The internal keys label, label-wrap, and tag are stripped before
rendering and never appear as HTML attributes.
Textarea and select
The selected option is matched by a strict comparison of the string forms of the selected value and each option key, so a numeric-string selected value still matches an integer array key without loose-typing surprises.
Buttons
Accessibility helper (removed)
Earlier versions shipped a WCAGElement class that enforced a handful of
accessibility rules (required alt on <img>/<area>, <figcaption> inside
<figure>, title on <iframe>, href on <a>, lang on <html>, and so
on). This class has been removed and is no longer part of the package.
tests/WCAGElementTest.php still references the removed class and will fail
until it is deleted or the class is deliberately reintroduced. Do not rely on
WCAGElement — it does not exist in src/.
