mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
Feature: [docgen][stored object] handler for request generator and required fixes
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
|
||||
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
|
||||
@@ -12,7 +13,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
class Generator
|
||||
class Generator implements GeneratorInterface
|
||||
{
|
||||
private ContextManagerInterface $contextManager;
|
||||
|
||||
@@ -50,6 +51,7 @@ class Generator
|
||||
DocGeneratorTemplate $template,
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
array $contextGenerationData,
|
||||
?StoredObject $destinationStoredObject = null,
|
||||
bool $isTest = false,
|
||||
?File $testFile = null
|
||||
@@ -59,7 +61,6 @@ class Generator
|
||||
}
|
||||
|
||||
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
|
||||
$contextGenerationData = ['test_file' => $testFile];
|
||||
|
||||
$entity = $this
|
||||
->entityManager
|
||||
@@ -70,6 +71,13 @@ class Generator
|
||||
throw new RelatedEntityNotFoundException($entityClassName, $entityId);
|
||||
}
|
||||
|
||||
$contextGenerationData = array_merge(
|
||||
$contextGenerationData,
|
||||
$context instanceof DocGeneratorContextWithPublicFormInterface ?
|
||||
$context->publicFormReverseTransform($template, $entity, $contextGenerationData)
|
||||
: []
|
||||
);
|
||||
|
||||
if ($isTest && ($testFile instanceof File)) {
|
||||
$dataDecrypted = file_get_contents($testFile->getPathname());
|
||||
} else {
|
||||
@@ -102,29 +110,6 @@ class Generator
|
||||
|
||||
$this->storedObjectManager->write($destinationStoredObject, $generatedResource);
|
||||
|
||||
try {
|
||||
$context
|
||||
->storeGenerated(
|
||||
$template,
|
||||
$destinationStoredObject,
|
||||
$entity,
|
||||
$contextGenerationData
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this
|
||||
->logger
|
||||
->error(
|
||||
'Unable to store the associated document to entity',
|
||||
[
|
||||
'entityClassName' => $entityClassName,
|
||||
'entityId' => $entityId,
|
||||
'contextKey' => $context->getName(),
|
||||
]
|
||||
);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
return null;
|
||||
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Service\Generator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
|
||||
interface GeneratorInterface
|
||||
{
|
||||
/**
|
||||
* @template T of File|null
|
||||
* @template B of bool
|
||||
* @param B $isTest
|
||||
* @param (B is true ? T : null) $testFile
|
||||
* @psalm-return (B is true ? string : null)
|
||||
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable
|
||||
*/
|
||||
public function generateDocFromTemplate(
|
||||
DocGeneratorTemplate $template,
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
array $contextGenerationData,
|
||||
?StoredObject $destinationStoredObject = null,
|
||||
bool $isTest = false,
|
||||
?File $testFile = null
|
||||
): ?string;
|
||||
}
|
Reference in New Issue
Block a user