1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebSocketsZMQExtension.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:WebSocketsZMQ! |
9
|
|
|
* @subpackage DI |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 01.03.17 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\WebSocketsZMQ\DI; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
use Nette\DI; |
21
|
|
|
use Nette\Schema; |
22
|
|
|
|
23
|
|
|
use IPub\WebSocketsZMQ; |
24
|
|
|
use IPub\WebSocketsZMQ\Consumer; |
25
|
|
|
use IPub\WebSocketsZMQ\Pusher; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* WebSockets ZeroMQ extension container |
29
|
|
|
* |
30
|
|
|
* @package iPublikuj:WebSocket! |
31
|
|
|
* @subpackage DI |
32
|
|
|
* |
33
|
|
|
* @author Adam Kadlec <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
final class WebSocketsZMQExtension extends DI\CompilerExtension |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
1 |
|
*/ |
40
|
|
|
public function getConfigSchema() : Schema\Schema |
41
|
|
|
{ |
42
|
|
|
return Schema\Expect::structure([ |
43
|
|
|
'host' => Schema\Expect::string('127.0.0.1'), |
44
|
|
|
'port' => Schema\Expect::int(5555), |
45
|
|
|
'persistent' => Schema\Expect::bool(TRUE), |
46
|
|
|
'protocol' => Schema\Expect::string('tcp'), |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function loadConfiguration() |
54
|
|
|
{ |
55
|
|
|
parent::loadConfiguration(); |
56
|
1 |
|
|
57
|
|
|
$builder = $this->getContainerBuilder(); |
58
|
|
|
$configuration = $this->getConfig(); |
59
|
1 |
|
|
60
|
|
|
$zmqConfiguration = new WebSocketsZMQ\Configuration( |
61
|
1 |
|
$configuration->host, |
62
|
1 |
|
$configuration->port, |
63
|
|
|
$configuration->persistent, |
64
|
|
|
$configuration->protocol |
65
|
|
|
); |
66
|
|
|
|
67
|
1 |
|
$builder->addDefinition($this->prefix('consumer')) |
68
|
1 |
|
->setType(Consumer\Consumer::class) |
69
|
1 |
|
->setArguments(['configuration' => $zmqConfiguration]); |
70
|
1 |
|
|
71
|
1 |
|
$builder->addDefinition($this->prefix('pusher')) |
72
|
|
|
->setType(Pusher\Pusher::class) |
73
|
|
|
->setArguments(['configuration' => $zmqConfiguration]); |
74
|
1 |
|
} |
75
|
1 |
|
|
76
|
1 |
|
/** |
77
|
|
|
* @param Nette\Configurator $config |
78
|
1 |
|
* @param string $extensionName |
79
|
1 |
|
* |
80
|
1 |
|
* @return void |
81
|
1 |
|
*/ |
82
|
|
|
public static function register( |
83
|
|
|
Nette\Configurator $config, |
84
|
|
|
string $extensionName = 'webSocketsZMQ' |
85
|
|
|
) : void { |
86
|
|
|
$config->onCompile[] = function (Nette\Configurator $config, DI\Compiler $compiler) use ($extensionName) { |
87
|
|
|
$compiler->addExtension($extensionName, new WebSocketsZMQExtension()); |
88
|
|
|
}; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|