factory() public static method

public static factory ( $bindingType )
Beispiel #1
0
 public function makeRequest($apiMethod, $params, $apiUsername = null)
 {
     $this->apiMethod = $apiMethod;
     if (is_string($apiUsername) || is_null($apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($this->config);
         $apiCredential = clone $credMgr->getCredentialObject($apiUsername);
     } else {
         $apiCredential = $apiUsername;
         //TODO: Aargh
     }
     if (isset($this->config['accessToken']) && isset($this->config['tokenSecret'])) {
         $apiCredential->setThirdPartyAuthorization(new PPTokenAuthorization($this->config['accessToken'], $this->config['tokenSecret']));
     }
     $request = new PPRequest($params, $this->serviceBinding);
     $request->setCredential($apiCredential);
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     $this->runHandlers($httpConfig, $request);
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->config);
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
Beispiel #2
0
 /**
  * Execute an api call
  *
  * @param string    $apiMethod Name of the API operation (such as 'Pay')
  * @param PPRequest $params    Request object
  *
  * @return array containing request and response
  */
 public function makeRequest($apiMethod, $request)
 {
     $this->apiMethod = $apiMethod;
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     if ($this->apiContext->getHttpHeaders() != null) {
         $httpConfig->setHeaders($this->apiContext->getHttpHeaders());
     }
     $this->runHandlers($httpConfig, $request);
     // Serialize request object to a string according to the binding configuration
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     // Execute HTTP call
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->apiContext->getConfig());
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
 /**
  * @test
  */
 public function testInvalidBinding()
 {
     $this->setExpectedException('\\InvalidArgumentException');
     FormatterFactory::factory('Unknown');
 }