FormsExtension::beforeCompile()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 1
nop 0
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
/**
3
 * FormsExtension.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Forms!
9
 * @subpackage     common
10
 * @since          1.0.0
11
 *
12
 * @date           31.01.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Forms\DI;
18
19
use Nette;
20
use Nette\Bridges;
21
use Nette\DI;
22
23
use IPub\Forms;
24
25
/**
26
 * Form extension container
27
 *
28
 * @package        iPublikuj:Forms!
29
 * @subpackage     DI
30
 *
31
 * @author         Adam Kadlec <[email protected]>
32
 */
33 1
final class FormsExtension extends DI\CompilerExtension
34
{
35
	/**
36
	 * @return void
37
	 */
38
	public function loadConfiguration() : void
39
	{
40 1
		$builder = $this->getContainerBuilder();
41
42 1
		$builder->addDefinition($this->prefix('factory'))
43 1
			->setType(Forms\FormFactory::class)
44 1
			->addTag('cms.forms');
45 1
	}
46
47
	/**
48
	 * {@inheritdoc}
49
	 */
50
	public function beforeCompile() : void
51
	{
52 1
		parent::beforeCompile();
53
54 1
		$builder = $this->getContainerBuilder();
55
56
		// Install extension latte macros
57 1
		$latteFactory = $builder->getDefinition($builder->getByType(Bridges\ApplicationLatte\ILatteFactory::class) ?: 'nette.latteFactory');
58
59 1
		$latteFactory->addSetup('IPub\Forms\Latte\Macros::install(?->getCompiler())', ['@self']);
60 1
	}
61
62
	/**
63
	 * @param Nette\Configurator $config
64
	 * @param string $extensionName
65
	 *
66
	 * @return void
67
	 */
68
	public static function register(Nette\Configurator $config, string $extensionName = 'extendedForms') : void
69
	{
70 1
		$config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) {
71 1
			$compiler->addExtension($extensionName, new FormsExtension());
72 1
		};
73 1
	}
74
}
75