Completed
Push — master ( 1d13ba...f9bf31 )
by Sam
49:13
created

SOA::outputFormatted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Badcow DNS Library.
5
 *
6
 * (c) Samuel Williams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Badcow\DNS\Rdata;
13
14
use Badcow\DNS\ResourceRecord;
15
use Badcow\DNS\Validator;
16
17
/**
18
 * @link http://www.ietf.org/rfc/rfc1035.text
19
 */
20
class SOA implements RdataInterface, FormattableInterface
21
{
22
    use RdataTrait, FormattableTrait;
23
24
    const TYPE = 'SOA';
25
26
    /**
27
     * The <domain-name> of the name server that was the
28
     * original or primary source of data for this zone.
29
     *
30
     * @var string
31
     */
32
    private $mname;
33
34
    /**
35
     * A <domain-name> which specifies the mailbox of the
36
     * person responsible for this zone.
37
     *
38
     * @var string
39
     */
40
    private $rname;
41
42
    /**
43
     * The unsigned 32 bit version number of the original copy
44
     * of the zone.
45
     *
46
     * @var int
47
     */
48
    private $serial;
49
50
    /**
51
     * A 32 bit time interval before the zone should be
52
     * refreshed.
53
     *
54
     * @var int
55
     */
56
    private $refresh;
57
58
    /**
59
     * A 32 bit time interval that should elapse before a
60
     * failed refresh should be retried.
61
     *
62
     * @var int
63
     */
64
    private $retry;
65
66
    /**
67
     * A 32 bit time value that specifies the upper limit on
68
     * the time interval that can elapse before the zone is no
69
     * longer authoritative.
70
     *
71
     * @var int
72
     */
73
    private $expire;
74
75
    /**
76
     * The unsigned 32 bit minimum TTL field that should be
77
     * exported with any RR from this zone.
78
     *
79
     * @var int
80
     */
81
    private $minimum;
82
83
    /**
84
     * @param $expire
85
     */
86
    public function setExpire($expire)
87
    {
88
        $this->expire = (int) $expire;
89
    }
90
91
    /**
92
     * @return int
93
     */
94
    public function getExpire()
95
    {
96
        return $this->expire;
97
    }
98
99
    /**
100
     * @param $minimum
101
     */
102
    public function setMinimum($minimum)
103
    {
104
        $this->minimum = (int) $minimum;
105
    }
106
107
    /**
108
     * @return int
109
     */
110
    public function getMinimum()
111
    {
112
        return $this->minimum;
113
    }
114
115
    /**
116
     * @param $mname
117
     */
118
    public function setMname($mname)
119
    {
120
        $this->mname = $mname;
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getMname()
127
    {
128
        return $this->mname;
129
    }
130
131
    /**
132
     * @param $refresh
133
     */
134
    public function setRefresh($refresh)
135
    {
136
        $this->refresh = (int) $refresh;
137
    }
138
139
    /**
140
     * @return int
141
     */
142
    public function getRefresh()
143
    {
144
        return $this->refresh;
145
    }
146
147
    /**
148
     * @param $retry
149
     */
150
    public function setRetry($retry)
151
    {
152
        $this->retry = (int) $retry;
153
    }
154
155
    /**
156
     * @return int
157
     */
158
    public function getRetry()
159
    {
160
        return $this->retry;
161
    }
162
163
    /**
164
     * @param $rname
165
     */
166
    public function setRname($rname)
167
    {
168
        $this->rname = $rname;
169
    }
170
171
    /**
172
     * @return string
173
     */
174
    public function getRname()
175
    {
176
        return $this->rname;
177
    }
178
179
    /**
180
     * @param int $serial
181
     */
182
    public function setSerial($serial)
183
    {
184
        $this->serial = (int) $serial;
185
    }
186
187
    /**
188
     * @return int
189
     */
190
    public function getSerial()
191
    {
192
        return $this->serial;
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198
    public function output()
199
    {
200
        return sprintf(
201
            '%s %s %s %s %s %s %s',
202
            $this->mname,
203
            $this->rname,
204
            $this->serial,
205
            $this->refresh,
206
            $this->retry,
207
            $this->expire,
208
            $this->minimum
209
        );
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215
    public function outputFormatted()
216
    {
217
        return ResourceRecord::MULTILINE_BEGIN . PHP_EOL .
218
            $this->makeLine($this->getMname(), 'MNAME') .
219
            $this->makeLine($this->getRname(), 'RNAME') .
220
            $this->makeLine($this->getSerial(), 'SERIAL') .
221
            $this->makeLine($this->getRefresh(), 'REFRESH') .
222
            $this->makeLine($this->getRetry(), 'RETRY') .
223
            $this->makeLine($this->getExpire(), 'EXPIRE') .
224
            $this->makeLine($this->getMinimum(), 'MINIMUM') .
225
            str_repeat(' ', $this->padding) . ResourceRecord::MULTILINE_END;
226
    }
227
228
    /**
229
     * Determines the longest variable.
230
     *
231
     * @return int
232
     */
233
    public function longestVarLength()
234
    {
235
        $l = 0;
236
237
        foreach ([
238
                    $this->getMname(),
239
                    $this->getRname(),
240
                    $this->getSerial(),
241
                    $this->getRefresh(),
242
                    $this->getRetry(),
243
                    $this->getExpire(),
244
                    $this->getMinimum(),
245
                ] as $var) {
246
            $l = ($l < strlen($var)) ? strlen($var) : $l;
247
        }
248
249
        return $l;
250
    }
251
}
252