/** * Writes a message to the output. * * @param string|array $messages The message as an array of lines or a single string * @param bool $newline Whether to add a newline * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL */ public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL) { $types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN; $type = $types & $options ?: self::OUTPUT_NORMAL; if (is_string($messages)) { if ("<aside>⏎</aside>" === $messages) { return; } $preparedMessage = $messages . ($newline ? '' : "\n"); switch ($type) { case OutputInterface::OUTPUT_NORMAL: $preparedMessage = $this->formatter->format($messages) . ($newline ? '' : "\n"); break; case OutputInterface::OUTPUT_RAW: break; case OutputInterface::OUTPUT_PLAIN: $preparedMessage = strip_tags($this->formatter->format($messages)) . ($newline ? '' : "\n"); break; } } elseif (is_array($messages)) { $preparedMessage = implode("\n", $messages) . ($newline ? '' : "\n"); } else { return; // TODO: Throw an error? } $this->executeAction->notifyMessage($preparedMessage); }
/** * @param $msg */ public function __invoke(array $msg) { list($zmqId, $delim, $hmac, $header, $parentHeader, $metadata, $content) = $msg; $header = json_decode($header, true); $content = json_decode($content, true); $this->logger->debug('Received message', ['processId' => getmypid(), 'zmqId' => $zmqId, 'delim' => $delim, 'hmac' => $hmac, 'header' => $header, 'parentHeader' => $parentHeader, 'metadata' => $metadata, 'content' => $content]); if ('kernel_info_request' === $header['msg_type']) { $this->kernelInfoAction->call($header, $content); } elseif ('execute_request' === $header['msg_type']) { $this->executeAction->call($header, $content); } elseif ('history_request' === $header['msg_type']) { $this->historyAction->call($header, $content); } elseif ('shutdown_request' === $header['msg_type']) { $this->shutdownAction->call($header, $content); } elseif ('comm_open' === $header['msg_type']) { // TODO: Research about what should be done. } else { $this->logger->error('Unknown message type', ['processId' => getmypid(), 'header' => $header]); } }