Пример #1
0
 /**
  * Produces a new message.
  *
  * @param string $type    The type of message
  * @param mixed  $message The message
  *
  * @return void
  *
  * @codeCoverageIgnore
  */
 public function produce($type, $message)
 {
     $fp = @stream_socket_client(sprintf('tcp://%s:%d', $this->hostname, $this->port), $errno, $errstr, 30);
     if (!$fp) {
         throw new \RuntimeException(sprintf('%s (%s)', $errstr, $errno));
     }
     fwrite($fp, Json::encode(array('type' => $type, 'message' => $message)));
     fclose($fp);
 }
Пример #2
0
 /**
  * @param mixed $item
  *
  * @return mixed
  */
 public function convert($item)
 {
     return Json::encode($item, $this->options);
 }
Пример #3
0
 /**
  * Finish the writer.
  */
 public function finish()
 {
     file_put_contents($this->filename, Json::encode($this->data));
 }
Пример #4
0
 /**
  * Finish the writer.
  */
 public function finish()
 {
     $this->json = Json::encode($this->data);
 }