Ejemplo n.º 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 = AbstractValue::getXmlRpcValue($value->format('Ymd\\TH:i:s'), AbstractValue::XMLRPC_TYPE_DATETIME);
             } elseif ($value instanceof Base64) {
                 $value = AbstractValue::getXmlRpcValue($value->getDecoded(), AbstractValue::XMLRPC_TYPE_BASE64);
             } else {
                 $value = get_object_vars($value);
             }
         } elseif ($type === 'resource') {
             throw new InvalidTypeException($value);
         }
         array_shift($toBeVisited);
     }
     $request = new Request($method, $params);
     try {
         return $request->saveXml();
     } catch (\Exception $e) {
         throw new SerializerException($e->getMessage(), $e->getCode(), $e);
     }
 }
Ejemplo n.º 2
0
 /**
  * __construct() test
  */
 public function testConstructorOptionallySetsMethodAndParams()
 {
     $r = new Request();
     $this->assertEquals('', $r->getMethod());
     $this->assertEquals(array(), $r->getParams());
     $method = 'foo.bar';
     $params = array('baz', 1, array('foo' => 'bar'));
     $r = new Request($method, $params);
     $this->assertEquals($method, $r->getMethod());
     $this->assertEquals($params, $r->getParams());
 }
Ejemplo n.º 3
0
 /**
  * Perform an XML-RPC request and return a response.
  *
  * @param \Zend\XmlRpc\Request $request
  * @param null|\Zend\XmlRpc\Response $response
  * @return void
  * @throws \Zend\XmlRpc\Client\Exception\HttpException
  */
 public function doRequest($request, $response = null)
 {
     $this->lastRequest = $request;
     if (PHP_VERSION_ID < 50600) {
         iconv_set_encoding('input_encoding', 'UTF-8');
         iconv_set_encoding('output_encoding', 'UTF-8');
         iconv_set_encoding('internal_encoding', 'UTF-8');
     } else {
         ini_set('default_charset', 'UTF-8');
     }
     $http = $this->getHttpClient();
     $httpRequest = $http->getRequest();
     if ($httpRequest->getUriString() === null) {
         $http->setUri($this->serverAddress);
     }
     $headers = $httpRequest->getHeaders();
     $headers->addHeaders(array('Content-Type: text/xml; charset=utf-8', 'Accept: text/xml'));
     if (!$headers->get('user-agent')) {
         $headers->addHeaderLine('user-agent', 'Zend_XmlRpc_Client');
     }
     $xml = $this->lastRequest->__toString();
     $http->setRawBody($xml);
     $httpResponse = $http->setMethod('POST')->send();
     if (!$httpResponse->isSuccess()) {
         /**
          * Exception thrown when an HTTP error occurs
          */
         throw new Client\Exception\HttpException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode());
     }
     if ($response === null) {
         $response = new Response();
     }
     $this->lastResponse = $response;
     $this->lastResponse->loadXml(trim($httpResponse->getBody()));
 }
Ejemplo n.º 4
0
 public function testHandleFunction()
 {
     $this->_server->addFunction('ZendTest\\XmlRpc\\testFunction');
     $request = new Request();
     $request->setMethod('ZendTest\\XmlRpc\\testFunction');
     $request->setParams(array(array('value1'), 'key'));
     $response = $this->_server->handle($request);
     $this->assertFalse($response instanceof Fault);
     $this->assertEquals('key: value1', $response->getReturnValue());
 }
