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,21 @@
<?php
namespace Chill\DocGeneratorBundle\Context;
class ContextManager
{
private iterable $contexts;
/**
* @param iterable $contexts
*/
public function __construct(iterable $contexts)
{
$this->contexts = $contexts;
}
public function getContext(): array
{
return iterator_to_array($this->contexts);
}
}

View File

@@ -16,6 +16,11 @@ namespace Chill\DocGeneratorBundle\Context;
*/
interface DocGeneratorContextInterface
{
public static function getKey(): string;
public function getName(): string;
/**
* Get the data that will be injected to the generated document.
*

View File

@@ -0,0 +1,11 @@
<?php
namespace Chill\DocGeneratorBundle\Context\Exception;
class UnexpectedTypeException extends \LogicException
{
public function __construct($value, string $expectedType)
{
parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, \is_object($value) ? \get_class($value) : \gettype($value)));
}
}

View File

@@ -23,6 +23,16 @@ use function get_class;
*/
class HouseholdMemberSelectionContext implements DocGeneratorContextInterface
{
public function getName(): string
{
return 'household member';
}
public static function getKey(): string
{
return self::class;
}
/**
* Get the data that will be injected to the generated document.
*