forked from laysense/laysite
27 lines
723 B
PHP
27 lines
723 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Content;
|
|
|
|
final class SystemPage
|
|
{
|
|
public const TYPES = ['maintenance' => '维护页', 'not-found' => '404 页'];
|
|
|
|
public static function slugMatches(string $type, mixed $slug): bool
|
|
{
|
|
return isset(self::TYPES[$type]) && is_string($slug)
|
|
&& preg_match('/^system--' . $type . '-[a-f0-9]{16}$/D', $slug) === 1;
|
|
}
|
|
|
|
public static function published(Repository $repo, string $type, mixed $slug): ?array
|
|
{
|
|
if (!self::slugMatches($type, $slug)) {
|
|
return null;
|
|
}
|
|
$page = $repo->page($slug);
|
|
|
|
return $page && $page['page_type'] === $type && $page['status'] === 'published' ? $page : null;
|
|
}
|
|
}
|