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>
42 lines
983 B
PHP
42 lines
983 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Micropub\Handlers;
|
|
|
|
use App\Exceptions\InvalidTokenScopeException;
|
|
use App\Services\Micropub\Data\CardData;
|
|
use App\Services\Micropub\Data\MicropubData;
|
|
use App\Services\PlaceService;
|
|
|
|
class CardHandler implements MicropubHandlerInterface
|
|
{
|
|
public function dataClass(): string
|
|
{
|
|
return CardData::class;
|
|
}
|
|
|
|
/**
|
|
* @throws InvalidTokenScopeException
|
|
*/
|
|
public function handle(MicropubData $data): array
|
|
{
|
|
assert($data instanceof CardData);
|
|
|
|
$scopes = $data->tokenData['scope'];
|
|
if (is_string($scopes)) {
|
|
$scopes = explode(' ', $scopes);
|
|
}
|
|
|
|
if (! in_array('create', $scopes, true)) {
|
|
throw new InvalidTokenScopeException;
|
|
}
|
|
|
|
$location = resolve(PlaceService::class)->createPlace($data->toArray())->uri;
|
|
|
|
return [
|
|
'response' => 'created',
|
|
'url' => $location,
|
|
];
|
|
}
|
|
}
|