This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
/
AtomLink.php
343 lines (306 loc) · 7.41 KB
/
AtomLink.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
/**
* LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
*
* @author Azure PHP SDK <azurephpsdk@microsoft.com>
* @copyright 2012 Microsoft Corporation
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*
* @link https://github.com/WindowsAzure/azure-sdk-for-php
*/
namespace WindowsAzure\Common\Internal\Atom;
use WindowsAzure\Common\Internal\Resources;
use WindowsAzure\Common\Internal\Validate;
/**
* This link defines a reference from an entry or feed to a Web resource.
*
* @category Microsoft
*
* @author Azure PHP SDK <azurephpsdk@microsoft.com>
* @copyright 2012 Microsoft Corporation
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*
* @version Release: 0.4.4_2016-08
*
* @link https://github.com/WindowsAzure/azure-sdk-for-php
*/
class AtomLink extends AtomBase
{
/**
* The undefined content.
*
* @var string
*/
protected $undefinedContent;
/**
* The HREF of the link.
*
* @var string
*/
protected $href;
/**
* The rel attribute of the link.
*
* @var string
*/
protected $rel;
/**
* The media type of the link.
*
* @var string
*/
protected $type;
/**
* The language of HREF.
*
* @var string
*/
protected $hreflang;
/**
* The titile of the link.
*
* @var string
*/
protected $title;
/**
* The length of the link.
*
* @var int
*/
protected $length;
/**
* Creates a AtomLink instance with specified text.
*/
public function __construct()
{
}
/**
* Parse an ATOM Link xml.
*
* @param string $xmlString an XML based string of ATOM Link.
*
* @return none
*/
public function parseXml($xmlString)
{
Validate::notNull($xmlString, 'xmlString');
Validate::isString($xmlString, 'xmlString');
$atomLinkXml = simplexml_load_string($xmlString);
$attributes = $atomLinkXml->attributes();
if (!empty($attributes['href'])) {
$this->href = (string) $attributes['href'];
}
if (!empty($attributes['rel'])) {
$this->rel = (string) $attributes['rel'];
}
if (!empty($attributes['type'])) {
$this->type = (string) $attributes['type'];
}
if (!empty($attributes['hreflang'])) {
$this->hreflang = (string) $attributes['hreflang'];
}
if (!empty($attributes['title'])) {
$this->title = (string) $attributes['title'];
}
if (!empty($attributes['length'])) {
$this->length = (integer) $attributes['length'];
}
$undefinedContent = (string) $atomLinkXml;
if (empty($undefinedContent)) {
$this->undefinedContent = null;
} else {
$this->undefinedContent = (string) $atomLinkXml;
}
}
/**
* Gets the href of the link.
*
* @return string
*/
public function getHref()
{
return $this->href;
}
/**
* Sets the href of the link.
*
* @param string $href The href of the link.
*
* @return none
*/
public function setHref($href)
{
$this->href = $href;
}
/**
* Gets the rel of the atomLink.
*
* @return string
*/
public function getRel()
{
return $this->rel;
}
/**
* Sets the rel of the link.
*
* @param string $rel The rel of the atomLink.
*
* @return none
*/
public function setRel($rel)
{
$this->rel = $rel;
}
/**
* Gets the type of the link.
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Sets the type of the link.
*
* @param string $type The type of the link.
*
* @return none
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Gets the language of the href.
*
* @return string
*/
public function getHrefLang()
{
return $this->hrefLang;
}
/**
* Sets the language of the href.
*
* @param string $hrefLang The language of the href.
*
* @return none
*/
public function setHrefLang($hrefLang)
{
$this->hrefLang = $hrefLang;
}
/**
* Gets the title of the link.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Sets the title of the link.
*
* @param string $title The title of the link.
*
* @return none
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Gets the length of the link.
*
* @return string
*/
public function getLength()
{
return $this->length;
}
/**
* Sets the length of the link.
*
* @param string $length The length of the link.
*
* @return none
*/
public function setLength($length)
{
$this->length = $length;
}
/**
* Gets the undefined content.
*
* @return string
*/
public function getUndefinedContent()
{
return $this->undefinedContent;
}
/**
* Sets the undefined content.
*
* @param string $undefinedContent The undefined content.
*
* @return none
*/
public function setUndefinedContent($undefinedContent)
{
$this->undefinedContent = $undefinedContent;
}
/**
* Writes an XML representing the ATOM link item.
*
* @param \XMLWriter $xmlWriter The xml writer.
*
* @return none
*/
public function writeXml($xmlWriter)
{
Validate::notNull($xmlWriter, 'xmlWriter');
$xmlWriter->startElementNS(
'atom',
Resources::LINK,
Resources::ATOM_NAMESPACE
);
$this->writeInnerXml($xmlWriter);
$xmlWriter->endElement();
}
/**
* Writes the inner XML representing the ATOM link item.
*
* @param \XMLWriter $xmlWriter The xml writer.
*
* @return none
*/
public function writeInnerXml($xmlWriter)
{
Validate::notNull($xmlWriter, 'xmlWriter');
$this->writeOptionalAttribute($xmlWriter, 'href', $this->href);
$this->writeOptionalAttribute($xmlWriter, 'rel', $this->rel);
$this->writeOptionalAttribute($xmlWriter, 'type', $this->type);
$this->writeOptionalAttribute($xmlWriter, 'hreflang', $this->hreflang);
$this->writeOptionalAttribute($xmlWriter, 'title', $this->title);
$this->writeOptionalAttribute($xmlWriter, 'length', $this->length);
if (!empty($this->undefinedContent)) {
$xmlWriter->writeRaw($this->undefinedContent);
}
}
}