Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Partners.php
Go to the documentation of this file.
1 <?php
7 
11 
16 class Partners
17 {
21  protected $curlClient;
22 
26  protected $urlPrefix = 'https://';
27 
31  protected $apiUrl = 'magento.com/magento-connect/platinumpartners/list';
32 
36  protected $cache;
37 
43  public function __construct(Curl $curl, Cache $cache, UrlInterface $backendUrl)
44  {
45  $this->curlClient = $curl;
46  $this->cache = $cache;
47  $this->backendUrl = $backendUrl;
48  }
49 
53  public function getApiUrl()
54  {
55  return $this->urlPrefix . $this->apiUrl;
56  }
57 
63  public function getPartners()
64  {
65  $apiUrl = $this->getApiUrl();
66  try {
67  $this->getCurlClient()->post($apiUrl, []);
68  $this->getCurlClient()->setOptions(
69  [
70  CURLOPT_REFERER => $this->getReferer()
71  ]
72  );
73  $response = json_decode($this->getCurlClient()->getBody(), true);
74  if ($response['partners']) {
75  $this->getCache()->savePartnersToCache($response['partners']);
76  return $response['partners'];
77  } else {
78  return $this->getCache()->loadPartnersFromCache();
79  }
80  } catch (\Exception $e) {
81  return $this->getCache()->loadPartnersFromCache();
82  }
83  }
84 
88  public function getCurlClient()
89  {
90  return $this->curlClient;
91  }
92 
96  public function getCache()
97  {
98  return $this->cache;
99  }
100 
104  public function getReferer()
105  {
106  return \Magento\Framework\App\Request\Http::getUrlNoScript($this->backendUrl->getBaseUrl())
107  . 'admin/marketplace/index/index';
108  }
109 }
$response
Definition: 404.php:11
__construct(Curl $curl, Cache $cache, UrlInterface $backendUrl)
Definition: Partners.php:43