protected function _extractNamedParams($pattern)
{
if (!Text::contains($pattern, '{')) {
return $pattern;
}
$left_token = '@_@';
$right_token = '!_!';
$need_restore_token = false;
if (preg_match('#{\\d#', $pattern) === 1 && !Text::contains($pattern, $left_token) && !Text::contains($pattern, $right_token)) {
$need_restore_token = true;
$pattern = preg_replace('#{(\\d+,?\\d*)}#', $left_token . '\\1' . $right_token, $pattern);
}
$matches = [];
if (preg_match_all('#{([A-Z].*)}#Ui', $pattern, $matches, PREG_SET_ORDER) > 0) {
foreach ($matches as $match) {
if (!Text::contains($match[0], ':')) {
$to = '(?<' . $match[1] . '>[\\w-]+)';
$pattern = str_replace($match[0], $to, $pattern);
} else {
$parts = explode(':', $match[1]);
$to = '(?<' . $parts[0] . '>' . $parts[1] . ')';
$pattern = str_replace($match[0], $to, $pattern);
}
}
}
if ($need_restore_token) {
$from = [$left_token, $right_token];
$to = ['{', '}'];
$pattern = str_replace($from, $to, $pattern);
}
return $pattern;
}