<?php
namespace App\Action\PressSite\Product;
use App\Action\PressSite\DomainAwareAction;
use App\Contract\PressSite\Language\Switcher\GenericActionInterface;
use App\Service\PressSite\Content\Callback\NewMoviesCallback;
use App\Service\PressSite\Content\MovieContentBuilder;
use App\Service\PressSite\DomainAwareManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig\Environment;
/**
* Class NewMoviesAction.
*/
class NewMoviesAction extends DomainAwareAction implements GenericActionInterface
{
/**
* The custom content builder responsible for returning the list with new movies.
*
* @var \App\Service\PressSite\Content\MovieContentBuilder
*/
private $contentBuilder;
public function __construct(
Environment $twig,
DomainAwareManager $domainAwareManager,
MovieContentBuilder $contentBuilder
) {
parent::__construct($twig, $domainAwareManager);
$this->contentBuilder = $contentBuilder;
}
/**
* Responsible for returning a collection of products.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object
*
* @return \Symfony\Component\HttpFoundation\Response
* The response object
*/
public function __invoke(Request $request): Response
{
// Theatrical sites do not have the new movies content page.
if ($this->getDomainManager()->getCurrentByHostnameAndLocale()->isBroadcastType()) {
throw new NotFoundHttpException('Page not found');
}
$this->contentBuilder->addCallback(new NewMoviesCallback());
return $this->render('press_site/actions/movies/new_movies.html.twig', [
'collection' => $this->contentBuilder->getContent(16, MovieContentBuilder::SORT_ORDER_DESC),
]);
}
}