mirror of
https://gh.wpcy.net/https://github.com/aspirepress/AspireCloud.git
synced 2026-07-16 11:26:56 +08:00
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Values\WpOrg\Plugins;
|
|
|
|
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 PluginUpdateCheckRequest extends DTO
|
|
{
|
|
/**
|
|
* @param array<string, array{"Version": string}> $plugins
|
|
* @param array<string, array<string, TranslationMetadata>> $translations
|
|
* @param list<string> $locale
|
|
*/
|
|
public function __construct(
|
|
public array $plugins,
|
|
public array $translations,
|
|
public array $locale,
|
|
public bool $all = false,
|
|
) {}
|
|
|
|
/** @return array<string, mixed> */
|
|
#[Transforms(Request::class)]
|
|
public static function fromRequest(Request $request): array
|
|
{
|
|
$decode = fn($key) => JSON::tryToAssoc($request->post($key) ?? '[]') ?? [];
|
|
return [
|
|
'plugins' => $decode('plugins')['plugins'],
|
|
'locale' => $decode('locale'),
|
|
'translations' => $decode('translations'),
|
|
'all' => $request->boolean('all'),
|
|
];
|
|
}
|
|
}
|