Add an async handler for using in AJAX requests and responses.
This commit is contained in:
parent
0c10957e9c
commit
f5e599c75d
27
app/src/Handler/AsyncHandler.php
Normal file
27
app/src/Handler/AsyncHandler.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user