/** * @param mixed $data * @param LoopInterface $loop * @return ChannelInterface */ public function createChannel($data, LoopInterface $loop) { $name = $data['config']['id']; $model = (new ReflectionClass($data['class']))->newInstance($loop, $data['config']); $router = new RouterComposite(['input' => $input = new Router(), 'output' => $output = new Router()]); $encoder = new Encoder(new JsonParser()); $channel = new Channel($name, $model, $router, $encoder, $loop); $router = $channel->getInput(); $router->addDefault(new RuleHandler(function ($params) use($channel) { $channel->pull($params['alias'], $params['protocol']); })); $router = $channel->getOutput(); $router->addDefault(new RuleHandler(function ($params) use($channel) { $channel->push($params['alias'], $params['protocol'], $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']); })); return $channel; }