Completed
Push — master ( d441ef...56480f )
by Adam
03:05
created

DI/ConfirmationDialogExtension.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\ConfirmationDialog;
24
25
/**
26
 * Confirmation dialog extension container
27
 *
28
 * @package        iPublikuj:ConfirmationDialog!
29
 * @subpackage     DI
30
 *
31
 * @author         Adam Kadlec <[email protected]>
32
 */
33 1
class ConfirmationDialogExtension extends DI\CompilerExtension
34
{
35
	/**
36
	 * @var array
37
	 */
38
	protected $defaults = [
39
		'layoutFile'   => NULL,
40
		'templateFile' => NULL
41
	];
42
43
	public function loadConfiguration()
44
	{
45 1
		$config = $this->getConfig($this->defaults);
46 1
		$builder = $this->getContainerBuilder();
47
48
		// Session storage
49 1
		$builder->addDefinition($this->prefix('storage'))
50 1
			->setClass(ConfirmationDialog\Storage\Session::CLASS_NAME);
51
52
		// Define components factories
53 1
		$dialog = $builder->addDefinition($this->prefix('dialog'))
54 1
			->setClass(ConfirmationDialog\Components\Control::CLASS_NAME)
55 1
			->setImplement(ConfirmationDialog\Components\IControl::INTERFACE_NAME)
56 1
			->setArguments([new Nette\PhpGenerator\PhpLiteral('$layoutFile'), new Nette\PhpGenerator\PhpLiteral('$templateFile')])
57 1
			->setInject(TRUE)
58 1
			->addTag('cms.components');
59
60 1
		$builder->addDefinition($this->prefix('confirmer'))
61 1
			->setClass(ConfirmationDialog\Components\Confirmer::CLASS_NAME)
62 1
			->setImplement(ConfirmationDialog\Components\IConfirmer::INTERFACE_NAME)
63 1
			->setArguments([new Nette\PhpGenerator\PhpLiteral('$templateFile')])
64 1
			->setInject(TRUE)
65 1
			->addTag('cms.components');
66
67 1
		if ($config['layoutFile']) {
68
			$dialog->addSetup('$service->setLayoutFile(?)', [$config['layoutFile']]);
69
		}
70
71 1
		if ($config['templateFile']) {
72
			$dialog->addSetup('$service->setTemplateFile(?)', [$config['templateFile']]);
73
		}
74 1
	}
75
76
	/**
77
	 * @param Nette\Configurator $config
78
	 * @param string $extensionName
79
	 */
80
	public static function register(Nette\Configurator $config, $extensionName = 'confirmationDialog')
81
	{
82 1
		$config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) {
83 1
			$compiler->addExtension($extensionName, new ConfirmationDialogExtension());
84 1
		};
85 1
	}
86
87
	/**
88
	 * Return array of directories, that contain resources for translator.
89
	 *
90
	 * @return string[]
91
	 */
92
	function getTranslationResources()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
93
	{
94
		return [
95
			__DIR__ . '/../Translations'
96
		];
97
	}
98
}
99