full generation for accompanying period

This commit is contained in:
2021-12-01 15:43:34 +01:00
parent 9d0e1a82e7
commit 7719d2b073
14 changed files with 248 additions and 108 deletions

View File

@@ -11,8 +11,14 @@ declare(strict_types=1);
namespace Chill\DocGeneratorBundle\Context;
use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
class ContextManager
{
/**
* @var DocGeneratorContextInterface[]|iterable
*/
private iterable $contexts;
public function __construct(iterable $contexts)
@@ -20,7 +26,21 @@ class ContextManager
$this->contexts = $contexts;
}
public function getContext(): array
/**
* @throw ContextNotFoundException when the context is not found
*/
public function getContextByDocGeneratorTemplate(DocGeneratorTemplate $docGeneratorTemplate): DocGeneratorContextInterface
{
foreach ($this->contexts as $key => $context) {
if ($docGeneratorTemplate->getContext() === $key) {
return $context;
}
}
throw new ContextNotFoundException($docGeneratorTemplate->getContext());
}
public function getContexts(): array
{
return iterator_to_array($this->contexts);
}