mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
Feature: [docgen][stored object] handler for request generator and required fixes
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Service\Messenger;
|
||||
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocGeneratorBundle\Service\Generator\Generator;
|
||||
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
/**
|
||||
* Handle the request of document generation
|
||||
*/
|
||||
class RequestGenerationHandler implements MessageHandlerInterface
|
||||
{
|
||||
private StoredObjectRepository $storedObjectRepository;
|
||||
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private Generator $generator;
|
||||
|
||||
public function __construct(
|
||||
StoredObjectRepository $storedObjectRepository,
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
Generator $generator
|
||||
) {
|
||||
$this->storedObjectRepository = $storedObjectRepository;
|
||||
$this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository;
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function __invoke(RequestGenerationMessage $message)
|
||||
{
|
||||
if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) {
|
||||
throw new \RuntimeException('template not found: ' . $message->getTemplateId());
|
||||
}
|
||||
|
||||
if (null === $destinationStoredObject = $this->storedObjectRepository->find($message->getDestinationStoredObjectId())) {
|
||||
throw new \RuntimeException('destination stored object not found : ' . $message->getDestinationStoredObjectId());
|
||||
}
|
||||
|
||||
$this->generator->generateDocFromTemplate(
|
||||
$template,
|
||||
$message->getEntityClassName(),
|
||||
$message->getEntityId(),
|
||||
$message->getContextGenerationData(),
|
||||
$destinationStoredObject
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -3,6 +3,7 @@
|
||||
namespace Chill\DocGeneratorBundle\Service\Messenger;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
class RequestGenerationMessage
|
||||
@@ -15,12 +16,24 @@ class RequestGenerationMessage
|
||||
|
||||
private string $entityClassName;
|
||||
|
||||
public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName)
|
||||
{
|
||||
private int $destinationStoredObjectId;
|
||||
|
||||
private array $contextGenerationData;
|
||||
|
||||
public function __construct(
|
||||
User $creator,
|
||||
DocGeneratorTemplate $template,
|
||||
int $entityId,
|
||||
string $entityClassName,
|
||||
StoredObject $destinationStoredObject,
|
||||
array $contextGenerationData
|
||||
) {
|
||||
$this->creatorId = $creator->getId();
|
||||
$this->templateId = $template->getId();
|
||||
$this->entityId = $entityId;
|
||||
$this->entityClassName = $entityClassName;
|
||||
$this->destinationStoredObjectId = $destinationStoredObject->getId();
|
||||
$this->contextGenerationData = $contextGenerationData;
|
||||
}
|
||||
|
||||
public function getCreatorId(): int
|
||||
@@ -28,6 +41,11 @@ class RequestGenerationMessage
|
||||
return $this->creatorId;
|
||||
}
|
||||
|
||||
public function getDestinationStoredObjectId(): int
|
||||
{
|
||||
return $this->destinationStoredObjectId;
|
||||
}
|
||||
|
||||
public function getTemplateId(): int
|
||||
{
|
||||
return $this->templateId;
|
||||
@@ -42,4 +60,9 @@ class RequestGenerationMessage
|
||||
{
|
||||
return $this->entityClassName;
|
||||
}
|
||||
|
||||
public function getContextGenerationData(): array
|
||||
{
|
||||
return $this->contextGenerationData;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user