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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Administration\Controller;
  3. use Shopware\Administration\Framework\Routing\KnownIps\KnownIpsCollectorInterface;
  4. use Shopware\Administration\Snippet\SnippetFinderInterface;
  5. use Shopware\Core\Defaults;
  6. use Shopware\Core\Framework\Adapter\Twig\TemplateFinder;
  7. use Shopware\Core\Framework\Feature;
  8. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  9. use Shopware\Core\Framework\Routing\Annotation\Since;
  10. use Shopware\Core\Framework\Store\Services\FirstRunWizardClient;
  11. use Shopware\Core\PlatformRequest;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class AdministrationController extends AbstractController
  18. {
  19.     /**
  20.      * @var TemplateFinder
  21.      */
  22.     private $finder;
  23.     /**
  24.      * @var FirstRunWizardClient
  25.      */
  26.     private $firstRunWizardClient;
  27.     /**
  28.      * @var SnippetFinderInterface
  29.      */
  30.     private $snippetFinder;
  31.     /**
  32.      * @var array
  33.      */
  34.     private $supportedApiVersions;
  35.     /**
  36.      * @var KnownIpsCollectorInterface
  37.      */
  38.     private $knownIpsCollector;
  39.     public function __construct(
  40.         TemplateFinder $finder,
  41.         FirstRunWizardClient $firstRunWizardClient,
  42.         SnippetFinderInterface $snippetFinder,
  43.         array $supportedApiVersions,
  44.         KnownIpsCollectorInterface $knownIpsCollector
  45.     ) {
  46.         $this->finder $finder;
  47.         $this->firstRunWizardClient $firstRunWizardClient;
  48.         $this->snippetFinder $snippetFinder;
  49.         $this->supportedApiVersions $supportedApiVersions;
  50.         $this->knownIpsCollector $knownIpsCollector;
  51.     }
  52.     /**
  53.      * @Since("6.3.3.0")
  54.      * @RouteScope(scopes={"administration"})
  55.      * @Route("/admin", defaults={"auth_required"=false}, name="administration.index", methods={"GET"})
  56.      */
  57.     public function index(Request $request): Response
  58.     {
  59.         $template $this->finder->find('@Administration/administration/index.html.twig');
  60.         return $this->render($template, [
  61.             'features' => Feature::getAll(),
  62.             'systemLanguageId' => Defaults::LANGUAGE_SYSTEM,
  63.             'defaultLanguageIds' => [Defaults::LANGUAGE_SYSTEM],
  64.             'systemCurrencyId' => Defaults::CURRENCY,
  65.             'liveVersionId' => Defaults::LIVE_VERSION,
  66.             'firstRunWizard' => $this->firstRunWizardClient->frwShouldRun(),
  67.             'apiVersion' => $this->getLatestApiVersion(),
  68.             'cspNonce' => $request->attributes->get(PlatformRequest::ATTRIBUTE_CSP_NONCE),
  69.         ]);
  70.     }
  71.     /**
  72.      * @Since("6.1.0.0")
  73.      * @RouteScope(scopes={"administration"})
  74.      * @Route("/api/v{version}/_admin/snippets", name="api.admin.snippets", methods={"GET"})
  75.      */
  76.     public function snippets(Request $request): Response
  77.     {
  78.         $locale $request->query->get('locale''en-GB');
  79.         $snippets[$locale] = $this->snippetFinder->findSnippets($locale);
  80.         if ($locale !== 'en-GB') {
  81.             $snippets['en-GB'] = $this->snippetFinder->findSnippets('en-GB');
  82.         }
  83.         return new JsonResponse($snippets);
  84.     }
  85.     /**
  86.      * @Since("6.3.1.0")
  87.      * @RouteScope(scopes={"administration"})
  88.      * @Route("/api/v{version}/_admin/known-ips", name="api.admin.known-ips", methods={"GET"})
  89.      */
  90.     public function knownIps(Request $request): Response
  91.     {
  92.         $ips = [];
  93.         foreach ($this->knownIpsCollector->collectIps($request) as $ip => $name) {
  94.             $ips[] = [
  95.                 'name' => $name,
  96.                 'value' => $ip,
  97.             ];
  98.         }
  99.         return new JsonResponse(['ips' => $ips]);
  100.     }
  101.     private function getLatestApiVersion(): int
  102.     {
  103.         $sortedSupportedApiVersions array_values($this->supportedApiVersions);
  104.         usort($sortedSupportedApiVersions'version_compare');
  105.         return array_pop($sortedSupportedApiVersions);
  106.     }
  107. }