vendor/contao/core-bundle/src/Controller/AbstractController.php line 64

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\Controller;
  11. use Contao\CoreBundle\Cache\EntityCacheTags;
  12. use Contao\CoreBundle\Csrf\ContaoCsrfTokenManager;
  13. use Contao\CoreBundle\Framework\Adapter;
  14. use Contao\CoreBundle\Framework\ContaoFramework;
  15. use Contao\Model\Collection as ModelCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use FOS\HttpCacheBundle\Http\SymfonyResponseTagger;
  18. use Psr\Log\LoggerInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SymfonyAbstractController;
  20. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  21. abstract class AbstractController extends SymfonyAbstractController
  22. {
  23.     public static function getSubscribedServices()/*: array*/
  24.     {
  25.         $services parent::getSubscribedServices();
  26.         $services['contao.framework'] = ContaoFramework::class;
  27.         $services['event_dispatcher'] = EventDispatcherInterface::class;
  28.         $services['logger'] = '?'.LoggerInterface::class;
  29.         $services['fos_http_cache.http.symfony_response_tagger'] = '?'.SymfonyResponseTagger::class;
  30.         $services['contao.csrf.token_manager'] = ContaoCsrfTokenManager::class;
  31.         $services['contao.cache.entity_tags'] = EntityCacheTags::class;
  32.         return $services;
  33.     }
  34.     protected function initializeContaoFramework(): void
  35.     {
  36.         $this->container->get('contao.framework')->initialize();
  37.     }
  38.     /**
  39.      * @template T
  40.      *
  41.      * @param class-string<T> $class
  42.      *
  43.      * @return T
  44.      *
  45.      * @phpstan-return Adapter<T>
  46.      */
  47.     protected function getContaoAdapter(string $class)
  48.     {
  49.         return $this->container->get('contao.framework')->getAdapter($class);
  50.     }
  51.     /**
  52.      * @param array|Collection|ModelCollection|string|object|null $tags
  53.      */
  54.     protected function tagResponse($tags): void
  55.     {
  56.         $this->container->get('contao.cache.entity_tags')->tagWith($tags);
  57.     }
  58.     /**
  59.      * @return array{csrf_field_name: string, csrf_token_manager: ContaoCsrfTokenManager, csrf_token_id: string}
  60.      */
  61.     protected function getCsrfFormOptions(): array
  62.     {
  63.         return [
  64.             'csrf_field_name' => 'REQUEST_TOKEN',
  65.             'csrf_token_manager' => $this->container->get('contao.csrf.token_manager'),
  66.             'csrf_token_id' => $this->getParameter('contao.csrf_token_name'),
  67.         ];
  68.     }
  69. }