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
|
|
|
|
22
|
|
|
use IPub; |
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
|
|
|
* @method DI\ContainerBuilder getContainerBuilder() |
36
|
|
|
* @method array getConfig(array $defaults) |
37
|
|
|
* @method string prefix(string $name) |
38
|
|
|
*/ |
39
|
1 |
|
final class WebSocketsZMQExtension extends DI\CompilerExtension |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private $defaults = [ |
45
|
|
|
'host' => '127.0.0.1', |
46
|
|
|
'port' => 5555, |
47
|
|
|
'persistent' => TRUE, |
48
|
|
|
'protocol' => 'tcp', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function loadConfiguration() |
55
|
|
|
{ |
56
|
1 |
|
parent::loadConfiguration(); |
57
|
|
|
|
58
|
|
|
/** @var DI\ContainerBuilder $builder */ |
59
|
1 |
|
$builder = $this->getContainerBuilder(); |
60
|
|
|
/** @var array $configuration */ |
61
|
1 |
|
$configuration = $this->getConfig($this->defaults); |
62
|
|
|
|
63
|
1 |
|
$configuration = new WebSocketsZMQ\Configuration( |
64
|
1 |
|
$configuration['host'], |
65
|
1 |
|
$configuration['port'], |
66
|
1 |
|
$configuration['persistent'], |
67
|
1 |
|
$configuration['protocol'] |
68
|
|
|
); |
69
|
|
|
|
70
|
1 |
|
$builder->addDefinition($this->prefix('consumer')) |
|
|
|
|
71
|
1 |
|
->setClass(Consumer\Consumer::class) |
72
|
1 |
|
->setArguments(['configuration' => $configuration]); |
73
|
|
|
|
74
|
1 |
|
$builder->addDefinition($this->prefix('pusher')) |
|
|
|
|
75
|
1 |
|
->setClass(Pusher\Pusher::class) |
76
|
1 |
|
->setArguments(['configuration' => $configuration]); |
77
|
1 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param Nette\Configurator $config |
81
|
|
|
* @param string $extensionName |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public static function register(Nette\Configurator $config, string $extensionName = 'webSocketsZMQ') |
86
|
|
|
{ |
87
|
|
|
$config->onCompile[] = function (Nette\Configurator $config, DI\Compiler $compiler) use ($extensionName) { |
88
|
|
|
$compiler->addExtension($extensionName, new WebSocketsZMQExtension()); |
89
|
|
|
}; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.