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.     private Pool $pool;
  18.     public function __construct(Pool $pool)
  19.     {
  20.         $this->pool $pool;
  21.     }
  22.     public function get(Request $request): AdminInterface
  23.     {
  24.         $adminCode $request->get('_sonata_admin');
  25.         if (!\is_string($adminCode)) {
  26.             $route $request->get('_route''');
  27.             \assert(\is_string($route));
  28.             throw new \InvalidArgumentException(sprintf(
  29.                 'There is no `_sonata_admin` defined for the current route `%s`.',
  30.                 $route
  31.             ));
  32.         }
  33.         $admin $this->pool->getAdminByAdminCode($adminCode);
  34.         $rootAdmin $admin;
  35.         while ($rootAdmin->isChild()) {
  36.             $rootAdmin->setCurrentChild(true);
  37.             $rootAdmin $rootAdmin->getParent();
  38.         }
  39.         $rootAdmin->setRequest($request);
  40.         if (\is_string($request->get('uniqid'))) {
  41.             $admin->setUniqId($request->get('uniqid'));
  42.         }
  43.         return $admin;
  44.     }
  45. }