|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SixtyEightPublishers\Application\Components\DI; |
|
6
|
|
|
|
|
7
|
|
|
use Nette\DI\CompilerExtension; |
|
8
|
|
|
use Nette\DI\Helpers; |
|
9
|
|
|
use SixtyEightPublishers\Application\Components\Template; |
|
10
|
|
|
use SixtyEightPublishers\Application\Components\TemplateManager; |
|
11
|
|
|
use SixtyEightPublishers\Application\Components\TemplateFactory; |
|
12
|
|
|
|
|
13
|
|
|
class ComponentsExtension extends CompilerExtension |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
private $defaults = [ |
|
19
|
|
|
'enabled' => TRUE, |
|
20
|
|
|
'debugger' => FALSE, |
|
21
|
|
|
'templatesDir' => '%appDir%/templates' |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function loadConfiguration() |
|
28
|
|
|
{ |
|
29
|
|
|
$builder = $this->getContainerBuilder(); |
|
30
|
|
|
|
|
31
|
|
|
$builder->addDefinition($this->prefix('templateManager')) |
|
32
|
|
|
->setClass(TemplateManager::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function beforeCompile() |
|
39
|
|
|
{ |
|
40
|
|
|
$builder = $this->getContainerBuilder(); |
|
41
|
|
|
$config = $this->getConfig($this->defaults); |
|
42
|
|
|
|
|
43
|
|
|
if (($templateFactory = $builder->getDefinition('latte.templateFactory')) && class_exists('Nette\Bridges\ApplicationLatte\TemplateFactory') |
|
44
|
|
|
&& class_exists('Nette\Bridges\ApplicationLatte\Template')) { |
|
45
|
|
|
$templateFactory->setFactory(TemplateFactory::class); |
|
46
|
|
|
$templateFactory->setArguments(['templateClass' => Template::class]); |
|
47
|
|
|
$templateFactory->addSetup('setTemplateManager', ['@' . $this->prefix('templateManager')]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if ($config['enabled']) { |
|
51
|
|
|
$templatesDir = Helpers::expand($this->defaults['templatesDir'], $builder->parameters); |
|
52
|
|
|
$builder->getDefinition($this->prefix('templateManager')) |
|
53
|
|
|
->setArguments([ |
|
54
|
|
|
'map' => TemplateManager::createMap($templatesDir), |
|
55
|
|
|
'templatesDir' => $templatesDir, |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|