Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
6562680 committed Aug 28, 2024
1 parent 0864922 commit cc9a2e7
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,16 @@ public function dispatch(
}

$dispatchHttpMethod = $contractHttpMethod;

if ($this->dispatchForceMethod) {
$dispatchHttpMethod = $this->dispatchForceMethod;
}

$indexMatch = null;
$routeNodeCurrent = $this->routerNodeRoot;

$middlewareIndex = [];
$fallbackIndex = [];

$routeNodeCurrent = $this->routerNodeRoot;

$indexMatch = null;
$pathCurrent = '';

$slice = $contractRequestUri;
Expand All @@ -525,45 +523,32 @@ public function dispatch(
while ( $slice ) {
$part = array_shift($slice);

if (isset($routeNodeCurrent->routeIndexByPart[ $part ])) {
$indexMatch = $routeNodeCurrent->routeIndexByPart[ $part ];

break;
}

if (isset($routeNodeCurrent->childrenByPart[ $part ])) {
$routeNodeCurrent = $routeNodeCurrent->childrenByPart[ $part ];

$pathCurrent .= '/' . $routeNodeCurrent->part;
$isRoute = empty($slice);

if (isset($this->middlewareCollection->middlewareIndexByPath[ $pathCurrent ])) {
$middlewareIndex += $this->middlewareCollection->middlewareIndexByPath[ $pathCurrent ];
}
if ($isRoute) {
if (isset($routeNodeCurrent->routeIndexByPart[ $part ])) {
$indexMatch = $routeNodeCurrent->routeIndexByPart[ $part ];

if (isset($this->fallbackCollection->fallbackIndexByPath[ $pathCurrent ])) {
$fallbackIndex += $this->fallbackCollection->fallbackIndexByPath[ $pathCurrent ];
break;
}

continue;
}

foreach ( $routeNodeCurrent->routeIndexByRegex ?? [] as $regex => $routeIndex ) {
if (preg_match('/^' . $regex . '$/', $part, $matches)) {
$indexMatch = $routeIndex;
foreach ( $routeNodeCurrent->routeIndexByRegex ?? [] as $regex => $routeIndex ) {
if (preg_match('/^' . $regex . '$/', $part, $matches)) {
$indexMatch = $routeIndex;

foreach ( $matches as $key => $value ) {
if (is_string($key)) {
$contractActionAttributes[ $key ] = $value;
foreach ( $matches as $key => $value ) {
if (is_string($key)) {
$contractActionAttributes[ $key ] = $value;
}
}
}

break 2;
break 2;
}
}
}

foreach ( $routeNodeCurrent->childrenByRegex ?? [] as $regex => $routeNode ) {
if (preg_match('/^' . $regex . '$/', $part, $matches)) {
$routeNodeCurrent = $routeNode;
} else {
if (isset($routeNodeCurrent->childrenByPart[ $part ])) {
$routeNodeCurrent = $routeNodeCurrent->childrenByPart[ $part ];

$pathCurrent .= '/' . $routeNodeCurrent->part;

Expand All @@ -575,13 +560,31 @@ public function dispatch(
$fallbackIndex += $this->fallbackCollection->fallbackIndexByPath[ $pathCurrent ];
}

foreach ( $matches as $key => $value ) {
if (is_string($key)) {
$contractActionAttributes[ $key ] = $value;
continue;
}

foreach ( $routeNodeCurrent->childrenByRegex ?? [] as $regex => $routeNode ) {
if (preg_match('/^' . $regex . '$/', $part, $matches)) {
$routeNodeCurrent = $routeNode;

$pathCurrent .= '/' . $routeNodeCurrent->part;

if (isset($this->middlewareCollection->middlewareIndexByPath[ $pathCurrent ])) {
$middlewareIndex += $this->middlewareCollection->middlewareIndexByPath[ $pathCurrent ];
}

if (isset($this->fallbackCollection->fallbackIndexByPath[ $pathCurrent ])) {
$fallbackIndex += $this->fallbackCollection->fallbackIndexByPath[ $pathCurrent ];
}
}

continue 2;
foreach ( $matches as $key => $value ) {
if (is_string($key)) {
$contractActionAttributes[ $key ] = $value;
}
}

continue 2;
}
}
}
}
Expand Down Expand Up @@ -1008,7 +1011,7 @@ protected function registerRouteGroup(RouteGroup $routeGroup) // : static
$this->registerRoute($route);
}

unset($this->routeGroupCurrent);
$this->routeGroupCurrent = null;

return $this;
}
Expand Down

0 comments on commit cc9a2e7

Please sign in to comment.