Files
laravel-manager-packagist/src/Support/Frontend.php
T
2026-12-04 16:52:00 +00:00

38 lines
1.5 KiB
PHP

<?php
namespace IriksIT\Manager\Support;
/**
* Who draws the pages of the site (config `manager.frontend.mode`, switchable on the settings screen):
*
* - `site`: the site draws them itself with its own routes and the blocks (Inertia + Vue or Blade). The package adds no public route. The default.
* - `package`: the package draws them: every page with blocks answers at `/{slug}` (the home page at `/`) in the Blade layout
* `manager.frontend.layout`, as long as no route of the site answers first (it is a fallback route).
* - `headless`: nothing is drawn here; the pages are JSON for a frontend elsewhere (the page API is on).
*
* The page API (`manager.blocks.api.enabled`) and the live preview (`manager.blocks.preview.enabled`) are switches of their own; `headless` implies the API.
*/
final class Frontend
{
public const MODES = ['site', 'package', 'headless'];
public static function mode(): string
{
$mode = config('manager.frontend.mode', 'site');
return is_string($mode) && in_array($mode, self::MODES, true) ? $mode : 'site';
}
/** Whether the package draws the public pages. */
public static function renders(): bool
{
return self::mode() === 'package';
}
/** Whether the pages go out as JSON: the headless mode, or the switch of the API on its own. */
public static function api(): bool
{
return self::mode() === 'headless' || (bool) config('manager.blocks.api.enabled', false);
}
}