vendor/easycorp/easyadmin-bundle/src/Registry/CrudControllerRegistry.php line 23

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Registry;
  3. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
  4. /**
  5.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  6.  */
  7. final class CrudControllerRegistry
  8. {
  9.     private $crudFqcnToEntityFqcnMap = [];
  10.     private $entityFqcnToCrudFqcnMap = [];
  11.     private $crudFqcnToCrudIdMap = [];
  12.     private $crudIdToCrudFqcnMap = [];
  13.     /**
  14.      * @param CrudControllerInterface[] $crudControllers
  15.      */
  16.     public function __construct(string $kernelSecret, array $crudControllersFqcn)
  17.     {
  18.         foreach ($crudControllersFqcn as $controllerFqcn) {
  19.             $this->crudFqcnToEntityFqcnMap[$controllerFqcn] = $controllerFqcn::getEntityFqcn();
  20.             $this->crudFqcnToCrudIdMap[$controllerFqcn] = substr(sha1($kernelSecret.$controllerFqcn), 07);
  21.         }
  22.         // more than one controller can manage the same entity, so this map will
  23.         // only contain the last controller associated to that repeated entity. That's why
  24.         // several methods in other classes allow to define the CRUD controller explicitly
  25.         $this->entityFqcnToCrudFqcnMap array_flip($this->crudFqcnToEntityFqcnMap);
  26.         $this->crudIdToCrudFqcnMap array_flip($this->crudFqcnToCrudIdMap);
  27.     }
  28.     public function findCrudFqcnByEntityFqcn(string $entityFqcn): ?string
  29.     {
  30.         return $this->entityFqcnToCrudFqcnMap[$entityFqcn] ?? null;
  31.     }
  32.     public function findEntityFqcnByCrudFqcn(string $controllerFqcn): ?string
  33.     {
  34.         return $this->crudFqcnToEntityFqcnMap[$controllerFqcn] ?? null;
  35.     }
  36.     public function findCrudFqcnByCrudId(string $crudId): ?string
  37.     {
  38.         return $this->crudIdToCrudFqcnMap[$crudId] ?? null;
  39.     }
  40.     public function findCrudIdByCrudFqcn(string $controllerFqcn): ?string
  41.     {
  42.         return $this->crudFqcnToCrudIdMap[$controllerFqcn] ?? null;
  43.     }
  44. }