Completed
Pull Request — master (#61)
by
unknown
01:33
created

Domain   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 30
lcom 1
cbo 5
dl 0
loc 178
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A setDomain() 0 7 2
A addAdminContact() 0 10 2
A addTechContact() 0 10 2
A addBillingContact() 0 10 2
A addHostObj() 0 14 3
A addHostAttr() 0 10 2
A addStatus() 0 14 3
A addSecDNSdsData() 0 14 2
A removeSecDNSdsData() 0 4 1
A removeSecDNSAll() 0 4 2
A removeAdminContact() 0 4 1
A removeTechContact() 0 4 1
A removeBillingContact() 0 4 1
A removeHostObj() 0 4 1
A removeHostAttr() 0 4 1
A removeStatus() 0 4 1
A changeRegistrant() 0 4 1
A changeAuthInfo() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of the php-epp2 library.
5
 *
6
 * (c) Gunter Grodotzki <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace AfriCC\EPP\Frame\Command\Update;
13
14
use AfriCC\EPP\AddrTrait;
15
use AfriCC\EPP\Frame\Command\Update as UpdateCommand;
16
use AfriCC\EPP\ObjectSpec;
17
use AfriCC\EPP\Random;
18
use AfriCC\EPP\Validator;
19
use Exception;
20
21
/**
22
 * @see http://tools.ietf.org/html/rfc5731#section-3.2.5
23
 */
24
class Domain extends UpdateCommand
25
{
26
    use AddrTrait;
27
28
    public function setDomain($domain)
29
    {
30
        if (!Validator::isHostname($domain)) {
31
            throw new Exception(sprintf('%s is not a valid domain name', $domain));
32
        }
33
        $this->set('domain:name', $domain);
34
    }
35
36
    public function addAdminContact($contact, $remove = false)
37
    {
38
        if ($remove) {
39
            $key = 'rem';
40
        } else {
41
            $key = 'add';
42
        }
43
44
        $this->set(sprintf('domain:%s/domain:contact[@type=\'admin\']', $key), $contact);
45
    }
46
47
    public function addTechContact($contact, $remove = false)
48
    {
49
        if ($remove) {
50
            $key = 'rem';
51
        } else {
52
            $key = 'add';
53
        }
54
55
        $this->set(sprintf('domain:%s/domain:contact[@type=\'tech\']', $key), $contact);
56
    }
57
58
    public function addBillingContact($contact, $remove = false)
59
    {
60
        if ($remove) {
61
            $key = 'rem';
62
        } else {
63
            $key = 'add';
64
        }
65
66
        $this->set(sprintf('domain:%s/domain:contact[@type=\'billing\']', $key), $contact);
67
    }
68
69
    public function addHostObj($host, $remove = false)
70
    {
71
        if (!Validator::isHostname($host)) {
72
            throw new Exception(sprintf('%s is not a valid host name', $host));
73
        }
74
75
        if ($remove) {
76
            $key = 'rem';
77
        } else {
78
            $key = 'add';
79
        }
80
81
        $this->set(sprintf('domain:%s/domain:ns/domain:hostObj[]', $key), $host);
82
    }
83
84
    public function addHostAttr($host, $ips = null, $remove = false)
85
    {
86
        if ($remove) {
87
            $key = 'rem';
88
        } else {
89
            $key = 'add';
90
        }
91
92
        $this->appendHostAttr(sprintf('domain:%s/domain:ns/domain:hostAttr[%%d]', $key), $host, $ips);
93
    }
94
95
    public function addStatus($status, $text, $remove = false)
96
    {
97
        if ($remove) {
98
            $key = 'rem';
99
        } else {
100
            $key = 'add';
101
        }
102
103
        $node = $this->set(sprintf('domain:%s/domain:status[@s=\'%s\']', $key, $status));
104
        if (!empty($text)) {
105
            $node->setAttribute('lang', 'en');
106
            $node->nodeValue = $text;
107
        }
108
    }
109
    
110
    /**
111
     * Add/remove SecDNS dsData - RFC 5910
112
     *
113
     * @param int $keyTag
114
     * @param int $alg
115
     * @param int $digestType
116
     * @param string $digest
117
     * @param bool $remove whether to remove or add (default add)
118
     */
119
    public function addSecDNSdsData($keyTag, $alg, $digestType, $digest, $remove = false)
120
    {
121
        $key = $remove ? 'rem' : 'add';
122
        $node = $this->set(sprintf('//epp:epp/epp:command/epp:extension/secDNS:update/secDNS:%s/secDNS:dsData[]', $key));
123
        $ns = ObjectSpec::xmlns('secDNS');
124
        $keyTagNode = $this->createElementNS($ns, 'secDNS:keyTag', $keyTag);
125
        $algNode = $this->createElementNS($ns, 'secDNS:alg', $alg);
126
        $digestTypeNode = $this->createElementNS($ns, 'secDNS:digestType', $digestType);
127
        $digestNode = $this->createElementNS($ns, 'secDNS:digest', $digest);
128
        $node->appendChild($keyTagNode);
129
        $node->appendChild($algNode);
130
        $node->appendChild($digestTypeNode);
131
        $node->appendChild($digestNode);
132
    }
133
    
134
    /**
135
     * Add/remove SecDNS dsData - RFC 5910
136
     *
137
     * @param int $keyTag
138
     * @param int $alg
139
     * @param int $digestType
140
     * @param string $digest
141
     */
142
    public function removeSecDNSdsData($keyTag, $alg, $digestType, $digest)
143
    {
144
        $this->addSecDNSdsData($keyTag, $alg, $digestType, $digest, true);
145
    }
146
    
147
    /**
148
     * Remove all secDNS data - RFC 5910
149
     * @param boolean $all - whether to remove ALL (true) or do nothing (false)
150
     */
151
    public function removeSecDNSAll($all = true)
152
    {
153
        $this->set('//epp:epp/epp:command/epp:extension/secDNS:update/secDNS:rem/secDNS:all', $all ? 'true': 'false');
154
    }
155
156
    public function removeAdminContact($contact)
157
    {
158
        $this->addAdminContact($contact, true);
159
    }
160
161
    public function removeTechContact($contact)
162
    {
163
        $this->addTechContact($contact, true);
164
    }
165
166
    public function removeBillingContact($contact)
167
    {
168
        $this->addBillingContact($contact, true);
169
    }
170
171
    public function removeHostObj($host)
172
    {
173
        $this->addHostObj($host, true);
174
    }
175
176
    public function removeHostAttr($host, $ips = null)
177
    {
178
        $this->addHostAttr($host, $ips, true);
179
    }
180
181
    public function removeStatus($status)
182
    {
183
        $this->addStatus($status, null, true);
184
    }
185
186
    public function changeRegistrant($registrant)
187
    {
188
        $this->set('domain:chg/domain:registrant', $registrant);
189
    }
190
191
    public function changeAuthInfo($pw = null)
192
    {
193
        if ($pw === null) {
194
            $pw = Random::auth(12);
195
        }
196
197
        $this->set('domain:chg/domain:authInfo/domain:pw', $pw);
198
199
        return $pw;
200
    }
201
}
202