47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Tenants;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
enum TenantPageCategory: string
|
|
{
|
|
case WorkspaceScoped = 'workspace_scoped';
|
|
case TenantBound = 'tenant_bound';
|
|
case OnboardingWorkflow = 'onboarding_workflow';
|
|
case CanonicalWorkspaceRecordViewer = 'canonical_workspace_record_viewer';
|
|
|
|
public static function fromRequest(?Request $request = null): self
|
|
{
|
|
if (! $request instanceof Request) {
|
|
return self::WorkspaceScoped;
|
|
}
|
|
|
|
return self::fromPath('/'.ltrim($request->path(), '/'));
|
|
}
|
|
|
|
public static function fromPath(string $path): self
|
|
{
|
|
$normalizedPath = '/'.ltrim($path, '/');
|
|
|
|
if (preg_match('#^/admin/operations/[^/]+$#', $normalizedPath) === 1) {
|
|
return self::CanonicalWorkspaceRecordViewer;
|
|
}
|
|
|
|
if (preg_match('#^/admin/onboarding(?:/[^/]+)?$#', $normalizedPath) === 1) {
|
|
return self::OnboardingWorkflow;
|
|
}
|
|
|
|
if (
|
|
preg_match('#^/admin/t/[^/]+(?:/|$)#', $normalizedPath) === 1
|
|
|| preg_match('#^/admin/tenants/[^/]+(?:/|$)#', $normalizedPath) === 1
|
|
) {
|
|
return self::TenantBound;
|
|
}
|
|
|
|
return self::WorkspaceScoped;
|
|
}
|
|
}
|