Each handler now declares the data class it needs via dataClass(). The controller builds the appropriate typed DTO from the raw request array before calling handle(), giving handlers typed property access instead of raw array lookups. Handlers moved to App\Services\Micropub\Handlers, data objects to App\Services\Micropub\Data. MicropubHandlerRegistry and the interface are documented with flow diagrams and guidance for adding new types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Micropub\Data;
|
|
|
|
class CardData extends MicropubData
|
|
{
|
|
public function __construct(
|
|
public readonly array $tokenData,
|
|
public readonly ?string $name,
|
|
public readonly ?string $description,
|
|
public readonly mixed $geo,
|
|
public readonly mixed $location,
|
|
public readonly ?string $latitude,
|
|
public readonly ?string $longitude,
|
|
) {}
|
|
|
|
public static function fromArray(array $data): static
|
|
{
|
|
return new static(
|
|
tokenData: $data['token_data'],
|
|
name: $data['name'] ?? null,
|
|
description: $data['description'] ?? null,
|
|
geo: $data['geo'] ?? null,
|
|
location: $data['location'] ?? null,
|
|
latitude: $data['latitude'] ?? null,
|
|
longitude: $data['longitude'] ?? null,
|
|
);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'token_data' => $this->tokenData,
|
|
'name' => $this->name,
|
|
'description' => $this->description,
|
|
'geo' => $this->geo,
|
|
'location' => $this->location,
|
|
'latitude' => $this->latitude,
|
|
'longitude' => $this->longitude,
|
|
];
|
|
}
|
|
}
|