<?php declare(strict_types=1);
namespace App\Controller\Proposal;
use App\Doctrine\Cache\CacheDecider;
use App\Entity\Proposal;
use App\Entity\ProposalBid;
use App\Entity\ProposalVideoFile;
use App\Exception\ProposalNotFoundException;
use App\Repository\ProposalRepository;
/**
* @template B of ProposalBid
* @template V of ProposalVideoFile
* @template T of Proposal<V, B>
* @extends \App\Controller\CRUD\DetailsController<T>
*/
abstract class DetailsController extends \App\Controller\CRUD\DetailsController
{
private CacheDecider $cacheDecider;
/**
* @param class-string<T> $repository FQCN for entity class
*/
public function __construct(CacheDecider $cacheDecider, string $repository, string $template)
{
$this->cacheDecider = $cacheDecider;
parent::__construct($repository, $template);
}
/**
* @param array<string, array<mixed>|bool|int|float|object|string|null> $filters
* @return T
*/
public function provideEntity(array $filters): Proposal
{
if (!isset($filters['id']) || !is_string($filters['id'])) {
throw $this->createNotFoundException('Id parameter is required.');
}
/** @var ProposalRepository<T> $repository */
$repository = $this->getRepository();
/**
* @var T|null $proposal
*/
$proposal = $repository->filterOneResult($repository->applyPublicFilters([
'stringId' => $filters['id'],
]), $this->cacheDecider);
if (null === $proposal) {
/**
* @var T|null $proposal
*/
$proposal = $repository->filterOneResult($repository->applyFinishedFilters([
'stringId' => $filters['id'],
]), $this->cacheDecider);
if (null === $proposal) {
throw new ProposalNotFoundException();
}
}
return $proposal;
}
}