1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PhoneUIExtension.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license http://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:PhoneUI! |
9
|
|
|
* @subpackage DI |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 30.05.19 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\PhoneUI\DI; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
use Nette\Bridges; |
21
|
|
|
use Nette\DI; |
22
|
|
|
use Nette\PhpGenerator as Code; |
23
|
|
|
|
24
|
|
|
use IPub\PhoneUI; |
25
|
|
|
|
26
|
|
|
use libphonenumber; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Phone UI extension container |
30
|
|
|
* |
31
|
|
|
* @package iPublikuj:PhoneUI! |
32
|
|
|
* @subpackage DI |
33
|
|
|
* |
34
|
|
|
* @author Adam Kadlec <[email protected]> |
35
|
|
|
*/ |
36
|
1 |
|
final class PhoneUIExtension extends DI\CompilerExtension |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function loadConfiguration() |
42
|
|
|
{ |
43
|
|
|
// Get container builder |
44
|
1 |
|
$builder = $this->getContainerBuilder(); |
45
|
|
|
|
46
|
1 |
|
$builder->addDefinition($this->prefix('phoneUI')) |
47
|
1 |
|
->setType(PhoneUI\PhoneUI::class) |
48
|
1 |
|
->setInject(FALSE); |
49
|
|
|
|
50
|
|
|
// Register template helpers |
51
|
|
|
$builder->addDefinition($this->prefix('helpers')) |
52
|
|
|
->setType(PhoneUI\Templating\Helpers::class) |
53
|
|
|
->setFactory($this->prefix('@phoneUI') . '::createTemplateHelpers') |
54
|
|
|
->setInject(FALSE); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function beforeCompile() |
61
|
|
|
{ |
62
|
|
|
parent::beforeCompile(); |
63
|
|
|
|
64
|
|
|
// Get container builder |
65
|
|
|
$builder = $this->getContainerBuilder(); |
66
|
|
|
|
67
|
|
|
// Install extension latte macros |
68
|
|
|
$latteFactory = $builder->getDefinition($builder->getByType(Bridges\ApplicationLatte\ILatteFactory::class) ?: 'nette.latteFactory'); |
69
|
|
|
|
70
|
|
|
$latteFactory |
71
|
|
|
->addSetup('IPub\PhoneUI\Latte\Macros::install(?->getCompiler())', ['@self']) |
72
|
|
|
->addSetup('addFilter', ['phone', [$this->prefix('@helpers'), 'phone']]) |
73
|
|
|
->addSetup('addFilter', ['getPhoneNumberService', [$this->prefix('@helpers'), 'getPhoneNumberService']]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param Nette\Configurator $config |
78
|
|
|
* @param string $extensionName |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public static function register(Nette\Configurator $config, string $extensionName = 'phoneUI') |
83
|
|
|
{ |
84
|
1 |
|
$config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) { |
85
|
1 |
|
$compiler->addExtension($extensionName, new PhoneUIExtension); |
86
|
1 |
|
}; |
87
|
1 |
|
} |
88
|
|
|
} |
89
|
|
|
|