Domain::setAdminContact()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Create;
13
14
use AfriCC\EPP\AddrTrait;
15
use AfriCC\EPP\Frame\Command\Create as CreateCommand;
16
use AfriCC\EPP\PeriodTrait;
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.1
23
 */
24
class Domain extends CreateCommand
25
{
26
    use PeriodTrait, 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
34
        $this->set('domain:name', $domain);
35
    }
36
37
    public function setPeriod($period)
38
    {
39
        $this->appendPeriod('domain:period[@unit=\'%s\']', $period);
40
    }
41
42
    public function addHostObj($host)
43
    {
44
        if (!Validator::isHostname($host)) {
45
            throw new Exception(sprintf('%s is not a valid host name', $host));
46
        }
47
48
        $this->set('domain:ns/domain:hostObj[]', $host);
49
    }
50
51
    public function addHostAttr($host, $ips = null)
52
    {
53
        $this->appendHostAttr('domain:ns/domain:hostAttr[%d]', $host, $ips);
54
    }
55
56
    public function setRegistrant($registrant)
57
    {
58
        $this->set('domain:registrant', $registrant);
59
    }
60
61
    public function setAdminContact($admin_contact)
62
    {
63
        $this->set('domain:contact[@type=\'admin\']', $admin_contact);
64
    }
65
66
    public function setTechContact($tech_contact)
67
    {
68
        $this->set('domain:contact[@type=\'tech\']', $tech_contact);
69
    }
70
71
    public function setBillingContact($billing_contact)
72
    {
73
        $this->set('domain:contact[@type=\'billing\']', $billing_contact);
74
    }
75
76
    public function setAuthInfo($pw = null)
77
    {
78
        if ($pw === null) {
79
            $pw = Random::auth(12);
80
        }
81
82
        $this->set('domain:authInfo/domain:pw', $pw);
83
84
        return $pw;
85
    }
86
87
    /**
88
     * Add SecDNS dsData - RFC 5910
89
     *
90
     * @param int $keyTag
91
     * @param int $alg
92
     * @param int $digestType
93
     * @param string $digest
94
     */
95
    public function addSecDNSdsData($keyTag, $alg, $digestType, $digest)
96
    {
97
        $node = $this->set('//epp:epp/epp:command/epp:extension/secDNS:create/secDNS:dsData[]');
98
        $ns = $this->objectSpec->xmlns('secDNS');
99
        $keyTagNode = $this->createElementNS($ns, 'secDNS:keyTag', $keyTag);
100
        $algNode = $this->createElementNS($ns, 'secDNS:alg', $alg);
101
        $digestTypeNode = $this->createElementNS($ns, 'secDNS:digestType', $digestType);
102
        $digestNode = $this->createElementNS($ns, 'secDNS:digest', $digest);
103
        $node->appendChild($keyTagNode);
104
        $node->appendChild($algNode);
105
        $node->appendChild($digestTypeNode);
106
        $node->appendChild($digestNode);
107
    }
108
}
109