create contextmanager and refactor docgeneratorTemplateType

This commit is contained in:
2021-11-30 18:35:05 +01:00
parent 0710d6572b
commit 3404d3669c
8 changed files with 132 additions and 2 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace Chill\PersonBundle\Service\DocGenerator;
use Chill\DocGeneratorBundle\Context\DocGeneratorContextInterface;
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class AccompanyingPeriodContext implements DocGeneratorContextInterface
{
public NormalizerInterface $normalizer;
public function getName(): string
{
return 'Accompanying Period';
}
public static function getKey(): string
{
return self::class;
}
public function getData($entity): array
{
if (!$entity instanceof AccompanyingPeriod) {
throw new UnexpectedTypeException($entity, AccompanyingPeriod::class);
}
return $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
}
public function getForm($entity)
{
// TODO: Implement getForm() method.
}
public function hasForm(): bool
{
return false;
}
public function supports(string $entityClass): bool
{
return $entityClass === AccompanyingPeriod::class;
}
}