vendor/shopware/administration/Controller/AdministrationController.php line 48

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Administration\Controller;
  3. use Shopware\Administration\Snippet\SnippetFinderInterface;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\Adapter\Twig\TemplateFinder;
  6. use Shopware\Core\Framework\FeatureFlag\FeatureConfig;
  7. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  8. use Shopware\Core\Framework\Store\Services\FirstRunWizardClient;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class AdministrationController extends AbstractController
  15. {
  16.     /**
  17.      * @var TemplateFinder
  18.      */
  19.     private $finder;
  20.     /**
  21.      * @var FirstRunWizardClient
  22.      */
  23.     private $firstRunWizardClient;
  24.     /**
  25.      * @var SnippetFinderInterface
  26.      */
  27.     private $snippetFinder;
  28.     private $supportedApiVersions;
  29.     public function __construct(TemplateFinder $finderFirstRunWizardClient $firstRunWizardClientSnippetFinderInterface $snippetFinder$supportedApiVersions)
  30.     {
  31.         $this->finder $finder;
  32.         $this->firstRunWizardClient $firstRunWizardClient;
  33.         $this->snippetFinder $snippetFinder;
  34.         $this->supportedApiVersions $supportedApiVersions;
  35.     }
  36.     /**
  37.      * @RouteScope(scopes={"administration"})
  38.      * @Route("/admin", defaults={"auth_required"=false}, name="administration.index", methods={"GET"})
  39.      */
  40.     public function index(): Response
  41.     {
  42.         $template $this->finder->find('@Administration/administration/index.html.twig');
  43.         return $this->render($template, [
  44.             'features' => FeatureConfig::getAll(),
  45.             'systemLanguageId' => Defaults::LANGUAGE_SYSTEM,
  46.             'defaultLanguageIds' => [Defaults::LANGUAGE_SYSTEM],
  47.             'systemCurrencyId' => Defaults::CURRENCY,
  48.             'liveVersionId' => Defaults::LIVE_VERSION,
  49.             'firstRunWizard' => $this->firstRunWizardClient->frwShouldRun(),
  50.             'apiVersion' => $this->getLatestApiVersion(),
  51.         ]);
  52.     }
  53.     /**
  54.      * @RouteScope(scopes={"administration"})
  55.      * @Route("/api/v{version}/_admin/snippets", name="api.admin.snippets", methods={"GET"})
  56.      */
  57.     public function snippets(Request $request): Response
  58.     {
  59.         $locale $request->query->get('locale''en-GB');
  60.         $snippets[$locale] = $this->snippetFinder->findSnippets($locale);
  61.         if ($locale !== 'en-GB') {
  62.             $snippets['en-GB'] = $this->snippetFinder->findSnippets('en-GB');
  63.         }
  64.         return new JsonResponse($snippets);
  65.     }
  66.     private function getLatestApiVersion(): int
  67.     {
  68.         $sortedSupportedApiVersions array_values($this->supportedApiVersions);
  69.         usort($sortedSupportedApiVersions'version_compare');
  70.         return array_pop($sortedSupportedApiVersions);
  71.     }
  72. }