/** * @param Route $route * @param array $data * * @return string */ private function routeRegexp(Route $route, array $data = null) : string { $regexp = $route->getMatch(); // AbstractApp::logger()->debug($regexp); preg_match_all('`\\{\\{(.+)\\}\\}`U', $regexp, $matches); if (sizeof($matches[1]) == 0) { return $regexp; } foreach ($matches[1] as $var) { $replace = '{{' . $var . '}}'; $explode = explode(':', $var); $type = array_shift($explode); $value = implode(':', $explode); unset($dest); switch ($type) { case 'T': $dest = $this->routeRegexpTranslatedText($route, $value, $data); break; case 'L': $dest = $this->routeRegexpLocales($data); break; case 'C': // mandatory capture variable with optionnal regexp // mandatory capture variable with optionnal regexp case 'O': // optionnal capture variable with optionnal regexp // optionnal capture variable with optionnal regexp case 'S': // uncapture text with optionnal regexp $dest = $this->routeRegexpCapture($type, $route, $value, $data); break; default: throw new \InvalidArgumentException(sprintf("Invalid route variable '%s' on route '%s'", $type, $route->getName())); } $regexp = str_replace($replace, isset($dest) ? $dest : '', $regexp); } return $regexp; }