diff --git a/src/App.php b/src/App.php index 563d0a6d..c2048f93 100755 --- a/src/App.php +++ b/src/App.php @@ -476,7 +476,7 @@ public function match(Request $request, bool $fresh = false): ?Route * @param Route $route * @param Request $request */ - public function execute(Route $route, Request $request): static + public function execute(Route $route, Request $request, Response $response): static { $arguments = []; $groups = $route->getGroups(); @@ -501,10 +501,13 @@ public function execute(Route $route, Request $request): static } } - $arguments = $this->getArguments($route, $pathValues, $request->getParams()); + if (!($response->sent())) { + $arguments = $this->getArguments($route, $pathValues, $request->getParams()); + + // Call the action callback with the matched positions as params + \call_user_func_array($route->getAction(), $arguments); + } - // Call the action callback with the matched positions as params - \call_user_func_array($route->getAction(), $arguments); foreach ($groups as $group) { foreach (self::$shutdown as $hook) { // Group shutdown hooks @@ -627,7 +630,7 @@ public function run(Request $request, Response $response): static $response->disablePayload(); } - if(self::REQUEST_METHOD_OPTIONS == $method) { + if (self::REQUEST_METHOD_OPTIONS == $method) { try { foreach ($groups as $group) { foreach (self::$options as $option) { // Group options hooks @@ -667,7 +670,7 @@ public function run(Request $request, Response $response): static } if (null !== $route) { - return $this->execute($route, $request); + return $this->execute($route, $request, $response); } elseif (self::REQUEST_METHOD_OPTIONS == $method) { try { foreach ($groups as $group) { diff --git a/src/Response.php b/src/Response.php index 742efd3b..d3a908d6 100755 --- a/src/Response.php +++ b/src/Response.php @@ -279,6 +279,16 @@ public function getContentType(): string return $this->contentType; } + /** + * Get if response was already sent + * + * @return bool + */ + public function sent(): bool + { + return $this->sent; + } + /** * Set status code *