call() public method

public call ( $methodName, array $params = [] )
$params array
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $results = $this->client->call('system.multicall', [$this->calls]);
     foreach ($results as $index => $result) {
         $this->processResult($this->handlers[$index], $result);
     }
     return $results;
 }
Ejemplo n.º 2
0
 private function call($method = null, $parameters = array())
 {
     if (is_null($method)) {
         throw new InvalidArgumentException('No method');
     }
     if (!is_array($parameters)) {
         throw new InvalidArgumentException('Wrong parameters');
     }
     try {
         return $this->blog->call($method, $parameters);
     } catch (\fXmlRpc\Exception\HttpException $e) {
         throw new Exception('(HTTP) Communication failed. Is the remote URL correct?', null, $e);
     } catch (\fXmlRpc\Exception\InvalidArgumentException $e) {
         throw new Exception('Wrong argument', null, $e);
     } catch (\fXmlRpc\Exception\MissingExtensionException $e) {
         throw new Exception('Error: missing extension. Aborted', null, $e);
     } catch (\fXmlRpc\Exception\ResponseException $e) {
         throw new Exception('Wrong response', null, $e);
     } catch (\fXmlRpc\Exception\RuntimeException $e) {
         throw new \RuntimeException('Runtime error', null, $e);
     } catch (\fXmlRpc\Exception\SerializationException $e) {
         throw new Exception('Passed data are corrupted', null, $e);
     } catch (\fXmlRpc\Exception\TcpException $e) {
         throw new Exception('(TCP) Communication failed', null, $e);
     } catch (\fXmlRpc\Exception\TransportException $e) {
         throw new Exception('Communication failed', null, $e);
     }
 }
 /**
  * @inheritdoc
  */
 function invalidateSession($sessionId)
 {
     $this->client->prependParams(array($sessionId));
     try {
         $result = $this->client->call('ox.logoff', array());
         if ($result !== true) {
             throw new \InvalidArgumentException();
         }
     } catch (\fXmlRpc\Exception\FaultException $e) {
         if ($e->getFaultCode()) {
             throw new \InvalidArgumentException("Invalid sessionId");
         }
         throw new RepositoryInfrastructureException("Infrastructure exception.", 0, $e);
     } catch (\fXmlRpc\Exception\ExceptionInterface $e) {
         throw new RepositoryInfrastructureException("Infrastructure exception.", 0, $e);
     }
     return $result;
 }
 /**
  * @param string          $uri
  * @param string          $method
  * @param array           $params
  * @param ClientInterface $client
  * @return mixed|void
  * @throws HttpException
  */
 public function request($uri, $method, $params, ClientInterface $client)
 {
     // Although we are using fXmlRpc to handle the XML-RPC formatting, we
     // can still use Guzzle as our HTTP client which is much more robust.
     try {
         $transport = $client->getXmlRpcTransport();
         $client = new Client($uri, $transport);
         $response = $client->call($method, $params);
         return $response;
     } catch (fXmlRpcException $e) {
         throw new HttpException($e);
     }
 }
 /** @dataProvider getClientsOnly */
 public function testServerNotReachableViaTcpIp(Client $client)
 {
     $client->setUri('http://127.0.0.1:12345/');
     try {
         $client->call('system.failure');
         $this->fail('Exception expected');
     } catch (\fXmlRpc\Exception\TransportException $e) {
         $this->assertInstanceOf('fXmlRpc\\Exception\\TransportException', $e);
         $this->assertInstanceOf('fXmlRpc\\Exception\\ExceptionInterface', $e);
         $this->assertInstanceOf('RuntimeException', $e);
         $this->assertStringStartsWith('Transport error occurred:', $e->getMessage());
         $this->assertSame(0, $e->getCode());
     }
 }
Ejemplo n.º 6
0
 public function testIsLastResponseNotContainXmlFromPreviousRequest()
 {
     $this->transportOk($this->at(0));
     $this->transportFail($this->at(1));
     $this->client->call('TestMethod', ['param1', 2, ['param3' => true]]);
     $this->assertXmlStringEqualsXmlString($this->expectedRequest, $this->recorder->getLastRequest());
     $this->assertXmlStringEqualsXmlString($this->expectedResponse, $this->recorder->getLastResponse());
     try {
         $this->client->call('TestMethod', ['param1', 2, ['param3' => true]]);
     } catch (Exception $e) {
         $this->assertSame($this->exception, $e);
     }
     $lastRequest = $this->recorder->getLastRequest();
     $lastResponse = $this->recorder->getLastResponse();
     $lastException = $this->recorder->getLastException();
     $this->assertXmlStringEqualsXmlString($this->expectedRequest, $lastRequest);
     $this->assertNull($lastResponse);
     $this->assertSame($this->exception, $lastException);
 }
