src/App/Controller/Proposal/DetailsController.php line 62

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Controller\Proposal;
  3. use App\Doctrine\Cache\CacheDecider;
  4. use App\Entity\Proposal;
  5. use App\Entity\ProposalBid;
  6. use App\Entity\ProposalVideoFile;
  7. use App\Exception\ProposalNotFoundException;
  8. use App\Repository\ProposalRepository;
  9. /**
  10.  * @template B of ProposalBid
  11.  * @template V of ProposalVideoFile
  12.  * @template T of Proposal<V, B>
  13.  * @extends \App\Controller\CRUD\DetailsController<T>
  14.  */
  15. abstract class DetailsController extends \App\Controller\CRUD\DetailsController
  16. {
  17.     private CacheDecider $cacheDecider;
  18.     /**
  19.      * @param class-string<T> $repository FQCN for entity class
  20.      */
  21.     public function __construct(CacheDecider $cacheDeciderstring $repositorystring $template)
  22.     {
  23.         $this->cacheDecider $cacheDecider;
  24.         parent::__construct($repository$template);
  25.     }
  26.     /**
  27.      * @param array<string, array<mixed>|bool|int|float|object|string|null> $filters
  28.      * @return T
  29.      */
  30.     public function provideEntity(array $filters): Proposal
  31.     {
  32.         if (!isset($filters['id']) || !is_string($filters['id'])) {
  33.             throw $this->createNotFoundException('Id parameter is required.');
  34.         }
  35.         /** @var ProposalRepository<T> $repository */
  36.         $repository $this->getRepository();
  37.         /**
  38.          * @var T|null $proposal
  39.          */
  40.         $proposal $repository->filterOneResult($repository->applyPublicFilters([
  41.             'stringId' => $filters['id'],
  42.         ]), $this->cacheDecider);
  43.         if (null === $proposal) {
  44.             /**
  45.              * @var T|null $proposal
  46.              */
  47.             $proposal $repository->filterOneResult($repository->applyFinishedFilters([
  48.                 'stringId' => $filters['id'],
  49.             ]), $this->cacheDecider);
  50.             if (null === $proposal) {
  51.                 throw new ProposalNotFoundException();
  52.             }
  53.         }
  54.         return $proposal;
  55.     }
  56. }