1 <?php
2 namespace PayPal\Transport;
3
4 use PayPal\Core\PayPalHttpConfig;
5 use PayPal\Core\PayPalHttpConnection;
6 use PayPal\Core\PayPalLoggingManager;
7 use PayPal\Rest\ApiContext;
8
9 10 11 12 13
14 class PayPalRestCall
15 {
16
17
18 19 20 21 22
23 private $logger;
24
25 26 27 28 29
30 private $apiContext;
31
32
33 34 35 36 37
38 public function __construct(ApiContext $apiContext)
39 {
40 $this->apiContext = $apiContext;
41 $this->logger = PayPalLoggingManager::getInstance(__CLASS__);
42 }
43
44 45 46 47 48 49 50 51 52
53 public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
54 {
55 $config = $this->apiContext->getConfig();
56 $httpConfig = new PayPalHttpConfig(null, $method, $config);
57 $headers = $headers ? $headers : array();
58 $httpConfig->setHeaders($headers +
59 array(
60 'Content-Type' => 'application/json'
61 )
62 );
63
64
65 if (!empty($config['http.Proxy'])) {
66 $httpConfig->setHttpProxy($config['http.Proxy']);
67 }
68
69
70 foreach ($handlers as $handler) {
71 if (!is_object($handler)) {
72 $fullHandler = "\\" . (string)$handler;
73 $handler = new $fullHandler($this->apiContext);
74 }
75 $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
76 }
77 $connection = new PayPalHttpConnection($httpConfig, $config);
78 $response = $connection->execute($data);
79
80 return $response;
81 }
82 }
83