CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Backend/ClientActions.php

68lines · modecode

1<?php
2
3namespace CloudFlare\Plugin\Backend;
4
5use \CF\Integration\DefaultIntegration;
6use \CF\API\APIInterface;
7use \CF\API\Request;
8
9class 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 {
25 $this->api = $api;
26 $this->config = $magentoIntegration->getConfig();
27 $this->integrationAPI = $magentoIntegration->getIntegrationAPI();
28 $this->dataStore = $magentoIntegration->getDataStore();
29 $this->logger = $magentoIntegration->getLogger();
30 $this->request = $request;
31 }
32
33 /*
34 * GET /zones
35 *
36 * To ensure the plugin can only be used to manage the current Magento installation we
37 * hook on this call to only return a list of size one of the current domain.
38 */
39 public function getZonesReturnMagentoZone()
40 {
41 $magentoDomainName = $this->integrationAPI->getMagentoDomainName();
42
43 $response = $this->api->callAPI($this->request);
44 if ($this->api->responseOk($response)) {
45 $magentoZone = null;
46 $bestMatch = strlen($magentoDomainName);
47 foreach ($response['result'] as $zone) {
48 $firstOccurrence = strpos($magentoDomainName, $zone['name']);
49 if ($firstOccurrence !== false && $firstOccurrence < $bestMatch) {
50 $bestMatch = $firstOccurrence;
51 $magentoZone = $zone;
52 }
53 }
54 if ($magentoZone === null) {
55 $this->logger->warning($magentoDomainName . 'doesn\'t appear to be provisioned on CloudFlare.com.');
56 $magentoZone = array(
57 'name' => $magentoDomainName,
58 'plan' => array('name' => ''),
59 'type' => '',
60 'status' => 'inactive',
61 );
62 }
63 $response['result'] = array($magentoZone);
64 }
65
66 return $response;
67 }
68}