Skip to content

Commit

Permalink
Refactor console output dashboard hook to be non-static
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 11, 2023
1 parent 7655f00 commit 30fdc58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 6 additions & 10 deletions packages/realtime-compiler/src/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ";
Expand All @@ -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();
}
}
4 changes: 3 additions & 1 deletion packages/realtime-compiler/src/Http/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DashboardController
public string $title;

protected Request $request;
protected ConsoleOutput $console;
protected bool $isAsync = false;

protected array $flashes = [];
Expand All @@ -56,6 +57,7 @@ public function __construct()
{
$this->title = config('hyde.name').' - Dashboard';
$this->request = Request::capture();
$this->console = new ConsoleOutput();

$this->loadFlashData();

Expand Down Expand Up @@ -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'!");
Expand Down

0 comments on commit 30fdc58

Please sign in to comment.