Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function log(int $level, string $format, ...$args) : \Generator
 {
     $date = new \DateTimeImmutable('now', $this->timezone);
     if ($this->level & $level) {
         yield from $this->stream->write($this->format($level, sprintf($format, ...$args), $date));
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function send($data) : \Generator
 {
     // Serialize the data to send into the channel.
     try {
         $serialized = serialize($data);
     } catch (\Throwable $exception) {
         throw new SerializationException('The given data cannot be sent because it is not serializable.', $exception);
     }
     $length = strlen($serialized);
     try {
         yield from $this->write->write(pack('CL', 0, $length) . $serialized);
     } catch (\Throwable $exception) {
         throw new ChannelException('Sending on the channel failed. Did the context die?', $exception);
     }
     return $length;
 }