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

Future::setPeriod()   A

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
namespace AfriCC\EPP\Extension\NASK\Create;
3
4
use AfriCC\EPP\Frame\Command\Create as CreateCommand;
5
use AfriCC\EPP\PeriodTrait;
6
use AfriCC\EPP\Random;
7
use AfriCC\EPP\Validator;
8
use Exception;
9
10
class Future extends CreateCommand
11
{
12
    use PeriodTrait;
13
14
    /**
15
     * Set domain name for future (option)
16
     *
17
     * @param string $domain Domain Name
18
     * @throws Exception on incorrect domain name
19
     */
20
    public function setFuture($domain)
21
    {
22
        if (!Validator::isHostname($domain)) {
23
            throw new Exception(sprintf('%s is not a valid domain name', $domain));
24
        }
25
26
        $this->set('future:name', $domain);
27
    }
28
29
    /**
30
     * Set future period
31
     *
32
     * Set period for which to create Future. Usually that will be 3y
33
     *
34
     * @param string $period Period ending with with y or m
35
     */
36
    public function setPeriod($period)
37
    {
38
        $this->appendPeriod('future:period[@unit=\'%s\']', $period);
39
    }
40
41
    /**
42
     * Set future registrant
43
     *
44
     * @param string $registrant registrant ContactID
45
     */
46
    public function setRegistrant($registrant)
47
    {
48
        $this->set('future:registrant', $registrant);
49
    }
50
51
    /**
52
     * Set future AuthInfo, generate if passed null
53
     *
54
     * @param string $pw AuthInfo code
55
     * @return string  AuthInfo code
56
     */
57
    public function setAuthInfo($pw = null)
58
    {
59
        if ($pw === null) {
60
            $pw = Random::auth(12);
61
        }
62
63
        $this->set('future:authInfo/future:pw', $pw);
64
65
        return $pw;
66
    }
67
}
68
69