17 \s* ([
a-zA-Z_][
a-zA-Z0-9_-]*) \
s*
19 : \
s* ([^{}]*(?:\{(?-1)\}[^{}]*)*)
27 $routeWithoutClosingOptionals = rtrim($route,
']');
28 $numOptionals = strlen($route) - strlen($routeWithoutClosingOptionals);
31 $segments = preg_split(
'~' . self::VARIABLE_REGEX .
'(*SKIP)(*F) | \[~x', $routeWithoutClosingOptionals);
32 if ($numOptionals !== count($segments) - 1) {
34 if (preg_match(
'~' . self::VARIABLE_REGEX .
'(*SKIP)(*F) | \]~x', $routeWithoutClosingOptionals)) {
35 throw new BadRouteException(
'Optional segments can only occur at the end of a route');
37 throw new BadRouteException(
"Number of opening '[' and closing ']' does not match");
42 foreach ($segments as
$n => $segment) {
43 if ($segment ===
'' &&
$n !== 0) {
47 $currentRoute .= $segment;
62 '~' . self::VARIABLE_REGEX .
'~x', $route, $matches,
63 PREG_OFFSET_CAPTURE | PREG_SET_ORDER
70 foreach ($matches as $set) {
71 if ($set[0][1] > $offset) {
72 $routeData[] = substr($route, $offset, $set[0][1] - $offset);
76 isset($set[2]) ? trim($set[2][0]) : self::DEFAULT_DISPATCH_REGEX
78 $offset = $set[0][1] + strlen($set[0][0]);
81 if ($offset !== strlen($route)) {
82 $routeData[] = substr($route, $offset);
const DEFAULT_DISPATCH_REGEX
Parses route strings of the following form:
parsePlaceholders($route)
Parses a route string that does not contain optional segments.
parse($route)
Parses a route string into multiple route data arrays.