vendor/boldr/cms-bundle/src/Controller/GeneralController.php line 30

Open in your IDE?
  1. <?php
  2. namespace Boldr\Cms\CmsBundle\Controller;
  3. use Boldr\Cms\CmsBundle\Homepage\HomepageProviderInterface;
  4. use Boldr\Cms\CmsBundle\Admin\LoginPageConfigurationProviderInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\{ RequestResponse };
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  10. use Composer\InstalledVersions;
  11. class GeneralController extends AbstractController
  12. {
  13.     private HomepageProviderInterface $homepageProvider;
  14.     /** @param mixed $homepageId */
  15.     public function __construct(HomepageProviderInterface $homepageProvider)
  16.     {
  17.         $this->homepageProvider $homepageProvider;
  18.     }
  19.     /**
  20.      * @Route("%locale_prefixes.variable%", name="cms_home", defaults={"_locale":""}, requirements={"_locale":"|%supported_locales_route_mask%"})
  21.      */
  22.     public function home(Request $request): Response
  23.     {
  24.         return $this->homepageProvider->handleHomepage($request$this->getParameter('boldr_cms.homepage_id'));
  25.     }
  26.     /**
  27.      * @Route("/boldr-login", name="cms_login")
  28.      */
  29.     public function login(AuthenticationUtils $authenticationUtilsLoginPageConfigurationProviderInterface $loginPageConfiguration): Response
  30.     {
  31.         if ($this->getUser())
  32.         {
  33.             return $this->redirectToRoute('cms_admin');
  34.         }
  35.         $error $authenticationUtils->getLastAuthenticationError();
  36.         $lastUsername $authenticationUtils->getLastUsername();
  37.         return $this->render('@BoldrCms/security/login.html.twig', [
  38.             'last_username' => $lastUsername,
  39.             'error' => $error,
  40.             'loginPageConfiguration' => $loginPageConfiguration
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/boldr-logout", name="cms_logout")
  45.      */
  46.     public function logout(): Response
  47.     {
  48.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  49.     }
  50.     /**
  51.      * @Route("/boldr-api/boldrcms/info", name="cms_api_info")
  52.      */
  53.     public function info(Request $request): Response
  54.     {
  55.         $infoApiKey $this->getParameter('boldr_cms.info_api_key');
  56.         if ($infoApiKey === null)
  57.         {
  58.             throw $this->createNotFoundException();
  59.         }
  60.         if ($request->headers->get('X-BoldrCms-Authorization') !== $infoApiKey)
  61.         {
  62.             throw new AccessDeniedHttpException;
  63.         }
  64.         $packages = [];
  65.         foreach (InstalledVersions::getAllRawData()[0]['versions'] as $packageName => $data)
  66.         {
  67.             if (!isset($data['version']) || $packageName === '__root__')
  68.             {
  69.                 continue;
  70.             }
  71.             $packages[$packageName] = $data['pretty_version'];
  72.         }
  73.         return $this->json([
  74.             'version' => 1,
  75.             'packages' => $packages
  76.         ]);
  77.     }
  78. }