1 | <?php |
||
21 | class ZmqServer implements ServerInterface, LoggerAwareInterface |
||
22 | { |
||
23 | /** |
||
24 | * Cruft flake generator. |
||
25 | * |
||
26 | * @var Generator |
||
27 | */ |
||
28 | private $generator; |
||
29 | |||
30 | /** |
||
31 | * DSN. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $dsn; |
||
36 | |||
37 | /** |
||
38 | * Logger. |
||
39 | * |
||
40 | * @var LoggerInterface |
||
41 | */ |
||
42 | private $logger; |
||
43 | private $debugMode = false; |
||
44 | |||
45 | /** |
||
46 | * Constructor. |
||
47 | * |
||
48 | * @param @inject Generator $generator |
||
49 | * @param string $dsn Where socket should be bound. Default 'tcp://*:5599' |
||
50 | * @param bool $debugMode Debug mode. If set to true, server will only listen for one command, before exiting. |
||
51 | */ |
||
52 | 8 | public function __construct(Generator $generator, $dsn = 'tcp://*:5599', $debugMode = false) |
|
59 | |||
60 | /** |
||
61 | * Run ZMQ interface for generator. |
||
62 | * |
||
63 | * Req-rep pattern; msgs are commands: |
||
64 | * |
||
65 | * GEN = Generate ID |
||
66 | * STATUS = Get status string |
||
67 | */ |
||
68 | 6 | public function run() |
|
84 | |||
85 | 5 | private function runCommand($msg) |
|
98 | |||
99 | /** |
||
100 | * Create generate command response. |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | 3 | private function commandGenerate() |
|
115 | |||
116 | /** |
||
117 | * Create status command response. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | 1 | private function commandStatus() |
|
125 | |||
126 | /** |
||
127 | * Prepare response. |
||
128 | * |
||
129 | * @param mixed $message Return message. Anything, which is JSON serializable. |
||
130 | * @param int $code Response code. |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 5 | private function createResponse($message, $code = 200) |
|
141 | |||
142 | /** |
||
143 | * Get ZMQ socket. |
||
144 | * |
||
145 | * @param string $dsn DSN, on which ZMQ connection should listen. |
||
146 | * |
||
147 | * @return \ZMQSocket |
||
148 | */ |
||
149 | 1 | protected function getZmqSocket($dsn) |
|
160 | |||
161 | 1 | public function setLogger(LoggerInterface $logger) |
|
165 | } |
||
166 |