API / Minn\Runtime / TagEditor

TagEditor final class

Minn\Runtime\TagEditor · public/minn/src/Minn/Runtime/TagEditor.php · 152 lines

Edits one start tag's attributes in place the way the reference's tag processor does: a replaced value keeps its position, a new attribute goes right after the tag name (after any earlier insertion), and a removal takes only the attribute's own text.

Used by 1

Constants and properties

privatearray $attrs
privatestring $tag
privateint $insertAt

Public

new__construct(string $tag, array $attrs)#
$attrslist<array{name: string, value: ?string, start: int, end: int}>offsets relative to the tag
methodget(string $name): ?string#

An attribute's value, or null.

methodhas(string $name): bool#

Whether the tag has an attribute.

methodset(string $name, string|bool $value): void#

true sets a bare boolean attribute; a URL attribute (href, src, ...) keeps only a URL whose scheme is allowed, as the reference's set_attribute keeps it.

methodremove(string $name): void#

Removes an attribute.

methodaddClass(string $class): void#

Adds or removes a class.

methodremoveClass(string $class): void#

Removes a class, and the attribute when it was the last one.

methodsetStyle(string $property, ?string $value): void#

Sets or removes one inline style property.

methodhtml(): string#

The tag as edited.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateclasses(): array#
@return list<string>
privatesetClasses(array $classes): void#
$classeslist<string>
privatesplice(int $start, int $end, string $text): void#