<?php
namespace Klaravik\Controller;
use Klaravik\Anthesis\CarbonDioxideEmissions;
use Klaravik\CompanyInfo\CompanyInfoClientInterface;
use Klaravik\Financing\Nordea\Calculate;
use Klaravik\Firebase\KamNotifier;
use Klaravik\Firebase\StorefrontNotifier;
use Klaravik\Identity\IdentityFactory;
use Klaravik\Assets\ManifestAssets;
use Klaravik\Page\MarketWpClient;
use Klaravik\Page\PropUserData;
use Klaravik\Product\Util\TimeLeftUtil;
use Klaravik\Storefront\GraphQL\Repository\ProductCategoriesRepository;
use Klaravik\Storefront\GraphQL\Repository\ProductSearchRepository;
use Klaravik\Translate\Trans;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Twig\Environment;
class LegacyController extends AbstractController
{
public function loadLegacyScript(
Request $request,
Trans $trans,
UrlGeneratorInterface $urlGenerator,
ManifestAssets $manifestAssets,
Environment $twig,
string $legacyScript,
array $requestParams = []
): StreamedResponse {
$session = $request->getSession()->start();
return new StreamedResponse(
function () use ($legacyScript, $requestParams, $request, $trans, $urlGenerator, $manifestAssets, $twig) {
$_SERVER['SCRIPT_FILENAME'] = $legacyScript;
// Needed for legacy inGroups function
global $container;
$container = $this->container;
foreach ($requestParams as $key => $value) {
$_REQUEST[$key] = $value;
}
$routeParameters = $request->attributes->get('_route_params');
unset($routeParameters['requestPath'], $routeParameters['legacyScript'], $routeParameters['requestParams']);
foreach ($routeParameters as $key => $value) {
$_REQUEST[$key] = $value;
}
session_start();
if ((null !== $user = $this->getUser()) && in_array('ROLE_ADMIN', $user->getRoles(), true)) {
$_SESSION['is_admin'] = true;
// TODO: Remove when RemoteUser is removed
$_SESSION['legacyRemoteUser'] = $user->getUserIdentifier();
}
chdir(dirname($legacyScript));
require $legacyScript;
}
);
}
public static function getSubscribedServices(): array
{
return array_merge(parent::getSubscribedServices(), [
CompanyInfoClientInterface::class,
Trans::class,
UrlGeneratorInterface::class,
IdentityFactory::class,
ParameterBagInterface::class,
HttpClientInterface::class,
KamNotifier::class,
CarbonDioxideEmissions::class,
TimeLeftUtil::class,
StorefrontNotifier::class,
Calculate::class,
ProductSearchRepository::class,
ProductCategoriesRepository::class,
EventDispatcherInterface::class,
MarketWpClient::class,
PropUserData::class,
]);
}
}