Refactor of micropub request handling
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 :)
This commit is contained in:
parent
23c275945a
commit
83d10e1a70
26 changed files with 699 additions and 352 deletions
34
app/Services/Micropub/MicropubHandlerRegistry.php
Normal file
34
app/Services/Micropub/MicropubHandlerRegistry.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?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];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue