pack() публичный Метод

public pack ( $value )
Пример #1
0
 public function testPackCustomType()
 {
     $obj = new \stdClass();
     $transformer = $this->getTransformerMock(5);
     $transformer->expects($this->once())->method('transform')->willReturn(1);
     $coll = $this->getTransformerCollectionMock([$transformer]);
     $coll->expects($this->once())->method('match')->with($obj);
     $this->packer->setTransformers($coll);
     $this->assertSame("�", $this->packer->pack($obj));
 }
Пример #2
0
 public function emit()
 {
     $packet = ['type' => $this->type, 'data' => func_get_args(), 'nsp' => $this->namespace];
     $options = ['rooms' => $this->rooms, 'flags' => $this->flags];
     $channelName = sprintf('%s#%s#', $this->prefix, $packet['nsp']);
     $message = $this->packer->pack([$this->uid, $packet, $options]);
     // hack buffer extensions for msgpack with binary
     if ($this->type === Type::BINARY_EVENT) {
         $message = str_replace(pack('c', 0xda), pack('c', 0xd8), $message);
         $message = str_replace(pack('c', 0xdb), pack('c', 0xd9), $message);
     }
     // publish
     if (is_array($this->rooms) && count($this->rooms) > 0) {
         foreach ($this->rooms as $room) {
             $chnRoom = $channelName . $room . '#';
             $this->client->publish($chnRoom, $message);
         }
     } else {
         $this->client->publish($channelName, $message);
     }
     // reset state
     return $this->reset();
 }