Edits final class
Minn\Html\Edits · public/minn/src/Minn/Html/Edits.php · 336 lines
The edits pending on the current token: attribute sets and removals, class additions and removals, and a text replacement, in call order. They answer reads before they are written, and become the source replacements the reader splices in when it moves on.
Constants and properties
| private | array $attributes | |
| private | array $classes | |
| private | ?string $text |
Public
| static | validName(string $name): bool# | Whether an attribute name may be set at all, by the reference's rules. | ||||||
| method | setAttribute(string $name, string|true $value): void# | Records a set; setting class outright forgets the class edits before it. | ||||||
| method | setEscapedAttribute(string $name, string $escaped): void# | Records an attribute value that comes already escaped (a URL through esc_url), written as it is. | ||||||
| method | removeAttribute(string $name): void# | Records a removal of an attribute the source has. | ||||||
| method | cancelAttribute(string $name): void# | Forgets a pending set that never reached the source: cancelling an addition is not a removal. | ||||||
| method | attribute(string $lower): ?array# | The pending set or removal for a lowercase name, or null when there is none. @return array{name: string, value: string|true|null}|null @return array{name: string, value: string|true|null}|null | ||||||
| method | addClass(string $class): void# | Records a class to add; a later removal of the same class wins. | ||||||
| method | removeClass(string $class): void# | Records a class to remove; a later addition of the same class wins. | ||||||
| method | hasClassEdits(): bool# | Whether any class edit is pending. | ||||||
| method | hasTagEdits(): bool# | Whether any attribute or class edit is pending. | ||||||
| method | classesAfter(array $base): array# | The class list after the pending edits: additions appended once, removals gone.
@return list<string> | ||||||
| static | closesComment(string $text): bool# | Whether text holds a comment closer, "-->" or "--!>". | ||||||
| method | setTextFor(?string $type, ?string $tagName, ?string $commentType, string $text): bool# | Records a text replacement for a token of a kind that takes one: text (escaped), an ordinary HTML comment, or a raw-text element's body (script and style bodies get their closers escaped). False when the kind takes none, or the text would end the element early.
| ||||||
| method | takeText(): ?string# | The pending text replacement, taken: it is cleared on read. | ||||||
| method | takeReplacements(array $attributes, int $nameEnd, ?string $baseClassValue): array# | The source replacements the attribute and class edits amount to, and forgets them: a changed attribute is rewritten in place (its duplicates removed), a removed one is cut, a new one is inserted after the tag name (several in the order of their text).
@return list<array{int, int, string}> start, end, text | ||||||
| method | clear(): void# | Forgets everything pending. | ||||||
| static | splice(string $html, array $replacements, array $bookmarks, int $tokenStart, int $tokenEnd): array# | Splices replacements into the source, ascending, and moves the bookmarks and the cursor by what the token at [$tokenStart, $tokenEnd] gained or lost.
@return array{0: string, 1: array<string, array{0: int, 1: int}>, 2: int} the source, the bookmarks, the cursor | ||||||
| static | classValue(?array $pending, array $attributes): ?string# | The class attribute's decoded value before class edits: a pending set, else the source's; null when there is none.
| ||||||
| static | classList(?array $pending, array $attributes): array# | The class names before class edits.
@return list<string> |
Internals 3
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | rebuiltClassValue(string $base): string# | The class attribute after edits: source order and inner whitespace kept, removed classes gone with the space before them, additions appended. | |||
| private | existingName(array $attributes, string $lower): ?string# |
| |||
| private | escape(string $value): string# |
Nothing matches.