src/Controller/Sync/Proxy/GetAction.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the nellapp-core package.
  4.  *
  5.  * (c) Benjamin Georgeault
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Controller\Sync\Proxy;
  11. use App\Entity\App\App;
  12. use App\Service\CrossApp\Proxy\ProxyClient;
  13. use Drosalys\Bundle\ApiBundle\Routing\Attributes\Get;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. /**
  19.  * Class GetAction
  20.  *
  21.  * @author Benjamin Georgeault
  22.  */
  23. class GetAction
  24. {
  25.     public function __construct(
  26.         private ProxyClient $proxyClient,
  27.     ) {}
  28.     /**
  29.      * Proxy api for app to other apps.
  30.      */
  31.     #[Get('/proxy/{app}/{path}'requirements: ['path' => '.+'])]
  32.     #[IsGranted('ROLE_USER')]
  33.     #[ParamConverter('app'options: ['mapping' => ['app' => 'queueName']])]
  34.     public function __invoke(Request $requestApp $appstring $path): Response
  35.     {
  36.         $response $this->proxyClient->doGet($app->getQueueName(), $path$request->query->all());
  37.         $headers array_filter($response->getHeaders(false), function (string $key) {
  38.             return in_array(strtolower($key), [
  39.                 'content-type',
  40.             ]);
  41.         }, ARRAY_FILTER_USE_KEY);
  42.         return new Response(
  43.             $response->getContent(false),
  44.             $response->getStatusCode(),
  45.             $headers,
  46.         );
  47.     }
  48. }