Completed
Push — develop ( c97899...e1148a )
by Chris
05:11
created

Cloudflare::getEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @author Chris Hilsdon <[email protected]>
4
 */
5
namespace Cloudflare;
6
7
use Symfony\Component\Yaml\Yaml;
8
9
class Cloudflare
10
{
11
    protected $Endpoint = "https://api.cloudflare.com/client/v4/";
12
    protected $APIKEY;
13
    protected $Email;
14
    protected $MakeRequests = true;
15
16
    /**
17
     * Origin CA Key that is used to request SSL certificates
18
     * @var string
19
     */
20
    protected $originCAKey;
21
22
    public function getOriginCAKey()
23
    {
24
        return $this->originCAKey;
25
    }
26
27
    public function getEndpoint()
28
    {
29
        return $this->Endpoint;
30
    }
31
32
    public function getAPIKEY()
33
    {
34
        return $this->APIKEY;
35
    }
36
37
    public function getEmail()
38
    {
39
        return $this->Email;
40
    }
41
42
    public function getMakeRequests()
43
    {
44
        return $this->MakeRequests;
45
    }
46
47
    public function diableRequests()
48
    {
49
        $this->MakeRequests = false;
50
    }
51
52
    public function enableRequests()
53
    {
54
        $this->MakeRequests = true;
55
    }
56
57
    public function __construct($APIKEY = null, $Email = null, $key = null)
58
    {
59
        if (is_null($APIKEY) || is_null($Email)) {
60
            $this->loadConfig();
61
        } else {
62
            $this->APIKEY = $APIKEY;
63
            $this->Email = $Email;
64
            $this->originCAKey = $key;
65
        }
66
    }
67
68
    private function loadConfig()
69
    {
70
        $config = 'Cloudflare.yml';
71
        $configDist = $config.'.dist';
72
        $dir = $_SERVER['DOCUMENT_ROOT'];
73
74
        if (@file_exists($dir . $config)) {
75
            $load = $config;
76
        } elseif (@file_exists($dir . $configDist)) {
77
            $load = $configDist;
78
        } else {
79
            throw new \Exception('Unable to load either "'.$config.'" or "'.$configDist.'"', 1);
80
        }
81
82
        $config = Yaml::parse(file_get_contents($load));
83
84
        $this->APIKEY = $config['APIKEY'];
85
        $this->Email = $config['Email'];
86
    }
87
}
88