2025-04-27 16:38:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-02-22 10:41:33 +00:00
|
|
|
namespace App\Services\Micropub\Handlers;
|
2025-04-27 16:38:25 +01:00
|
|
|
|
|
|
|
|
use App\Exceptions\InvalidTokenScopeException;
|
2026-02-22 10:41:33 +00:00
|
|
|
use App\Services\Micropub\Data\CardData;
|
|
|
|
|
use App\Services\Micropub\Data\MicropubData;
|
2025-04-27 16:38:25 +01:00
|
|
|
use App\Services\PlaceService;
|
|
|
|
|
|
|
|
|
|
class CardHandler implements MicropubHandlerInterface
|
|
|
|
|
{
|
2026-02-22 10:41:33 +00:00
|
|
|
public function dataClass(): string
|
|
|
|
|
{
|
|
|
|
|
return CardData::class;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-27 16:38:25 +01:00
|
|
|
/**
|
|
|
|
|
* @throws InvalidTokenScopeException
|
|
|
|
|
*/
|
2026-02-22 10:41:33 +00:00
|
|
|
public function handle(MicropubData $data): array
|
2025-04-27 16:38:25 +01:00
|
|
|
{
|
2026-02-22 10:41:33 +00:00
|
|
|
assert($data instanceof CardData);
|
|
|
|
|
|
|
|
|
|
$scopes = $data->tokenData['scope'];
|
2025-04-27 16:38:25 +01:00
|
|
|
if (is_string($scopes)) {
|
|
|
|
|
$scopes = explode(' ', $scopes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! in_array('create', $scopes, true)) {
|
|
|
|
|
throw new InvalidTokenScopeException;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 10:41:33 +00:00
|
|
|
$location = resolve(PlaceService::class)->createPlace($data->toArray())->uri;
|
2025-04-27 16:38:25 +01:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'response' => 'created',
|
|
|
|
|
'url' => $location,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|