-
Notifications
You must be signed in to change notification settings - Fork 2
/
Enclosure.php
47 lines (43 loc) · 1.15 KB
/
Enclosure.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
<?php
namespace Lucinda\RSS;
/**
* Encapsulates a RSS enclosure tag according to specifications:
* https://www.rssboard.org/rss-profile#element-channel-enclosure
*/
class Enclosure implements Tag
{
private string $url;
private int $length;
private string $type;
/**
* Enclosure constructor.
*
* @param string $url Url says where the media object is located.
* @param integer $length Byte size of media object
* @param string $type Mime type of media object.
* @throws Exception
*/
public function __construct(string $url, int $length, string $type)
{
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new Exception("Invalid managing editor");
}
$this->url = $url;
$this->length = $length;
$this->type = $type;
}
/**
* {@inheritDoc}
*
* @see Tag::__toString()
*/
public function __toString(): string
{
$output = "";
$vars = get_object_vars($this);
foreach ($vars as $key=>$value) {
$output .= $key.'="'.$value.'" ';
}
return "<enclosure ".$output."/>";
}
}