vendor/easycorp/easyadmin-bundle/src/Context/AdminContext.php line 30

Open in your IDE?
  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Context;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
  5. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
  6. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Factory\MenuFactoryInterface;
  7. use EasyCorp\Bundle\EasyAdminBundle\Dto\AssetsDto;
  8. use EasyCorp\Bundle\EasyAdminBundle\Dto\CrudDto;
  9. use EasyCorp\Bundle\EasyAdminBundle\Dto\DashboardDto;
  10. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  11. use EasyCorp\Bundle\EasyAdminBundle\Dto\I18nDto;
  12. use EasyCorp\Bundle\EasyAdminBundle\Dto\LocaleDto;
  13. use EasyCorp\Bundle\EasyAdminBundle\Dto\MainMenuDto;
  14. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  15. use EasyCorp\Bundle\EasyAdminBundle\Dto\UserMenuDto;
  16. use EasyCorp\Bundle\EasyAdminBundle\Registry\CrudControllerRegistry;
  17. use EasyCorp\Bundle\EasyAdminBundle\Registry\TemplateRegistry;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Security\Core\User\UserInterface;
  20. /**
  21.  * A context object that stores all the state and config of the current admin request.
  22.  *
  23.  * IMPORTANT: any new methods added here MUST be duplicated in the AdminContextProvider class.
  24.  *
  25.  * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  26.  */
  27. final class AdminContext
  28. {
  29.     private Request $request;
  30.     private ?UserInterface $user;
  31.     private I18nDto $i18nDto;
  32.     private CrudControllerRegistry $crudControllers;
  33.     private ?EntityDto $entityDto;
  34.     private DashboardDto $dashboardDto;
  35.     private DashboardControllerInterface $dashboardControllerInstance;
  36.     private AssetsDto $assetDto;
  37.     private ?CrudDto $crudDto;
  38.     private ?SearchDto $searchDto;
  39.     private MenuFactoryInterface $menuFactory;
  40.     private TemplateRegistry $templateRegistry;
  41.     private ?MainMenuDto $mainMenuDto null;
  42.     private ?UserMenuDto $userMenuDto null;
  43.     private bool $usePrettyUrls;
  44.     public function __construct(Request $request, ?UserInterface $userI18nDto $i18nDtoCrudControllerRegistry $crudControllersDashboardDto $dashboardDtoDashboardControllerInterface $dashboardControllerAssetsDto $assetDto, ?CrudDto $crudDto, ?EntityDto $entityDto, ?SearchDto $searchDtoMenuFactoryInterface $menuFactoryTemplateRegistry $templateRegistrybool $usePrettyUrls false)
  45.     {
  46.         $this->request $request;
  47.         $this->user $user;
  48.         $this->i18nDto $i18nDto;
  49.         $this->crudControllers $crudControllers;
  50.         $this->dashboardDto $dashboardDto;
  51.         $this->dashboardControllerInstance $dashboardController;
  52.         $this->crudDto $crudDto;
  53.         $this->assetDto $assetDto;
  54.         $this->entityDto $entityDto;
  55.         $this->searchDto $searchDto;
  56.         $this->menuFactory $menuFactory;
  57.         $this->templateRegistry $templateRegistry;
  58.         $this->usePrettyUrls $usePrettyUrls;
  59.     }
  60.     public function getRequest(): Request
  61.     {
  62.         return $this->request;
  63.     }
  64.     public function getReferrer(): ?string
  65.     {
  66.         $referrer $this->request->query->get(EA::REFERRER);
  67.         return '' !== $referrer $referrer null;
  68.     }
  69.     public function getI18n(): I18nDto
  70.     {
  71.         return $this->i18nDto;
  72.     }
  73.     public function getCrudControllers(): CrudControllerRegistry
  74.     {
  75.         return $this->crudControllers;
  76.     }
  77.     public function getEntity(): EntityDto
  78.     {
  79.         return $this->entityDto;
  80.     }
  81.     public function getUser(): ?UserInterface
  82.     {
  83.         return $this->user;
  84.     }
  85.     public function getAssets(): AssetsDto
  86.     {
  87.         return $this->assetDto;
  88.     }
  89.     public function getSignedUrls(): bool
  90.     {
  91.         return $this->dashboardDto->getSignedUrls();
  92.     }
  93.     public function getAbsoluteUrls(): bool
  94.     {
  95.         return $this->dashboardDto->getAbsoluteUrls();
  96.     }
  97.     public function usePrettyUrls(): bool
  98.     {
  99.         return $this->usePrettyUrls;
  100.     }
  101.     public function getDashboardTitle(): string
  102.     {
  103.         return $this->dashboardDto->getTitle();
  104.     }
  105.     public function getDashboardFaviconPath(): string
  106.     {
  107.         return $this->dashboardDto->getFaviconPath();
  108.     }
  109.     public function getDashboardControllerFqcn(): string
  110.     {
  111.         return \get_class($this->dashboardControllerInstance);
  112.     }
  113.     public function getDashboardRouteName(): string
  114.     {
  115.         return $this->dashboardDto->getRouteName();
  116.     }
  117.     public function getDashboardContentWidth(): string
  118.     {
  119.         return $this->dashboardDto->getContentWidth();
  120.     }
  121.     public function getDashboardSidebarWidth(): string
  122.     {
  123.         return $this->dashboardDto->getSidebarWidth();
  124.     }
  125.     public function getDashboardHasDarkModeEnabled(): bool
  126.     {
  127.         return $this->dashboardDto->isDarkModeEnabled();
  128.     }
  129.     public function getDashboardDefaultColorScheme(): string
  130.     {
  131.         return $this->dashboardDto->getDefaultColorScheme();
  132.     }
  133.     /**
  134.      * @return LocaleDto[]
  135.      */
  136.     public function getDashboardLocales(): array
  137.     {
  138.         return $this->dashboardDto->getLocales();
  139.     }
  140.     public function getMainMenu(): MainMenuDto
  141.     {
  142.         if (null !== $this->mainMenuDto) {
  143.             return $this->mainMenuDto;
  144.         }
  145.         $configuredMenuItems $this->dashboardControllerInstance->configureMenuItems();
  146.         $mainMenuItems \is_array($configuredMenuItems) ? $configuredMenuItems iterator_to_array($configuredMenuItemsfalse);
  147.         return $this->mainMenuDto $this->menuFactory->createMainMenu($mainMenuItems);
  148.     }
  149.     public function getUserMenu(): UserMenuDto
  150.     {
  151.         if (null !== $this->userMenuDto) {
  152.             return $this->userMenuDto;
  153.         }
  154.         if (null === $this->user) {
  155.             return UserMenu::new()->getAsDto();
  156.         }
  157.         $userMenu $this->dashboardControllerInstance->configureUserMenu($this->user);
  158.         return $this->userMenuDto $this->menuFactory->createUserMenu($userMenu);
  159.     }
  160.     public function getCrud(): ?CrudDto
  161.     {
  162.         return $this->crudDto;
  163.     }
  164.     public function getSearch(): ?SearchDto
  165.     {
  166.         return $this->searchDto;
  167.     }
  168.     public function getTemplatePath(string $templateName): string
  169.     {
  170.         return $this->templateRegistry->get($templateName);
  171.     }
  172. }