cloudflare/Cloudflare-Magento
Publicmirrored fromhttps://github.com/cloudflare/Cloudflare-Magento
Backend/ClientActions.php
58lines · modecode
| 1 | <?php |
| 2 | |
| 3 | namespace CloudFlare\Plugin\Backend; |
| 4 | |
| 5 | use \CF\Integration\DefaultIntegration; |
| 6 | use \CF\API\APIInterface; |
| 7 | use \CF\API\Request; |
| 8 | |
| 9 | class ClientActions |
| 10 | { |
| 11 | protected $api; |
| 12 | protected $config; |
| 13 | protected $integrationAPI; |
| 14 | protected $dataStore; |
| 15 | protected $logger; |
| 16 | protected $request; |
| 17 | |
| 18 | /** |
| 19 | * @param DefaultIntegration $magentoIntegration |
| 20 | * @param APIInterface $api |
| 21 | * @param Request $request |
| 22 | */ |
| 23 | public function __construct(DefaultIntegration $magentoIntegration, APIInterface $api, Request $request) { |
| 24 | $this->api = $api; |
| 25 | $this->config = $magentoIntegration->getConfig(); |
| 26 | $this->integrationAPI = $magentoIntegration->getIntegrationAPI(); |
| 27 | $this->dataStore = $magentoIntegration->getDataStore(); |
| 28 | $this->logger = $magentoIntegration->getLogger(); |
| 29 | $this->request = $request; |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * GET /zones |
| 34 | * |
| 35 | * To ensure the plugin can only be used to manage the current Magento installation we |
| 36 | * hook on this call to only return a list of size one of the current domain. |
| 37 | */ |
| 38 | public function getZonesReturnMagentoZone() { |
| 39 | $magentoDomainName = $this->integrationAPI->getMagentoDomainName(); |
| 40 | $this->request->setParameters(array('name' => $magentoDomainName)); |
| 41 | |
| 42 | $response = $this->api->callAPI($this->request); |
| 43 | |
| 44 | if($this->api->responseOk($response)) { |
| 45 | if(count($response["result"] === 0 )) { |
| 46 | array_push($response["result"], array( |
| 47 | 'name' => $magentoDomainName, |
| 48 | 'plan' => array('name' => ''), |
| 49 | 'type' => '', |
| 50 | 'status' => 'inactive', |
| 51 | ) |
| 52 | ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return $response; |
| 57 | } |
| 58 | } |