Introduce typed DTOs and sub-namespaces for Micropub handlers
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>
This commit is contained in:
parent
24cb6d61aa
commit
ad15b36f4d
12 changed files with 282 additions and 36 deletions
|
|
@ -5,7 +5,27 @@ declare(strict_types=1);
|
|||
namespace App\Services\Micropub;
|
||||
|
||||
use App\Exceptions\MicropubHandlerException;
|
||||
use App\Services\Micropub\Handlers\MicropubHandlerInterface;
|
||||
|
||||
/**
|
||||
* Maps Micropub post types to their handler instances.
|
||||
*
|
||||
* MicropubRequest normalises every incoming request and resolves it to a type
|
||||
* string ("entry", "card", "update"). The controller asks the registry for the
|
||||
* right handler, then asks the handler which data class to build, and finally
|
||||
* calls handle() with that data object.
|
||||
*
|
||||
* Flow:
|
||||
* MicropubRequest (normalise) → MicropubController
|
||||
* → MicropubHandlerRegistry::getHandler($type)
|
||||
* → $handler->dataClass()::fromArray($rawData)
|
||||
* → $handler->handle($dataObject)
|
||||
*
|
||||
* Handlers are registered in MicropubServiceProvider. To support a new
|
||||
* Micropub post type, create a handler in App\Services\Micropub\Handlers, a
|
||||
* matching data class in App\Services\Micropub\Data, and register the handler
|
||||
* here with its type string.
|
||||
*/
|
||||
class MicropubHandlerRegistry
|
||||
{
|
||||
/**
|
||||
|
|
@ -13,6 +33,9 @@ class MicropubHandlerRegistry
|
|||
*/
|
||||
protected array $handlers = [];
|
||||
|
||||
/**
|
||||
* Register a handler for a given Micropub type string.
|
||||
*/
|
||||
public function register(string $type, MicropubHandlerInterface $handler): self
|
||||
{
|
||||
$this->handlers[$type] = $handler;
|
||||
|
|
@ -21,6 +44,8 @@ class MicropubHandlerRegistry
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve the handler for a given type, or throw if none is registered.
|
||||
*
|
||||
* @throws MicropubHandlerException
|
||||
*/
|
||||
public function getHandler(string $type): MicropubHandlerInterface
|
||||
|
|
|
|||
Loading…
Reference in a new issue