28 lines
655 B
PHP
28 lines
655 B
PHP
<?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;
|
|
}
|
|
}
|
|
}
|