Skip to content

Commit

Permalink
fix RouteGroup register methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BMTmohammedtaha committed Aug 21, 2023
1 parent eed1287 commit edf7ba1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function routeId($method, $pattern)
* @param string $route The route to correct.
* @return string The corrected route.
*/
private function correctRoute(string $route): string
public function correctRoute(string $route): string
{
return $route = str_replace(['//', '\\', '///'], '/', $route);
}
Expand Down
21 changes: 14 additions & 7 deletions src/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(
*/
public function get(string $pattern, string $method): void
{
$this->router->get($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->get($newPattern, [$this->controller, $method]);
}

/**
Expand All @@ -45,7 +46,8 @@ public function get(string $pattern, string $method): void
*/
public function post(string $pattern, string $method): void
{
$this->router->post($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->post($newPattern, [$this->controller, $method]);
}

/**
Expand All @@ -57,7 +59,8 @@ public function post(string $pattern, string $method): void
*/
public function put(string $pattern, string $method): void
{
$this->router->put($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->put($newPattern, [$this->controller, $method]);
}

/**
Expand All @@ -69,7 +72,8 @@ public function put(string $pattern, string $method): void
*/
public function delete(string $pattern, string $method): void
{
$this->router->delete($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->delete($newPattern, [$this->controller, $method]);
}

/**
Expand All @@ -81,7 +85,8 @@ public function delete(string $pattern, string $method): void
*/
public function patch(string $pattern, string $method): void
{
$this->router->patch($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->patch($newPattern, [$this->controller, $method]);
}

/**
Expand All @@ -93,7 +98,8 @@ public function patch(string $pattern, string $method): void
*/
public function options(string $pattern, string $method): void
{
$this->router->options($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->options($newPattern, [$this->controller, $method]);
}

/**
Expand All @@ -105,6 +111,7 @@ public function options(string $pattern, string $method): void
*/
public function any(string $pattern, string $method): void
{
$this->router->any($this->prePath . $pattern, [$this->controller, $method]);
$newPattern = $this->router->correctRoute($this->prePath . $pattern);
$this->router->any($newPattern, [$this->controller, $method]);
}
}

0 comments on commit edf7ba1

Please sign in to comment.