CodeCommitsIssuesPull requestsActionsInsightsSecurity
06ab6cb9fb45560acfd72cf02ad4ea21d9e164e9

Branches

Tags

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

Clone

HTTPS

Download ZIP

Backend/DataStore.php

106lines · modecode

1<?php
2namespace CloudFlare\Plugin\Backend;
3
4use \CF\Integration\DataStoreInterface;
5
6class DataStore implements DataStoreInterface
7{
8 protected $magentoAPI;
9
10 const CLIENT_API_KEY = "clientApiKey";
11 const CLOUDFLARE_EMAIL = "cloudflareEmail";
12 const ZONE_ID_KEY = "zoneId:";
13
14 public function __construct(MagentoAPI $magentoAPI)
15 {
16 $this->magentoAPI = $magentoAPI;
17 }
18
19 /**
20 * @param $clientAPIKey
21 * @param $email
22 * @param $uniqueId
23 * @param $userKey
24 * @return mixed
25 * @internal param $client_api_key
26 * @internal param $unique_id
27 * @internal param $user_key
28 */
29 public function createUserDataStore($clientAPIKey, $email, $uniqueId, $userKey)
30 {
31 //Magento doesn't use the host api - $uniqueId, $userKey will always be null
32 $this->set(self::CLIENT_API_KEY, $clientAPIKey);
33 $this->set(self::CLOUDFLARE_EMAIL, $email);
34 return true;
35 }
36
37 /**
38 * @return mixed
39 */
40 public function getHostAPIUserUniqueId()
41 {
42 return null;
43 }
44
45 /**
46 * @return mixed
47 */
48 public function getClientV4APIKey()
49 {
50 return $this->get(self::CLIENT_API_KEY);
51 }
52
53 /**
54 * @return mixed
55 */
56 public function getHostAPIUserKey()
57 {
58 return null;
59 }
60
61 /**
62 * @return mixed
63 */
64 public function getCloudFlareEmail()
65 {
66 return $this->get(self::CLOUDFLARE_EMAIL);
67 }
68
69 /**
70 * @param $domainName
71 * @return null
72 */
73 public function getZoneId($domainName)
74 {
75 return $this->get(self::ZONE_ID_KEY . $domainName);
76 }
77
78 /**
79 * @param $domainName
80 * @param $zoneId
81 * @return mixed
82 */
83 public function setZoneId($domainName, $zoneId)
84 {
85 return $this->set(self::ZONE_ID_KEY . $domainName, $zoneId);
86 }
87
88 /**
89 * @param $key
90 * @return mixed
91 */
92 public function get($key)
93 {
94 return json_decode($this->magentoAPI->getValue($key), true);
95 }
96
97 /**
98 * @param $key
99 * @param $value
100 * @return mixed
101 */
102 public function set($key, $value)
103 {
104 return $this->magentoAPI->setValue($key, json_encode($value));
105 }
106}