Trying to organise the code better. It now temporarily doesn’t support update requests. Thought the spec defines them as SHOULD features and not MUST features. So safe for now :)
34 lines
725 B
PHP
34 lines
725 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Micropub;
|
|
|
|
use App\Exceptions\MicropubHandlerException;
|
|
|
|
class MicropubHandlerRegistry
|
|
{
|
|
/**
|
|
* @var MicropubHandlerInterface[]
|
|
*/
|
|
protected array $handlers = [];
|
|
|
|
public function register(string $type, MicropubHandlerInterface $handler): self
|
|
{
|
|
$this->handlers[$type] = $handler;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @throws MicropubHandlerException
|
|
*/
|
|
public function getHandler(string $type): MicropubHandlerInterface
|
|
{
|
|
if (! isset($this->handlers[$type])) {
|
|
throw new MicropubHandlerException("No handler registered for '{$type}'");
|
|
}
|
|
|
|
return $this->handlers[$type];
|
|
}
|
|
}
|