VisualPaginatorExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A getTranslationResources() 0 6 1
A loadConfiguration() 0 18 2
1
<?php
2
/**
3
 * VisualPaginatorExtension.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:VisualPaginator!
9
 * @subpackage	DI
10
 * @since		5.0
11
 *
12
 * @date		18.06.14
13
 */
14
15
namespace IPub\VisualPaginator\DI;
16
17
use Nette;
18
use Nette\DI;
19
20
class VisualPaginatorExtension extends DI\CompilerExtension
21
{
22
	/**
23
	 * @var array
24
	 */
25
	protected $defaults = [
26
		'templateFile'	=> NULL
27
	];
28
29
	public function loadConfiguration()
30
	{
31
		$config = DI\Config\Helpers::merge($this->getConfig(), $this->defaults);
32
		$builder = $this->getContainerBuilder();
33
34
		// Define components
35
		$paginator = $builder->addFactoryDefinition($this->prefix('paginator'))
36
			->setImplement('IPub\VisualPaginator\Components\IControl')
37
			->addTag('cms.components')
38
			->getResultDefinition()
39
			->setType('IPub\VisualPaginator\Components\Control')
40
			->setArguments([new Nette\PhpGenerator\PhpLiteral('$templateFile')])
41
			->addTag(DI\Extensions\InjectExtension::TAG_INJECT);
42
43
		if ($config['templateFile']) {
44
			$paginator->addSetup('$service->setTemplateFile(?)', [$config['templateFile']]);
45
		}
46
	}
47
48
	/**
49
	 * @param Nette\Configurator $config
50
	 * @param string $extensionName
51
	 */
52
	public static function register(Nette\Configurator $config, $extensionName = 'visualPaginator')
53
	{
54
		$config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) {
55
			$compiler->addExtension($extensionName, new VisualPaginatorExtension());
56
		};
57
	}
58
59
	/**
60
	 * Return array of directories, that contain resources for translator.
61
	 *
62
	 * @return string[]
63
	 */
64
	function getTranslationResources()
0 ignored issues
show
Best Practice introduced by
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...
65
	{
66
		return array(
67
			__DIR__ . '/../Translations'
68
		);
69
	}
70
}
71