* team default empty values are empty array * page caches only updated if there is actually a filter id set for the team
48 lines
1.3 KiB
PHP
Executable File
48 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Handler;
|
|
|
|
use App\Service\AvatarService;
|
|
use finfo;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
use Zend\Diactoros\Response\TextResponse;
|
|
|
|
class AvatarHandler implements RequestHandlerInterface
|
|
{
|
|
/** @var AvatarService */
|
|
private $avatarService;
|
|
|
|
/**
|
|
* AvatarHandler constructor.
|
|
* @param AvatarService $avatarService
|
|
*/
|
|
public function __construct(AvatarService $avatarService)
|
|
{
|
|
$this->avatarService = $avatarService;
|
|
}
|
|
|
|
/**
|
|
* @param ServerRequestInterface $request
|
|
* @return ResponseInterface
|
|
*/
|
|
public function handle(ServerRequestInterface $request): ResponseInterface
|
|
{
|
|
$signum = $request->getAttribute('signum', false);
|
|
try {
|
|
$avatarImageData = $this->avatarService->getAvatarImageData($signum);
|
|
} catch (\UnexpectedValueException $e) {
|
|
return new TextResponse("Avatar not found", 404);
|
|
}
|
|
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
|
$contentType = $finfo->buffer($avatarImageData);
|
|
return (new TextResponse($avatarImageData, 200, [
|
|
'content-type' => $contentType,
|
|
]))->withHeader('Expires', '0')
|
|
->withHeader('Cache-Control', 'must-revalidate');
|
|
}
|
|
}
|