getTranslationResources()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * ConfirmationDialogExtension.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
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\ConfirmationDialog\Components;
24
use IPub\ConfirmationDialog\Storage;
25
26
/**
27
 * Confirmation dialog extension container
28
 *
29
 * @package        iPublikuj:ConfirmationDialog!
30
 * @subpackage     DI
31
 *
32
 * @author         Adam Kadlec <[email protected]>
33
 */
34 1
final class ConfirmationDialogExtension extends DI\CompilerExtension
35
{
36
	/**
37
	 * @var array
38
	 */
39
	private $defaults = [
40
		'layoutFile'   => NULL,
41
		'templateFile' => NULL
42
	];
43
44
	/**
45
	 * @return void
46
	 */
47
	public function loadConfiguration() : void
48
	{
49 1
		$config = $this->getConfig($this->defaults);
50 1
		$builder = $this->getContainerBuilder();
51
52
		// Session storage
53 1
		$builder->addDefinition($this->prefix('storage'))
54 1
			->setType(Storage\Session::class);
55
56 1
		$confirmerFactory = $builder->addDefinition($this->prefix('confirmer'))
57 1
			->setType(Components\Confirmer::class)
58 1
			->setImplement(Components\IConfirmer::class)
59 1
			->setArguments([new Code\PhpLiteral('$templateFile')])
60 1
			->setAutowired(FALSE)
61 1
			->setInject(TRUE);
62
63
		// Define components factories
64 1
		$dialogFactory = $builder->addDefinition($this->prefix('dialog'))
65 1
			->setType(Components\Control::class)
66 1
			->setImplement(Components\IControl::class)
67 1
			->setArguments([
68 1
				new Code\PhpLiteral('$layoutFile'),
69 1
				new Code\PhpLiteral('$templateFile'),
70 1
				$confirmerFactory,
71
			])
72 1
			->setInject(TRUE);
73
74 1
		if ($config['layoutFile']) {
75
			$dialogFactory->addSetup('$service->setLayoutFile(?)', [$config['layoutFile']]);
76
		}
77
78 1
		if ($config['templateFile']) {
79
			$dialogFactory->addSetup('$service->setTemplateFile(?)', [$config['templateFile']]);
80
		}
81 1
	}
82
83
	/**
84
	 * @param Nette\Configurator $config
85
	 * @param string $extensionName
86
	 */
87
	public static function register(Nette\Configurator $config, $extensionName = 'confirmationDialog') : void
88
	{
89 1
		$config->onCompile[] = function (Nette\Configurator $config, DI\Compiler $compiler) use ($extensionName) : void {
90 1
			$compiler->addExtension($extensionName, new ConfirmationDialogExtension());
91 1
		};
92 1
	}
93
94
	/**
95
	 * Return array of directories, that contain resources for translator.
96
	 *
97
	 * @return string[]
98
	 */
99
	public function getTranslationResources() : array
100
	{
101
		return [
102
			__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Translations'
103
		];
104
	}
105
}
106