feat: GlobalMenu API

- GlobalMenu 작성용 DTO(MenuItem, MenuMulti, MenuSplit)
- d_setting에 GlobalMenu를 직접 작성 가능하도록 제공
This commit is contained in:
2023-03-09 02:20:18 +09:00
parent a2b800b2ef
commit 72657692ee
8 changed files with 246 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace sammo\API\Global;
use LDTO\DTO;
use sammo\APICacheResult;
use sammo\BaseAPI;
use sammo\GlobalMenu;
use sammo\Session;
class GetGlobalMenu extends BaseAPI
{
public function getRequiredSessionMode(): int
{
return self::NO_SESSION;
}
function validateArgs(): ?string
{
return null;
}
function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
{
if ($reqEtag !== null) {
$version = GlobalMenu::version;
if ($reqEtag == "v{$version}") {
return null;
}
}
return [
'result' => true,
'menu' => array_map(function (DTO $dto) {
return $dto->toArray();
}, GlobalMenu::getMenu()),
];
}
public function tryCache(): ?APICacheResult
{
$version = GlobalMenu::version;
return new APICacheResult(
null,
"v{$version}",
60 * 60 * 6,
true
);
}
}