vendor/sonata-project/admin-bundle/src/Route/AdminPoolLoader.php line 62

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\Route;
  12. use Sonata\AdminBundle\Admin\Pool;
  13. use Symfony\Component\Config\Loader\Loader;
  14. use Symfony\Component\Config\Resource\FileResource;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Component\Routing\RouteCollection as SymfonyRouteCollection;
  17. /**
  18.  * @final since sonata-project/admin-bundle 3.52
  19.  *
  20.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  21.  */
  22. class AdminPoolLoader extends Loader
  23. {
  24.     public const ROUTE_TYPE_NAME 'sonata_admin';
  25.     /**
  26.      * @var Pool
  27.      */
  28.     protected $pool;
  29.     /**
  30.      * @var array
  31.      */
  32.     protected $adminServiceIds = [];
  33.     /**
  34.      * @var ContainerInterface
  35.      */
  36.     protected $container;
  37.     public function __construct(Pool $pool, array $adminServiceIdsContainerInterface $container)
  38.     {
  39.         $this->pool $pool;
  40.         $this->adminServiceIds $adminServiceIds;
  41.         $this->container $container;
  42.     }
  43.     public function supports($resource$type null)
  44.     {
  45.         return self::ROUTE_TYPE_NAME === $type;
  46.     }
  47.     public function load($resource$type null)
  48.     {
  49.         $collection = new SymfonyRouteCollection();
  50.         foreach ($this->adminServiceIds as $id) {
  51.             $admin $this->pool->getInstance($id);
  52.             foreach ($admin->getRoutes()->getElements() as $code => $route) {
  53.                 $collection->add($route->getDefault('_sonata_name'), $route);
  54.             }
  55.             $reflection = new \ReflectionObject($admin);
  56.             if (file_exists($reflection->getFileName())) {
  57.                 $collection->addResource(new FileResource($reflection->getFileName()));
  58.             }
  59.         }
  60.         $reflection = new \ReflectionObject($this->container);
  61.         if (file_exists($reflection->getFileName())) {
  62.             $collection->addResource(new FileResource($reflection->getFileName()));
  63.         }
  64.         return $collection;
  65.     }
  66. }