TemplateFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace h4kuna\MailManager\Template;
4
5
use Nette\Application;
6
use Nette\Bridges\ApplicationLatte;
7
8
class TemplateFactory implements ITemplateFactory
9
{
10
11
	/** @var Application\UI\ITemplateFactory */
12
	private $templateFactory;
13
14
	/** @var Application\LinkGenerator */
15
	private $linkGenerator;
16
17
	/** @var mixed[] */
18
	private $variables = [];
19
20
21
	public function __construct(
22
		Application\UI\ITemplateFactory $templateFactory,
23
		Application\LinkGenerator $linkGenerator
24
	)
25
	{
26
		$this->templateFactory = $templateFactory;
27
		$this->linkGenerator = $linkGenerator;
28
	}
29
30
31
	public function setVariables(array $variables): void
32
	{
33
		$this->variables = $variables;
34
	}
35
36
37
	public function create(): Application\UI\ITemplate
38
	{
39
		/** @var ApplicationLatte\Template $template */
40
		$template = $this->templateFactory->createTemplate();
41
		$template->getLatte()->addProvider('uiControl', $this->linkGenerator);
42
		foreach ($this->variables as $name => $value) {
43
			$template->{$name} = $value;
44
		}
45
		return $template;
46
	}
47
48
}
49