vendor/sonata-project/admin-bundle/src/Controller/CoreController.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\AdminBundle\Controller;
  12. // NEXT_MAJOR: remove this file
  13. @trigger_error(sprintf(
  14.     'The %1$s\CoreController class is deprecated since version 3.36 and will be removed in 4.0.'
  15.     .' Use %1$s\SearchAction or %1$s\DashboardAction instead.',
  16.     __NAMESPACE__
  17. ), \E_USER_DEPRECATED);
  18. use Sonata\AdminBundle\Action\DashboardAction;
  19. use Sonata\AdminBundle\Action\SearchAction;
  20. use Sonata\AdminBundle\Admin\Pool;
  21. use Sonata\AdminBundle\Search\SearchHandler;
  22. use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
  23. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. /**
  28.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  29.  */
  30. class CoreController extends Controller
  31. {
  32.     /**
  33.      * @return Response
  34.      */
  35.     public function dashboardAction()
  36.     {
  37.         $dashboardAction $this->container->get(DashboardAction::class);
  38.         return $dashboardAction($this->getCurrentRequest());
  39.     }
  40.     /**
  41.      * The search action first render an empty page, if the query is set, then the template generates
  42.      * some ajax request to retrieve results for each admin. The Ajax query returns a JSON response.
  43.      *
  44.      * @throws \RuntimeException
  45.      *
  46.      * @return JsonResponse|Response
  47.      */
  48.     public function searchAction(Request $request)
  49.     {
  50.         $searchAction $this->container->get(SearchAction::class);
  51.         return $searchAction($request);
  52.     }
  53.     /**
  54.      * Get the request object from the container.
  55.      *
  56.      * This method is compatible with both Symfony 2.3 and Symfony 3
  57.      *
  58.      * NEXT_MAJOR: remove this method.
  59.      *
  60.      * @deprecated since sonata-project/admin-bundle 3.0, to be removed in 4.0 and action methods will be adjusted.
  61.      *             Use Symfony\Component\HttpFoundation\Request as an action argument
  62.      *
  63.      * @return Request
  64.      */
  65.     public function getRequest()
  66.     {
  67.         @trigger_error(sprintf(
  68.             'The %s method is deprecated since 3.0 and will be removed in 4.0.'
  69.             .' Inject the %s into the actions instead.',
  70.             __METHOD__,
  71.             Request::class
  72.         ), \E_USER_DEPRECATED);
  73.         return $this->getCurrentRequest();
  74.     }
  75.     /**
  76.      * @return Pool
  77.      */
  78.     protected function getAdminPool()
  79.     {
  80.         $pool $this->container->get('sonata.admin.pool');
  81.         \assert($pool instanceof Pool);
  82.         return $pool;
  83.     }
  84.     /**
  85.      * @return SearchHandler
  86.      */
  87.     protected function getSearchHandler()
  88.     {
  89.         $searchHandler $this->get('sonata.admin.search.handler');
  90.         \assert($searchHandler instanceof SearchHandler);
  91.         return $searchHandler;
  92.     }
  93.     /**
  94.      * @return string
  95.      */
  96.     protected function getBaseTemplate()
  97.     {
  98.         if ($this->getCurrentRequest()->isXmlHttpRequest()) {
  99.             return $this->getTemplateRegistry()->getTemplate('ajax');
  100.         }
  101.         return $this->getTemplateRegistry()->getTemplate('layout');
  102.     }
  103.     private function getTemplateRegistry(): TemplateRegistryInterface
  104.     {
  105.         $templateRegistry $this->container->get('sonata.admin.global_template_registry');
  106.         \assert($templateRegistry instanceof TemplateRegistryInterface);
  107.         return $templateRegistry;
  108.     }
  109.     private function getCurrentRequest(): Request
  110.     {
  111.         return $this->container->get('request_stack')->getCurrentRequest();
  112.     }
  113. }