src/Controller/LegacyController.php line 29

Open in your IDE?
  1. <?php
  2. namespace Klaravik\Controller;
  3. use Klaravik\Anthesis\CarbonDioxideEmissions;
  4. use Klaravik\CompanyInfo\CompanyInfoClientInterface;
  5. use Klaravik\Financing\Nordea\Calculate;
  6. use Klaravik\Firebase\KamNotifier;
  7. use Klaravik\Firebase\StorefrontNotifier;
  8. use Klaravik\Identity\IdentityFactory;
  9. use Klaravik\Assets\ManifestAssets;
  10. use Klaravik\Page\MarketWpClient;
  11. use Klaravik\Page\PropUserData;
  12. use Klaravik\Product\Util\TimeLeftUtil;
  13. use Klaravik\Storefront\GraphQL\Repository\ProductCategoriesRepository;
  14. use Klaravik\Storefront\GraphQL\Repository\ProductSearchRepository;
  15. use Klaravik\Translate\Trans;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\StreamedResponse;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  22. use Symfony\Contracts\HttpClient\HttpClientInterface;
  23. use Twig\Environment;
  24. class LegacyController extends AbstractController
  25. {
  26.     public function loadLegacyScript(
  27.         Request $request,
  28.         Trans $trans,
  29.         UrlGeneratorInterface $urlGenerator,
  30.         ManifestAssets $manifestAssets,
  31.         Environment $twig,
  32.         string $legacyScript,
  33.         array $requestParams = []
  34.     ): StreamedResponse {
  35.         $session $request->getSession()->start();
  36.         return new StreamedResponse(
  37.             function () use ($legacyScript$requestParams$request$trans$urlGenerator$manifestAssets$twig) {
  38.                 $_SERVER['SCRIPT_FILENAME'] = $legacyScript;
  39.                 // Needed for legacy inGroups function
  40.                 global $container;
  41.                 $container $this->container;
  42.                 foreach ($requestParams as $key => $value) {
  43.                     $_REQUEST[$key] = $value;
  44.                 }
  45.                 $routeParameters $request->attributes->get('_route_params');
  46.                 unset($routeParameters['requestPath'], $routeParameters['legacyScript'], $routeParameters['requestParams']);
  47.                 foreach ($routeParameters as $key => $value) {
  48.                     $_REQUEST[$key] = $value;
  49.                 }
  50.                 session_start();
  51.                 if ((null !== $user $this->getUser()) && in_array('ROLE_ADMIN'$user->getRoles(), true)) {
  52.                     $_SESSION['is_admin'] = true;
  53.                     // TODO: Remove when RemoteUser is removed
  54.                     $_SESSION['legacyRemoteUser'] = $user->getUserIdentifier();
  55.                 }
  56.                 chdir(dirname($legacyScript));
  57.                 require $legacyScript;
  58.             }
  59.         );
  60.     }
  61.     public static function getSubscribedServices(): array
  62.     {
  63.         return array_merge(parent::getSubscribedServices(), [
  64.             CompanyInfoClientInterface::class,
  65.             Trans::class,
  66.             UrlGeneratorInterface::class,
  67.             IdentityFactory::class,
  68.             ParameterBagInterface::class,
  69.             HttpClientInterface::class,
  70.             KamNotifier::class,
  71.             CarbonDioxideEmissions::class,
  72.             TimeLeftUtil::class,
  73.             StorefrontNotifier::class,
  74.             Calculate::class,
  75.             ProductSearchRepository::class,
  76.             ProductCategoriesRepository::class,
  77.             EventDispatcherInterface::class,
  78.             MarketWpClient::class,
  79.             PropUserData::class,
  80.         ]);
  81.     }
  82. }