/**
  * {@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);
     }
 }
Exemple #2
0
 protected function getResponse($value, $type, $login = false)
 {
     $valueObject = \Zend\XmlRpc\AbstractValue::getXmlRpcValue($value, $type);
     $content = '<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param>' . $valueObject->saveXml() . '</param></params></methodResponse>';
     $this->debug("XML: " . $content);
     $response = new \Symfony\Component\HttpFoundation\Response();
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($content);
     $response->setPrivate();
     $response->setMaxAge(100);
     $user = $this->userManager->getCurrentUser();
     if ($user->getSymbbType() === 'user') {
         $response->headers->set('Mobiquo_is_login', "true");
     } else {
         $response->headers->set('Mobiquo_is_login', false);
     }
     return $response;
 }
Exemple #3
0
 /**
  * Send an XML-RPC request to the service (for a specific method)
  *
  * @param  string $method Name of the method we want to call
  * @param  array $params Array of parameters for the method
  * @return mixed
  * @throws \Zend\XmlRpc\Client\Exception\FaultException
  */
 public function call($method, $params = array())
 {
     if (!$this->skipSystemLookup() && 'system.' != substr($method, 0, 7)) {
         // Ensure empty array/struct params are cast correctly
         // If system.* methods are not available, bypass. (ZF-2978)
         $success = true;
         try {
             $signatures = $this->getIntrospector()->getMethodSignature($method);
         } catch (\Zend\XmlRpc\Exception\ExceptionInterface $e) {
             $success = false;
         }
         if ($success) {
             $validTypes = array(AbstractValue::XMLRPC_TYPE_ARRAY, AbstractValue::XMLRPC_TYPE_BASE64, AbstractValue::XMLRPC_TYPE_BOOLEAN, AbstractValue::XMLRPC_TYPE_DATETIME, AbstractValue::XMLRPC_TYPE_DOUBLE, AbstractValue::XMLRPC_TYPE_I4, AbstractValue::XMLRPC_TYPE_INTEGER, AbstractValue::XMLRPC_TYPE_NIL, AbstractValue::XMLRPC_TYPE_STRING, AbstractValue::XMLRPC_TYPE_STRUCT);
             if (!is_array($params)) {
                 $params = array($params);
             }
             foreach ($params as $key => $param) {
                 if ($param instanceof AbstractValue) {
                     continue;
                 }
                 if (count($signatures) > 1) {
                     $type = AbstractValue::getXmlRpcTypeByValue($param);
                     foreach ($signatures as $signature) {
                         if (!is_array($signature)) {
                             continue;
                         }
                         if (isset($signature['parameters'][$key])) {
                             if ($signature['parameters'][$key] == $type) {
                                 break;
                             }
                         }
                     }
                 } elseif (isset($signatures[0]['parameters'][$key])) {
                     $type = $signatures[0]['parameters'][$key];
                 } else {
                     $type = null;
                 }
                 if (empty($type) || !in_array($type, $validTypes)) {
                     $type = AbstractValue::AUTO_DETECT_TYPE;
                 }
                 $params[$key] = AbstractValue::getXmlRpcValue($param, $type);
             }
         }
     }
     $request = $this->_createRequest($method, $params);
     $this->doRequest($request);
     if ($this->lastResponse->isFault()) {
         $fault = $this->lastResponse->getFault();
         /**
          * Exception thrown when an XML-RPC fault is returned
          */
         throw new Client\Exception\FaultException($fault->getMessage(), $fault->getCode());
     }
     return $this->lastResponse->getReturnValue();
 }
Exemple #4
0
 /**
  * Test encoding settings
  */
 public function testSetGetEncoding()
 {
     $this->assertEquals('UTF-8', $this->_request->getEncoding());
     $this->assertEquals('UTF-8', AbstractValue::getGenerator()->getEncoding());
     $this->assertSame($this->_request, $this->_request->setEncoding('ISO-8859-1'));
     $this->assertEquals('ISO-8859-1', $this->_request->getEncoding());
     $this->assertEquals('ISO-8859-1', AbstractValue::getGenerator()->getEncoding());
 }
Exemple #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);
 }
Exemple #6
0
 /**
  * Create XML request
  *
  * @return string
  */
 public function saveXml()
 {
     $args = $this->_getXmlRpcParams();
     $method = $this->getMethod();
     $generator = AbstractValue::getGenerator();
     $generator->openElement('methodCall')->openElement('methodName', $method)->closeElement('methodName');
     if (is_array($args) && count($args)) {
         $generator->openElement('params');
         foreach ($args as $arg) {
             $generator->openElement('param');
             $arg->generateXml();
             $generator->closeElement('param');
         }
         $generator->closeElement('params');
     }
     $generator->closeElement('methodCall');
     return $generator->flush();
 }
 /**
  * @group ZF-6445
  */
 public function testMarshalBigIntegerFromNative()
 {
     $bigIntegerValue = (string) (PHP_INT_MAX + 42);
     $value = AbstractValue::getXmlRpcValue($bigIntegerValue, AbstractValue::XMLRPC_TYPE_I8);
     $this->assertEquals(AbstractValue::XMLRPC_TYPE_I8, $value->getType());
     $this->assertSame($bigIntegerValue, $value->getValue());
 }
 /**
  * Return response as XML
  *
  * @return string
  */
 public function saveXml()
 {
     $value = $this->_getXmlRpcReturn();
     $generator = AbstractValue::getGenerator();
     $generator->openElement('methodResponse')->openElement('params')->openElement('param');
     $value->generateXml();
     $generator->closeElement('param')->closeElement('params')->closeElement('methodResponse');
     return $generator->flush();
 }
Exemple #9
0
 public function testGetXmlRpcTypeByValueThrowsExceptionOnInvalidValue()
 {
     $this->setExpectedException('Zend\\XmlRpc\\Exception\\InvalidArgumentException');
     AbstractValue::getXmlRpcTypeByValue(fopen(__FILE__, 'r'));
 }
Exemple #10
0
 /**
  * @group ZF-8074
  */
 public function testXmlRpcObjectsAreNotConverted()
 {
     $this->mockIntrospector();
     $this->mockedIntrospector->expects($this->exactly(1))->method('getMethodSignature')->with('date.method')->will($this->returnValue(array(array('parameters' => array('dateTime.iso8601', 'string')))));
     $expects = 'date.method response';
     $this->setServerResponseTo($expects);
     $this->assertSame($expects, $this->xmlrpcClient->call('date.method', array(AbstractValue::getXmlRpcValue(time(), AbstractValue::XMLRPC_TYPE_DATETIME), 'foo')));
 }
Exemple #11
0
 /**
  * Serialize fault to XML
  *
  * @return string
  */
 public function saveXml()
 {
     // Create fault value
     $faultStruct = array('faultCode' => $this->getCode(), 'faultString' => $this->getMessage());
     $value = AbstractValue::getXmlRpcValue($faultStruct);
     $generator = AbstractValue::getGenerator();
     $generator->openElement('methodResponse')->openElement('fault');
     $value->generateXml();
     $generator->closeElement('fault')->closeElement('methodResponse');
     return $generator->flush();
 }