Add an async handler for using in AJAX requests and responses.

This commit is contained in:
Dave Smith-Hayes 2025-04-27 03:12:14 +00:00
parent 0c10957e9c
commit f5e599c75d
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace Slovocast\Handler;
use Psr\Http\Message\ResponseInterface;
use Slovocast\Handler\Handler;
abstract class AsyncHandler extends Handler
{
/**
* @param array<mixed> $data Data used for the response
*/
public function prepareResponse(array $data, string $template = ""): ResponseInterface
{
$acceptsHeader = $this->request->getHeader('Accept');
switch ($acceptsHeader) {
case 'text/html':
return $this->renderInline($template, $data);
break;
case 'application/json':
default:
return $this->json($data);
break;
}
}
}

View File

@ -12,6 +12,9 @@ use Slovocast\Handler\Handler;
use Psr\Http\Message\ResponseInterface;
use Slovocast\Domain\Repository\Episode\EpisodeFileRepositoryInterface;
/**
* Maybe call this Async? Used for
*/
class UploadEpisodeFileAction extends Handler
{
public function __construct(