Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Config/Option/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ final class CacheKey
public const ROUTE_ATTRIBUTES_TO_NAME = 'easyadmin.routes.fqcn_to_route';
public const DASHBOARD_FQCN_TO_ROUTE = 'easyadmin.routes.controller_fqcn_to_dashboard_route';
public const CRUD_FQCN_TO_ENTITY_FQCN = 'easyadmin.crud.controller_fqcn_to_entity_fqcn';
public const ENTITY_FQCN_TO_CRUD_FQCN = 'easyadmin.crud.entity_fqcn_to_controller_fqcn';
}
23 changes: 6 additions & 17 deletions src/Router/AdminRouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function generateAll(): RouteCollection
// this dumps all admin routes in a performance-optimized format to later
// find them quickly without having to use Symfony's router service
$this->saveAdminRoutesInCache($adminRoutes);
$this->saveCrudControllersAndEntityFqcnMapInCache($this->crudControllers);
$this->saveCrudControllerToEntityFqcnMapInCache($this->crudControllers);

return $collection;
}
Expand Down Expand Up @@ -873,32 +873,21 @@ private function saveAdminRoutesInCache(array $adminRoutes): void
}

// This replaces the ControllerRegistry that existed in previous EasyAdmin versions.
// It stores two maps between CRUD controllers and their associated entity FQCN:
// controller_to_entity: $cache['crud_controller_fqcn'] => 'entity_fqcn'
// entity_to_controller: $cache['entity_fqcn'] => ['crud_controller_fqcn1', 'crud_controller_fqcn2', ...]
// It stores the map between CRUD controllers and their associated entity FQCN:
// $cache['crud_controller_fqcn'] => 'entity_fqcn'
// (AdminControllerRegistry derives the reverse entity-to-controller map from it)
/**
* @param iterable<CrudControllerInterface> $crudControllers
*/
private function saveCrudControllersAndEntityFqcnMapInCache(iterable $crudControllers): void
private function saveCrudControllerToEntityFqcnMapInCache(iterable $crudControllers): void
{
$crudToEntityMap = [];
$entityToCrudMap = [];
foreach ($crudControllers as $crudController) {
$entityFqcn = $crudController::getEntityFqcn();
$crudToEntityMap[$crudController::class] = $entityFqcn;

if (!isset($entityToCrudMap[$entityFqcn])) {
$entityToCrudMap[$entityFqcn] = [];
}
$entityToCrudMap[$entityFqcn][] = $crudController::class;
$crudToEntityMap[$crudController::class] = $crudController::getEntityFqcn();
}

$crudToEntityCacheItem = $this->cache->getItem(CacheKey::CRUD_FQCN_TO_ENTITY_FQCN);
$crudToEntityCacheItem->set($crudToEntityMap);
$this->cache->save($crudToEntityCacheItem);

$entityToCrudCacheItem = $this->cache->getItem(CacheKey::ENTITY_FQCN_TO_CRUD_FQCN);
$entityToCrudCacheItem->set($entityToCrudMap);
$this->cache->save($entityToCrudCacheItem);
}
}
Loading