Skip to content

Commit

Permalink
Fix router execution action
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Aug 6, 2023
1 parent 1c8ed95 commit ae9c22f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit ae9c22f

Please sign in to comment.