35 lines
678 B
PHP
35 lines
678 B
PHP
<?php
|
|
|
|
namespace App\Domains\Workspace\Services;
|
|
|
|
use App\Domains\Workspace\Models\Workspace;
|
|
|
|
class CurrentWorkspace
|
|
{
|
|
private ?Workspace $workspace = null;
|
|
|
|
public function set(Workspace $workspace): void
|
|
{
|
|
$this->workspace = $workspace;
|
|
}
|
|
|
|
public function get(): ?Workspace
|
|
{
|
|
return $this->workspace;
|
|
}
|
|
|
|
public function require(): Workspace
|
|
{
|
|
if (! $this->workspace) {
|
|
throw new \RuntimeException('No current workspace set. Route missing workspace.resolve middleware?');
|
|
}
|
|
|
|
return $this->workspace;
|
|
}
|
|
|
|
public function clear(): void
|
|
{
|
|
$this->workspace = null;
|
|
}
|
|
}
|