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

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