cb8910e66ab8e77accff33d3c939bc5f332dde74
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 namespace PayPal\Transport;
3 use PayPal\Core\PPLoggingManager;
4 use PayPal\Core\PPHttpConfig;
5 use PayPal\Core\PPHttpConnection;
6 class PPRestCall {
7
8         
9         /**
10          * 
11          * @var PPLoggingManager logger interface
12          */
13         private $logger;
14         
15         private $apiContext;
16
17         public function __construct($apiContext) {
18                 $this->apiContext = $apiContext;
19                 $this->logger = new PPLoggingManager(__CLASS__, $apiContext->getConfig());
20         }
21
22         /**
23          * @param array $handlers array of handlers
24          * @param string $path   Resource path relative to base service endpoint
25          * @param string $method HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
26          * @param string $data   Request payload
27          * @param array $headers HTTP headers
28          */
29         public function execute($handlers, $path, $method, $data='', $headers=array()) {
30
31                 $config = $this->apiContext->getConfig();               
32                 $httpConfig = new PPHttpConfig(null, $method);
33                 $httpConfig->setHeaders($headers + 
34                         array(
35                                 'Content-Type' => 'application/json'
36                         )       
37                 );
38                 
39                 foreach($handlers as $handler) {
40                         $handler = new $handler($this->apiContext);
41                         $handler->handle($httpConfig, $data, array('path' => $path));
42                 }
43                 $connection = new PPHttpConnection($httpConfig, $config);
44                 $response = $connection->execute($data);
45                 $this->logger->fine($response);
46                 
47                 return $response;
48         }
49         
50 }