Move request parsing into DTOs via fromRequest(), expand update handler
Each DTO now owns its own parsing logic via fromRequest(), removing the normalization layer from MicropubRequest entirely. UpdateHandler gains delete support and allows replace/add/delete to compose in a single request rather than being mutually exclusive. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ad15b36f4d
commit
1137d2a07e
8 changed files with 310 additions and 124 deletions
|
|
@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Services\Micropub\Data;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CardData extends MicropubData
|
||||
{
|
||||
public function __construct(
|
||||
|
|
@ -16,6 +19,33 @@ class CardData extends MicropubData
|
|||
public readonly ?string $longitude,
|
||||
) {}
|
||||
|
||||
public static function fromRequest(Request $request): static
|
||||
{
|
||||
if ($request->isJson()) {
|
||||
$data = $request->json()->all();
|
||||
|
||||
return new static(
|
||||
tokenData: $data['token_data'],
|
||||
name: Arr::get($data, 'properties.name.0'),
|
||||
description: Arr::get($data, 'properties.description.0'),
|
||||
geo: Arr::get($data, 'properties.geo.0'),
|
||||
location: Arr::get($data, 'properties.location'),
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
);
|
||||
}
|
||||
|
||||
return new static(
|
||||
tokenData: $request->input('token_data'),
|
||||
name: $request->input('name'),
|
||||
description: $request->input('description'),
|
||||
geo: $request->input('geo'),
|
||||
location: $request->input('location'),
|
||||
latitude: $request->input('latitude'),
|
||||
longitude: $request->input('longitude'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromArray(array $data): static
|
||||
{
|
||||
return new static(
|
||||
|
|
|
|||
Loading…
Reference in a new issue