diff --git a/packages/realtime-compiler/src/ConsoleOutput.php b/packages/realtime-compiler/src/ConsoleOutput.php index 0dd3ac4d208..4deb9a5a88c 100644 --- a/packages/realtime-compiler/src/ConsoleOutput.php +++ b/packages/realtime-compiler/src/ConsoleOutput.php @@ -14,12 +14,13 @@ class ConsoleOutput { - protected static SymfonyOutput $output; + protected SymfonyOutput $output; protected bool $verbose; - public function __construct(bool $verbose = false) + public function __construct(bool $verbose = false, ?SymfonyOutput $output = null) { $this->verbose = $verbose; + $this->output = $output ?? new SymfonyOutput(); } public function printStartMessage(string $host, int $port): void @@ -58,9 +59,9 @@ public function getFormatter(): Closure } /** @experimental */ - public static function printMessage(string $message, string $context): void + public function printMessage(string $message, string $context): void { - static::getConsoleOutput()->writeln(sprintf('%s [%s]', $message, $context)); + $this->output->writeln(sprintf('%s [%s]', $message, $context)); } protected function handleOutput(string $buffer): void @@ -126,7 +127,7 @@ protected function formatRequestStatusLine(string $line): string return $this->formatLine(sprintf('%s %s', $address, $status), $this->parseDate($line)); } - protected static function formatLine(string $message, Carbon $date, string $iconColor = 'blue-500', string $context = ''): string + protected function formatLine(string $message, Carbon $date, string $iconColor = 'blue-500', string $context = ''): string { if ($context) { $context = "$context "; @@ -149,9 +150,4 @@ protected function parseDate(string $line): Carbon { return Carbon::parse(Str::betweenFirst($line, '[', ']')); } - - protected static function getConsoleOutput(): SymfonyOutput - { - return static::$output ??= new SymfonyOutput(); - } } diff --git a/packages/realtime-compiler/src/Http/DashboardController.php b/packages/realtime-compiler/src/Http/DashboardController.php index 6af6559679f..ff5c44bcc86 100644 --- a/packages/realtime-compiler/src/Http/DashboardController.php +++ b/packages/realtime-compiler/src/Http/DashboardController.php @@ -38,6 +38,7 @@ class DashboardController public string $title; protected Request $request; + protected ConsoleOutput $console; protected bool $isAsync = false; protected array $flashes = []; @@ -56,6 +57,7 @@ public function __construct() { $this->title = config('hyde.name').' - Dashboard'; $this->request = Request::capture(); + $this->console = new ConsoleOutput(); $this->loadFlashData(); @@ -354,7 +356,7 @@ protected function createPage(): void $this->abort($exception->getCode(), $exception->getMessage()); } - ConsoleOutput::printMessage("Created file '$path'", 'dashboard@createPage'); + $this->console->printMessage("Created file '$path'", 'dashboard@createPage'); $this->flash('justCreatedPage', RouteKey::fromPage($pageClass, $pageClass::pathToIdentifier($path))->get()); $this->setJsonResponse(201, "Created file '$path'!");