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

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\Csrf\ContaoCsrfTokenManager;
  12. use Contao\CoreBundle\Framework\ContaoFramework;
  13. use FOS\HttpCacheBundle\Http\SymfonyResponseTagger;
  14. use Psr\Log\LoggerInterface;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SymfonyAbstractController;
  16. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  17. abstract class AbstractController extends SymfonyAbstractController
  18. {
  19.     public static function getSubscribedServices()
  20.     {
  21.         $services parent::getSubscribedServices();
  22.         $services['contao.framework'] = ContaoFramework::class;
  23.         $services['event_dispatcher'] = EventDispatcherInterface::class;
  24.         $services['logger'] = '?'.LoggerInterface::class;
  25.         $services['fos_http_cache.http.symfony_response_tagger'] = '?'.SymfonyResponseTagger::class;
  26.         $services[] = ContaoCsrfTokenManager::class;
  27.         return $services;
  28.     }
  29.     protected function initializeContaoFramework(): void
  30.     {
  31.         $this->get('contao.framework')->initialize();
  32.     }
  33.     protected function tagResponse(array $tags): void
  34.     {
  35.         if (!$this->has('fos_http_cache.http.symfony_response_tagger')) {
  36.             return;
  37.         }
  38.         $this->get('fos_http_cache.http.symfony_response_tagger')->addTags($tags);
  39.     }
  40.     /**
  41.      * @return array{csrf_field_name: string, csrf_token_manager: ContaoCsrfTokenManager, csrf_token_id: string}
  42.      */
  43.     protected function getCsrfFormOptions(): array
  44.     {
  45.         return [
  46.             'csrf_field_name' => 'REQUEST_TOKEN',
  47.             'csrf_token_manager' => $this->get(ContaoCsrfTokenManager::class),
  48.             'csrf_token_id' => $this->getParameter('contao.csrf_token_name'),
  49.         ];
  50.     }
  51. }