Completed
Push — master ( d2ee45...5d494d )
by Adam
04:50 queued 02:51
created

ConfirmationDialogExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 88.46%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 64
ccs 23
cts 26
cp 0.8846
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
B loadConfiguration() 0 30 3
A getTranslationResources() 0 6 1
1
<?php
2
/**
3
 * ConfirmationDialogExtension.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:ConfirmationDialog!
9
 * @subpackage     DI
10
 * @since          1.0.0
11
 *
12
 * @date           08.06.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\ConfirmationDialog\DI;
18
19
use Nette;
20
use Nette\DI;
21
use Nette\PhpGenerator as Code;
22
23
use IPub;
24
use IPub\ConfirmationDialog;
25
use IPub\ConfirmationDialog\Components;
26
use IPub\ConfirmationDialog\Storage;
27
28
/**
29
 * Confirmation dialog extension container
30
 *
31
 * @package        iPublikuj:ConfirmationDialog!
32
 * @subpackage     DI
33
 *
34
 * @author         Adam Kadlec <[email protected]>
35
 */
36 1
class ConfirmationDialogExtension extends DI\CompilerExtension
37
{
38
	/**
39
	 * @var array
40
	 */
41
	protected $defaults = [
42
		'layoutFile'   => NULL,
43
		'templateFile' => NULL
44
	];
45
46
	public function loadConfiguration()
47
	{
48 1
		$config = $this->getConfig($this->defaults);
49 1
		$builder = $this->getContainerBuilder();
50
51
		// Session storage
52 1
		$builder->addDefinition($this->prefix('storage'))
53 1
			->setClass(Storage\Session::class);
54
55
		// Define components factories
56 1
		$dialog = $builder->addDefinition($this->prefix('dialog'))
57 1
			->setClass(Components\Control::class)
58 1
			->setImplement(Components\IControl::class)
59 1
			->setArguments([new Code\PhpLiteral('$layoutFile'), new Code\PhpLiteral('$templateFile')])
60 1
			->setInject(TRUE);
61
62 1
		$builder->addDefinition($this->prefix('confirmer'))
63 1
			->setClass(Components\Confirmer::class)
64 1
			->setImplement(Components\IConfirmer::class)
65 1
			->setArguments([new Code\PhpLiteral('$templateFile')])
66 1
			->setInject(TRUE);
67
68 1
		if ($config['layoutFile']) {
69
			$dialog->addSetup('$service->setLayoutFile(?)', [$config['layoutFile']]);
70
		}
71
72 1
		if ($config['templateFile']) {
73
			$dialog->addSetup('$service->setTemplateFile(?)', [$config['templateFile']]);
74
		}
75 1
	}
76
77
	/**
78
	 * @param Nette\Configurator $config
79
	 * @param string $extensionName
80
	 */
81
	public static function register(Nette\Configurator $config, $extensionName = 'confirmationDialog')
82
	{
83 1
		$config->onCompile[] = function (Nette\Configurator $config, DI\Compiler $compiler) use ($extensionName) {
84 1
			$compiler->addExtension($extensionName, new ConfirmationDialogExtension());
85 1
		};
86 1
	}
87
88
	/**
89
	 * Return array of directories, that contain resources for translator.
90
	 *
91
	 * @return string[]
92
	 */
93
	public function getTranslationResources()
94
	{
95
		return [
96
			__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Translations'
97
		];
98
	}
99
}
100