API / Minn\Content / Clickable

Clickable final class

Minn\Content\Clickable · public/minn/src/Minn/Content/Clickable.php · 64 lines

Bare addresses in text made links (make_clickable, probe formatting-callbacks). Only text is read, never tags or comments, and nothing inside code, pre, script or style. An address must start the text or follow whitespace or "("; trailing . , ; : ! ? stay outside it. URLs (http, https, ftp) are found first, then www. and ftp. hosts, then email addresses; each is handed to its callback, which builds the link. A link made as the whole text of an existing link is unwrapped into it.

Uses 1

Constants and properties

privateSKIP = 'code|pre|script|style'
privateBEFORE = '(^|[\\s(])'
privateTRAILING = '([.,;:!?]*)(?=[\\s<>"]|$)'

Public

staticmake(string $text, Closure $url, Closure $web, Closure $email): string#

The text with its addresses made links: $url gets [whole, before, address, trailing], $web the same for a www. or ftp. host, $email [whole, before, user, domain].

$urlClosure(list<string>): string
$webClosure(list<string>): string
$emailClosure(list<string>): string
staticunbalancedClosers(string $url): array#

A URL's trailing ")" taken off while the URL closes more parentheses than it opens: [the URL, what was taken off].

@return array{0: string, 1: string}

Internals 2

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

privatelinked(string $text, Closure $url, Closure $web, Closure $email): string#
privateunwrapNested(string $html): string#

A link that is the whole text of another link gives the outer one its text.