Ejemplo n.º 5
0
 /**
  * Handle an xmlrpc call (actual work)
  *
  * @param  Request $request
  * @return Response
  * @throws Server\Exception\RuntimeException
  * Zend\XmlRpc\Server\Exceptions are thrown for internal errors; otherwise,
  * any other exception may be thrown by the callback
  */
 protected function handleRequest(Request $request)
 {
     $method = $request->getMethod();
     // Check for valid method
     if (!$this->table->hasMethod($method)) {
         throw new Server\Exception\RuntimeException('Method "' . $method . '" does not exist', 620);
     }
     $info = $this->table->getMethod($method);
     $params = $request->getParams();
     $argv = $info->getInvokeArguments();
     if (0 < count($argv) and $this->sendArgumentsToAllMethods()) {
         $params = array_merge($params, $argv);
     }
     // Check calling parameters against signatures
     $matched = false;
     $sigCalled = $request->getTypes();
     $sigLength = count($sigCalled);
     $paramsLen = count($params);
     if ($sigLength < $paramsLen) {
         for ($i = $sigLength; $i < $paramsLen; ++$i) {
             $xmlRpcValue = AbstractValue::getXmlRpcValue($params[$i]);
             $sigCalled[] = $xmlRpcValue->getType();
         }
     }
     $signatures = $info->getPrototypes();
     foreach ($signatures as $signature) {
         $sigParams = $signature->getParameters();
         if ($sigCalled === $sigParams) {
             $matched = true;
             break;
         }
     }
     if (!$matched) {
         throw new Server\Exception\RuntimeException('Calling parameters do not match signature', 623);
     }
     $return = $this->_dispatch($info, $params);
     $responseClass = $this->getResponseClass();
     return new $responseClass($return);
 }
Ejemplo n.º 6
0
 /**
  * PingBackを送信
  */
 protected function sendPingBack()
 {
     $err = array();
     $links = array();
     // Wikiのソースのアドレスを取得
     if (preg_match_all('/(https?://[a-zA-Z0-9./~_]+)/', $wiki->get(), $links, PREG_PATTERN_ORDER) === false) {
         // ない場合そのままリターン
         return;
     }
     // 重複を削除
     $target_uris = array_unique($links[0]);
     foreach ($target_uris as $target_uri) {
         // 初期値
         $pingback = false;
         // ターゲットとなるURL接続
         $client = new Client($target_uri);
         // HEADメソッドで接続し、ヘッダーのみ取得
         $client->setMethod(Request::METHOD_HEAD);
         // 返り値を取得
         $response = $client->send();
         // アクセス失敗
         if (!$response->isSuccess()) {
             continue;
         }
         // 返り値のヘッダーからPingBackのURIを取得
         $pingback = $response->getHeaders()->get('x-pingback');
         // x-pingbackヘッダーがない場合(このへんの処理は重そう)
         if ($pingback === false) {
             try {
                 // GETでアクセスしてコンテンツを取得し、linkタグを探す。
                 $client->setMethod(Request::METHOD_GET);
                 // 返り値を取得
                 $response = $client->send();
                 // linkタグからPingBackのURIを取得
                 if (preg_match('<link rel="pingback" href="([^"]+)" ?/?>', $response->getBody(), $matches) !== false) {
                     $pingback = isset($matches[1]) ? $matches[1] : null;
                 }
             } catch (Exception $e) {
                 $err[] = $e;
             }
         }
         // PingBack送信先が見つからない場合スキップ
         if ($pingback === false) {
             continue;
         }
         unset($client, $response);
         // PingBackで送信する内容
         $request = new XmlRpcRequest();
         $request->setMethod('pingback.ping');
         $request->setParams(array($source_uri, $target_uri));
         // 例外を取得
         try {
             // PingBack送信先に接続
             $client = new XmlRpcClient($pingback);
             // 送信
             $client->doRequest($request);
         } catch (\Zend\XmlRpc\Client\Exception\FaultException $e) {
             $err[] = $e;
         }
         $err[] = '-----' . "\n";
         unset($client, $request);
     }
     return $err;
 }
Ejemplo n.º 7
0
 public function testShouldDisallowsDoctypeInRequestXmlAndReturnFalseOnLoading()
 {
     $payload = file_get_contents(dirname(__FILE__) . '/_files/ZF12293-request.xml');
     $payload = sprintf($payload, 'file://' . realpath(dirname(__FILE__) . '/_files/ZF12293-payload.txt'));
     $this->assertFalse($this->_request->loadXml($payload));
 }