Example #1
0
 public function parse_list($response)
 {
     if ($response === "N;") {
         throw new Exception("Invalid data");
     }
     $result = array();
     foreach (unserialize($response) as $re) {
         $obj = new self();
         $obj->language($re["language"]);
         $obj->id($re["id"]);
         $obj->url($re["url"]);
         $obj->title($re["title"]);
         $obj->body($re["body"]);
         $obj->length($re["length"]);
         $obj->redirect($re["redirect"]);
         $obj->strict($re["strict"]);
         $obj->datetime($re["datetime"]);
         $result[] = $obj;
     }
     return $result;
 }
Example #2
0
 /**
  * Run a self test of the Zmsg class.
  *
  * @return boolean
  * @todo See if assert returns
  */
 public static function test()
 {
     $result = true;
     $context = new ZMQContext();
     $output = new ZMQSocket($context, ZMQ::SOCKET_DEALER);
     $output->bind("inproc://zmsg_selftest");
     $input = new ZMQSocket($context, ZMQ::SOCKET_ROUTER);
     $input->connect("inproc://zmsg_selftest");
     //  Test send and receive of single-part message
     $zmsgo = new self($output);
     $zmsgo->body_set("Hello");
     $result &= assert($zmsgo->body() == "Hello");
     $zmsgo->send();
     $zmsgi = new self($input);
     $zmsgi->recv();
     $result &= assert($zmsgi->parts() == 2);
     $result &= assert($zmsgi->body() == "Hello");
     echo $zmsgi;
     //  Test send and receive of multi-part message
     $zmsgo = new self($output);
     $zmsgo->body_set("Hello");
     $zmsgo->wrap("address1", "");
     $zmsgo->wrap("address2");
     $result &= assert($zmsgo->parts() == 4);
     echo $zmsgo;
     $zmsgo->send();
     $zmsgi = new self($input);
     $zmsgi->recv();
     $result &= assert($zmsgi->parts() == 5);
     $zmsgi->unwrap();
     $result &= assert($zmsgi->unwrap() == "address2");
     $zmsgi->body_fmt("%s%s", 'W', "orld");
     $result &= assert($zmsgi->body() == "World");
     //  Pull off address 1, check that empty part was dropped
     $zmsgi->unwrap();
     $result &= assert($zmsgi->parts() == 1);
     //  Check that message body was correctly modified
     $part = $zmsgi->pop();
     $result &= assert($part == "World");
     $result &= assert($zmsgi->parts() == 0);
     // Test load and save
     $zmsg = new self();
     $zmsg->body_set("Hello");
     $zmsg->wrap("address1", "");
     $zmsg->wrap("address2");
     $result &= assert($zmsg->parts() == 4);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'w');
     $zmsg->save($fh);
     fclose($fh);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'r');
     $zmsg2 = new self();
     $zmsg2->load($fh);
     assert($zmsg2->last() == $zmsg->last());
     fclose($fh);
     $result &= assert($zmsg2->parts() == 4);
     echo $result ? "OK" : "FAIL", PHP_EOL;
     return $result;
 }