generate document with relatorio: config and driver

This commit is contained in:
2021-12-02 18:02:19 +01:00
parent 2245f83631
commit af6efdd0ba
15 changed files with 286 additions and 363 deletions

View File

@@ -1,11 +1,18 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\DocGeneratorBundle\GeneratorDriver;
use Nelmio\Alice\ParameterBag;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
@@ -31,10 +38,10 @@ class RelatorioDriver implements DriverInterface
$this->url = $parameterBag->get('chill_doc_generator')['driver']['relatorio']['url'];
}
public function generateFromResource($template, string $resourceType, array $data, string $templateName = null)
public function generateFromResource($template, string $resourceType, array $data, ?string $templateName = null)
{
$formFields = [
'variables' => \json_encode($data),
'variables' => json_encode($data),
'template' => new DataPart($template, $templateName ?? uniqid('template_'), $resourceType),
];
$form = new FormDataPart($formFields);
@@ -47,7 +54,7 @@ class RelatorioDriver implements DriverInterface
return $response->toStream();
} catch (HttpExceptionInterface $e) {
$this->logger->error("relatorio: error while generating document", [
$this->logger->error('relatorio: error while generating document', [
'msg' => $e->getMessage(),
'response' => $e->getResponse()->getStatusCode(),
'content' => $e->getResponse()->getContent(false),
@@ -55,14 +62,14 @@ class RelatorioDriver implements DriverInterface
throw $e;
} catch (TransportExceptionInterface $e) {
$this->logger->error("relatorio: transport exception", [
$this->logger->error('relatorio: transport exception', [
'msg' => $e->getMessage(),
'e' => $e->getTraceAsString(),
]);
throw $e;
} catch (DecodingExceptionInterface $e) {
$this->logger->error("relatorio: could not decode response", [
$this->logger->error('relatorio: could not decode response', [
'msg' => $e->getMessage(),
'e' => $e->getTraceAsString(),
]);