vendor/easycorp/easyadmin-bundle/src/Registry/DashboardControllerRegistry.php line 26

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Registry;
  3. use EasyCorp\Bundle\EasyAdminBundle\Cache\CacheWarmer;
  4. use function Symfony\Component\String\u;
  5. /**
  6.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  7.  */
  8. final class DashboardControllerRegistry
  9. {
  10.     private $controllerFqcnToContextIdMap = [];
  11.     private $contextIdToControllerFqcnMap = [];
  12.     private $controllerFqcnToRouteMap = [];
  13.     private $routeToControllerFqcnMap = [];
  14.     public function __construct(string $kernelSecretstring $cacheDir, array $dashboardControllersFqcn)
  15.     {
  16.         foreach ($dashboardControllersFqcn as $controllerFqcn) {
  17.             $this->controllerFqcnToContextIdMap[$controllerFqcn] = substr(sha1($kernelSecret.$controllerFqcn), 07);
  18.         }
  19.         $this->contextIdToControllerFqcnMap array_flip($this->controllerFqcnToContextIdMap);
  20.         $dashboardRoutesCachePath $cacheDir.'/'.CacheWarmer::DASHBOARD_ROUTES_CACHE;
  21.         $dashboardControllerRoutes = !file_exists($dashboardRoutesCachePath) ? [] : require $dashboardRoutesCachePath;
  22.         foreach ($dashboardControllerRoutes as $routeName => $controller) {
  23.             $this->controllerFqcnToRouteMap[u($controller)->before('::')->toString()] = $routeName;
  24.         }
  25.         $this->routeToControllerFqcnMap array_flip($this->controllerFqcnToRouteMap);
  26.     }
  27.     public function getControllerFqcnByContextId(string $contextId): ?string
  28.     {
  29.         return $this->contextIdToControllerFqcnMap[$contextId] ?? null;
  30.     }
  31.     public function getContextIdByControllerFqcn(string $controllerFqcn): ?string
  32.     {
  33.         return $this->controllerFqcnToContextIdMap[$controllerFqcn] ?? null;
  34.     }
  35.     public function getControllerFqcnByRoute(string $routeName): ?string
  36.     {
  37.         return $this->routeToControllerFqcnMap[$routeName] ?? null;
  38.     }
  39.     public function getRouteByControllerFqcn(string $controllerFqcn): ?string
  40.     {
  41.         return $this->controllerFqcnToRouteMap[$controllerFqcn] ?? null;
  42.     }
  43.     public function getNumberOfDashboards(): int
  44.     {
  45.         return \count($this->controllerFqcnToContextIdMap);
  46.     }
  47.     public function getFirstDashboardRoute(): ?string
  48.     {
  49.         return \count($this->controllerFqcnToRouteMap) < null $this->controllerFqcnToRouteMap[array_key_first($this->controllerFqcnToRouteMap)];
  50.     }
  51. }