コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function serialize($method, array $params = [])
 {
     $toBeVisited = [&$params];
     while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
         $type = gettype($value);
         if ($type === 'array') {
             // Zend converts non-zero-indexed arrays to structs
             if (array_keys($value) !== range(0, count($value) - 1) && array_keys($value) == range(1, count($value))) {
                 $value = array_values($value);
             }
             foreach ($value as &$child) {
                 $toBeVisited[] =& $child;
             }
         } elseif ($type === 'object') {
             if ($value instanceof \DateTime) {
                 $value = \Zend_XmlRpc_Value::getXmlRpcValue($value->format('Ymd\\TH:i:s'), \Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME);
             } elseif ($value instanceof Base64) {
                 $value = \Zend_XmlRpc_Value::getXmlRpcValue($value->getDecoded(), \Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64);
             } else {
                 $value = get_object_vars($value);
             }
         } elseif ($type === 'resource') {
             throw new InvalidTypeException($value);
         }
         array_shift($toBeVisited);
     }
     $request = new \Zend_XmlRpc_Request($method, $params);
     try {
         return $request->saveXml();
     } catch (\Exception $e) {
         throw new SerializerException($e->getMessage(), $e->getCode(), $e);
     }
 }
コード例 #2
0
ファイル: RequestTest.php プロジェクト: navassouza/zf2
 /**
  * testSaveXML() test
  */
 public function testSaveXML()
 {
     $argv = array('string', true);
     $this->_request->setMethod('do.Something');
     $this->_request->setParams($argv);
     $xml = $this->_request->saveXml();
     $this->_testXmlRequest($xml, $argv);
 }
コード例 #3
0
$serializer = null;
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $request = new Zend\XmlRpc\Request();
    $request->setMethod('test');
    $request->setParams($args);
    $r = $request->saveXml();
}
$end = microtime(true);
printf("Zend\\XmlRpc\\Request (ZF2): %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $request = new Zend_XmlRpc_Request();
    $request->setMethod('test');
    $request->setParams($args);
    $r = $request->saveXml();
}
$end = microtime(true);
printf("Zend_XmlRpc_Request (ZF1): %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $serializer = new fXmlRpc\Serializer\XmlWriterSerializer();
    $r = $serializer->serialize('test', $args);
}
$end = microtime(true);
printf("fXmlRpc\\Serializer\\XmlWriterSerializer: %s sec for %d passes\n", $end - $start, $limit);
$start = microtime(true);
for ($a = 0; $a < $limit; ++$a) {
    $serializer = new fXmlRpc\Serializer\NativeSerializer();
    $r = $serializer->serialize('test', $args);
}