matcher = MatcherFactory::createMatcher($validator, $encoder); $this->replacer = ReplacerFactory::createReplacer($this->matcher); $this->highlighter = $highlighter ?? new HtmlHighlighter('http'); } /** * Check if string is valid url. * If encoder provided - string will be decoded, than check performed. * * @param string $string * @return bool */ public function isUrl(string $string): bool { return $this->matcher->match($string) !== null; } /** * Parse string and return array of urls found. * If encoder provided - will return decoded urls. * * @param string $string * @return array|string[] */ public function getUrls(string $string): array { $result = []; $matches = $this->matcher->matchAll($string); foreach ($matches as $match) { $result[] = $match->getUrl(); } return $result; } /** * Parse string and replace urls with highlighted links * e.g. http://example.com -> http://example.com * * @param string $string * @return string */ public function highlightUrls(string $string): string { return $this->highlighter->highlight($string, $this->replacer); } }