Ejemplo n.º 7
0
 public function testInvalidMethodName()
 {
     $this->setExpectedException('fXmlRpc\\Exception\\InvalidArgumentException', 'Expected parameter 0 to be of type "string", "object" of type "stdClass" given');
     $this->client->call(new \stdClass());
 }
 protected function executeSystemFailureTest(Client $client)
 {
     $client->setUri(static::$errorEndpoint);
     try {
         $client->call('system.failure');
         $this->fail('Exception expected');
     } catch (\fXmlRpc\Exception\HttpException $e) {
         $this->assertInstanceOf('fXmlRpc\\Exception\\AbstractTransportException', $e);
         $this->assertInstanceOf('fXmlRpc\\Exception\\ExceptionInterface', $e);
         $this->assertInstanceOf('RuntimeException', $e);
         $this->assertStringStartsWith('An HTTP error occurred', $e->getMessage());
         $this->assertSame(500, $e->getCode());
     }
 }
Ejemplo n.º 9
0
 /**
  * Invokes remote command
  *
  * @param string $method
  * @param array  $parameters
  *
  * @return mixed
  */
 public function __call($method, array $parameters)
 {
     return $this->client->call($this->prependNamespace($method), $parameters);
 }
Ejemplo n.º 10
0
 /**
  * @param $method
  * @param array $params
  * @return mixed
  */
 public function call($method, $params = array())
 {
     $this->lastRequest = array('method' => $method, 'params' => $params);
     $uri = $this->getHost() . ':' . $this->getPort() . $this->getPath();
     // Make the call through the fast-XmlRpc client.
     $client = new fXmlRpc\Client($uri);
     try {
         $response = $client->call($method, $params);
     } catch (RpcException\ResponseException $e) {
         // Get the details of the error, and pass it on.
         // We don't have a response, so can't return with anything sensible.
         // Here we just concatenate the faultCode and the faultString, since in practice both of
         // them seeto be string and either of them can contain the error message.
         // CHECKME: if we get $e->getFaultCode() == 'AccessDenied' then we have possibly
         // been logged out. It may be worth checking the authentication status and setting
         // the session as logged out. However, AccessDenied may be a more general error that
         // is applied to individual models and not just the whole login session. There will be
         // a way to check though.
         // TODO: store these error parts separately, so they are available later on.
         // Or maybe just don't catch it? Think it through.
         throw new RpcException\ResponseException(trim($e->getFaultCode() . ' ' . $e->getFaultString()), $e->getCode(), $e);
     }
     $this->lastRawResponse = $response;
     return $response;
 }
 /**
  * Ends the session if applicable.
  */
 public function __destruct()
 {
     if ($this->autoCloseSession && $this->client) {
         $this->client->call('endSession', array($this->getConfig('session')));
     }
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function call($methodName, array $arguments = [])
 {
     return $this->wrapped->call($methodName, $arguments);
 }
Ejemplo n.º 13
0
 /**
  * Calls XML_RPC Class
  *
  * @param string $method final endpoint of call
  * @param mixed  $args   variable length array
  *
  * @return mixed
  */
 function __call($method, $args)
 {
     $this->method = $method;
     $this->calledMethod = $this->getCompleteMethod();
     $callArray = array();
     if (GandiAPIMethodRequirements::isApiKeyRequired($this->calledMethod)) {
         $callArray[] = $this->getApiKey();
     }
     foreach ($args as $a) {
         $callArray[] = $a;
     }
     try {
         $guzzle = new \GuzzleHttp\Client(array('verify' => false));
         $transport = new Guzzle4Bridge($guzzle);
         $client = new Client($this->getUrl(), $transport);
         $apiResult = $client->call($this->getCompleteMethod(), $callArray);
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $apiResult = array();
         // @codeCoverageIgnoreEnd
     }
     return $apiResult;
 }