<?php
/*
* This file is part of the nellapp-core package.
*
* (c) Benjamin Georgeault
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Controller\Sync\Proxy;
use App\Entity\App\App;
use App\Service\CrossApp\Proxy\ProxyClient;
use Drosalys\Bundle\ApiBundle\Routing\Attributes\Get;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Class GetAction
*
* @author Benjamin Georgeault
*/
class GetAction
{
public function __construct(
private ProxyClient $proxyClient,
) {}
/**
* Proxy api for app to other apps.
*/
#[Get('/proxy/{app}/{path}', requirements: ['path' => '.+'])]
#[IsGranted('ROLE_USER')]
#[ParamConverter('app', options: ['mapping' => ['app' => 'queueName']])]
public function __invoke(Request $request, App $app, string $path): Response
{
$response = $this->proxyClient->doGet($app->getQueueName(), $path, $request->query->all());
$headers = array_filter($response->getHeaders(false), function (string $key) {
return in_array(strtolower($key), [
'content-type',
]);
}, ARRAY_FILTER_USE_KEY);
return new Response(
$response->getContent(false),
$response->getStatusCode(),
$headers,
);
}
}