/**
  * pack entity with msgpack protocol.
  * {@link https://github.com/msgpack/msgpack-php}
  * @param Entity $entity
  * @return string
  */
 public function pack(Entity $entity)
 {
     if (function_exists('msgpack_pack')) {
         return msgpack_pack(array($entity->getTag(), $entity->getTime(), $entity->getData()));
     } else {
         return json_encode(array($entity->getTag(), $entity->getTime(), $entity->getData()));
     }
 }
示例#2
0
 public function testWhole()
 {
     $time = time();
     $expected_data = array("abc" => "def");
     $entity = new Entity(self::TAG, $expected_data, $time);
     $this->assertEquals(self::TAG, $entity->getTag(), "unexpected tag `{$entity->getTag()}` returns.");
     $this->assertEquals($expected_data, $entity->getData(), "unexpected data returns");
     $this->assertEquals($time, $entity->getTime(), "unexpected time returns");
     $entity = new Entity(self::TAG, $expected_data);
     $this->assertGreaterThanOrEqual($time, $entity->getTime(), "unexpected time returns");
     $entity = new Entity(self::TAG, $expected_data, "not int");
     $this->assertGreaterThanOrEqual($time, $entity->getTime(), "unexpected time returns");
 }
示例#3
0
 public function pack(\Fluent\Logger\Entity $entity)
 {
     return serialize([$entity->getTag(), $entity->getTime(), $entity->getData()]);
 }