1 | <?php |
||
18 | class ZmqServer implements ServerInterface, LoggerAwareInterface |
||
19 | { |
||
20 | /** |
||
21 | * Cruft flake generator. |
||
22 | * |
||
23 | * @var Generator |
||
24 | */ |
||
25 | private $generator; |
||
26 | |||
27 | /** |
||
28 | * DSN. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $dsn; |
||
33 | |||
34 | /** |
||
35 | * Logger. |
||
36 | * |
||
37 | * @var LoggerInterface |
||
38 | */ |
||
39 | private $logger; |
||
40 | private $debugMode = false; |
||
41 | |||
42 | /** |
||
43 | * Constructor. |
||
44 | * |
||
45 | * @param @inject Generator $generator |
||
46 | * @param string $dsn Where socket should be bound. Default 'tcp://*:5599' |
||
47 | * @param bool $debugMode Debug mode. If set to true, server will only listen for one command, before exiting. |
||
48 | */ |
||
49 | 4 | public function __construct(Generator $generator, $dsn = 'tcp://*:5599', $debugMode = false) |
|
56 | |||
57 | /** |
||
58 | * Run ZMQ interface for generator. |
||
59 | * |
||
60 | * Req-rep pattern; msgs are commands: |
||
61 | * |
||
62 | * GEN = Generate ID |
||
63 | * STATUS = Get status string |
||
64 | */ |
||
65 | 4 | public function run() |
|
79 | |||
80 | 4 | private function runCommand($msg) |
|
93 | |||
94 | /** |
||
95 | * Create generate command response. |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | 2 | private function commandGenerate() |
|
110 | |||
111 | /** |
||
112 | * Create status command response. |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | 1 | private function commandStatus() |
|
120 | |||
121 | /** |
||
122 | * Prepare response. |
||
123 | * |
||
124 | * @param mixed $message Return message. Anything, which is JSON serializable. |
||
125 | * @param int $code Response code. |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | 4 | private function createResponse($message, $code = 200) |
|
136 | |||
137 | /** |
||
138 | * Get ZMQ socket. |
||
139 | * |
||
140 | * @param string $dsn DSN, on which ZMQ connection should listen. |
||
141 | * |
||
142 | * @return \ZMQSocket |
||
143 | */ |
||
144 | protected function getZmqSocket($dsn) |
||
153 | |||
154 | public function setLogger(LoggerInterface $logger) |
||
158 | } |
||
159 |