FormsExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 42
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 8 1
A beforeCompile() 0 11 2
A register() 0 6 1
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