Using HttpClientInterface instead of file_get_contents

This commit is contained in:
marcu 2021-11-30 14:46:21 +01:00
parent 2993dab3f7
commit 0e88d7c549

View File

@ -37,13 +37,17 @@ use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
final class DocGeneratorTemplateController extends AbstractController
{
private KernelInterface $kernel;
private HttpClientInterface $client;
public function __construct(KernelInterface $kernel)
public function __construct(KernelInterface $kernel, HttpClientInterface $client)
{
$this->kernel = $kernel;
$this->client = $client;
}
/**
@ -63,7 +67,7 @@ final class DocGeneratorTemplateController extends AbstractController
'GET',
$template->getFile()->getFilename());
$data = file_get_contents($getUrlGen->url);
$data = $this->client->request('GET', $getUrlGen->url);
$iv = $template->getFile()->getIv(); // iv as an Array
$ivGoodFormat = pack('C*', ...$iv); // iv as a String (ok for openssl_decrypt)
@ -73,7 +77,7 @@ final class DocGeneratorTemplateController extends AbstractController
$key = $template->getFile()->getKeyInfos()['k'];
$keyGoodFormat = Base64Url::decode($key);
$dataDecrypted = openssl_decrypt($data, $method, $keyGoodFormat, 1, $ivGoodFormat);
$dataDecrypted = openssl_decrypt($data->getContent(), $method, $keyGoodFormat, 1, $ivGoodFormat);
if ($dataDecrypted === FALSE) {
throw new \Exception("Error during Decrypt ", 1);