vendor/sonata-project/admin-bundle/src/Request/AdminFetcher.php line 43

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\Request;
  12. use Sonata\AdminBundle\Admin\AdminInterface;
  13. use Sonata\AdminBundle\Admin\Pool;
  14. use Symfony\Component\HttpFoundation\Request;
  15. final class AdminFetcher implements AdminFetcherInterface
  16. {
  17.     /**
  18.      * @var Pool
  19.      */
  20.     private $pool;
  21.     public function __construct(Pool $pool)
  22.     {
  23.         $this->pool $pool;
  24.     }
  25.     public function get(Request $request): AdminInterface
  26.     {
  27.         $adminCode = (string) $request->get('_sonata_admin');
  28.         if ('' === $adminCode) {
  29.             throw new \InvalidArgumentException(sprintf(
  30.                 'There is no `_sonata_admin` defined for the current route `%s`.',
  31.                 (string) $request->get('_route')
  32.             ));
  33.         }
  34.         $admin $this->pool->getAdminByAdminCode($adminCode);
  35.         $rootAdmin $admin;
  36.         while ($rootAdmin->isChild()) {
  37.             $rootAdmin->setCurrentChild(true);
  38.             $rootAdmin $rootAdmin->getParent();
  39.         }
  40.         $rootAdmin->setRequest($request);
  41.         if (null !== $request->get('uniqid')) {
  42.             $admin->setUniqId($request->get('uniqid'));
  43.         }
  44.         return $admin;
  45.     }
  46. }