Completed
Push — master ( 461c20...02a675 )
by Chris
01:56
created

Cloudflare::getAPIKEY()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
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
    public function getEndpoint()
17
    {
18
        return $this->Endpoint;
19
    }
20
21
    public function getAPIKEY()
22
    {
23
        return $this->APIKEY;
24
    }
25
26
    public function getEmail()
27
    {
28
        return $this->Email;
29
    }
30
31
    public function getMakeRequests()
32
    {
33
        return $this->MakeRequests;
34
    }
35
36
    public function diableRequests()
37
    {
38
        $this->MakeRequests = false;
39
    }
40
41
    public function enableRequests()
42
    {
43
        $this->MakeRequests = true;
44
    }
45
46
    public function __construct($APIKEY = null, $Email = null)
47
    {
48
        if (is_null($APIKEY) || is_null($Email)) {
49
            $this->loadConfig();
50
        } else {
51
            $this->APIKEY = $APIKEY;
52
            $this->Email = $Email;
53
        }
54
    }
55
56
    private function loadConfig()
57
    {
58
        $config = 'Cloudflare.yml';
59
        $configDist = $config.'.dist';
60
        $dir = $_SERVER['DOCUMENT_ROOT'];
61
62
        if (@file_exists($dir . $config)) {
63
            $load = $config;
64
        } elseif (@file_exists($dir . $configDist)) {
65
            $load = $configDist;
66
        } else {
67
            die('Unable to load either "'.$config.'" or "'.$configDist.'"');
68
        }
69
70
        $config = Yaml::parse(file_get_contents($load));
71
72
        $this->APIKEY = $config['APIKEY'];
73
        $this->Email = $config['Email'];
74
    }
75
}
76