mirror of
https://gh.wpcy.net/https://github.com/fairpm/aspirecloud.git
synced 2026-06-20 02:22:28 +08:00
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Values\WpOrg\Themes;
|
|
|
|
use App\Utils\JSON;
|
|
use App\Values\DTO;
|
|
use Bag\Attributes\Transforms;
|
|
use Illuminate\Http\Request;
|
|
|
|
use function Safe\json_decode;
|
|
|
|
/**
|
|
* @phpstan-type TranslationMetadata array{
|
|
* POT-Creation-Date: string,
|
|
* PO-Revision-Date: string,
|
|
* Project-Id-Version: string,
|
|
* X-Generator: string
|
|
* }
|
|
*/
|
|
readonly class ThemeUpdateCheckRequest extends DTO
|
|
{
|
|
/**
|
|
* @param string $active slug of currently active theme
|
|
* @param array<string, array{Version: string, UpdateURI?: string}> $themes
|
|
* @param array<string, array<string, TranslationMetadata>> $translations
|
|
* @param list<string> $locale
|
|
*/
|
|
public function __construct(
|
|
public string $active,
|
|
public array $themes,
|
|
public array $translations,
|
|
public array $locale,
|
|
) {}
|
|
|
|
/** @return array<string, mixed> */
|
|
#[Transforms(Request::class)]
|
|
public static function fromRequest(Request $request): array
|
|
{
|
|
$decode = fn($key) => JSON::tryToAssoc($request->post($key) ?? '[]') ?? [];
|
|
$themes = $decode('themes');
|
|
return [
|
|
'active' => $themes['active'],
|
|
'themes' => $themes['themes'],
|
|
'locale' => $decode('locale'),
|
|
'translations' => $decode('translations'),
|
|
];
|
|
}
|
|
}
|