Skip to content

Commit

Permalink
Add base session state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 12, 2023
1 parent 1f1ce85 commit f301710
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/realtime-compiler/src/Http/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ abstract class BaseController
protected Request $request;
protected ConsoleOutput $console;
protected bool $withConsoleOutput = false;
protected bool $withSession = false;

protected static bool $sessionStarted = false;

abstract public function handle(): Response;

Expand All @@ -28,6 +31,19 @@ public function __construct(?Request $request = null)
if ($this->withConsoleOutput && ((bool) env('HYDE_SERVER_REQUEST_OUTPUT', false)) === true) {
$this->console = new ConsoleOutput();
}

if ($this->withSession && ! self::$sessionStarted) {
session_start();
self::$sessionStarted = true;
}
}

public function __destruct()
{
if ($this->withSession && self::$sessionStarted) {
session_write_close();
self::$sessionStarted = false;
}
}

protected function sendJsonErrorResponse(int $statusCode, string $message): JsonResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DashboardController extends BaseController
public string $title;

protected bool $withConsoleOutput = true;
protected bool $withSession = true;

protected JsonResponse $response;

Expand Down

0 comments on commit f301710

Please sign in to comment.