Skip to content
Permalink
Browse files Browse the repository at this point in the history
Stop execution of code after redirecting
  • Loading branch information
aheinze committed Aug 7, 2022
1 parent 545e36a commit dd8d031
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
- Add GraphQL mutation saveContentItem to create|update content items
- Add GraphQL mutation deleteContentItem to delete content items
- Add app side panel (admin layout)
- Stop execution of code after redirecting

## 2.1.2 (2022-08-04)

Expand Down
18 changes: 18 additions & 0 deletions lib/Lime/App.php
Expand Up @@ -234,6 +234,11 @@ public function stop(mixed $data = null, ?int $status = null): void {
}

$this->request->stopped = true;

$this->trigger('app:request:stop');
$this->trigger('after', [true]);

exit;
}

/**
Expand Down Expand Up @@ -856,6 +861,19 @@ public function run(?string $route = null, ?Request $request = null, bool $flush
$this->response = new Response();
$this->trigger('before');

if ($flush) {

$this->on('app:request:stop', function() {

if ($this->response->status === 307 && isset($this->response->headers['Location'])) {
\header("Location: {$this->response->headers['Location']}");
exit;
}

$this->response->flush();
});
}

if (!$this->request->stopped) {

$contents = $this->dispatch($route);
Expand Down

0 comments on commit dd8d031

Please sign in to comment.