1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the feed-io package. |
4
|
|
|
* |
5
|
|
|
* (c) Alexandre Debril <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace FeedIo; |
12
|
|
|
|
13
|
|
|
use FeedIo\Feed\Node; |
14
|
|
|
use FeedIo\Feed\Item; |
15
|
|
|
use FeedIo\Feed\ItemInterface; |
16
|
|
|
|
17
|
|
|
class Feed extends Node implements FeedInterface, \JsonSerializable |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var \ArrayIterator |
21
|
|
|
*/ |
22
|
|
|
protected $items; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string $url |
26
|
|
|
*/ |
27
|
|
|
protected $url; |
28
|
|
|
|
29
|
33 |
|
public function __construct() |
30
|
|
|
{ |
31
|
33 |
|
$this->items = new \ArrayIterator(); |
32
|
|
|
|
33
|
33 |
|
parent::__construct(); |
34
|
33 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return string $url |
38
|
|
|
*/ |
39
|
1 |
|
public function getUrl() |
40
|
|
|
{ |
41
|
1 |
|
return $this->url; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $url |
46
|
|
|
* @return FeedInterface |
47
|
|
|
*/ |
48
|
1 |
|
public function setUrl($url) |
49
|
|
|
{ |
50
|
1 |
|
$this->url = $url; |
51
|
|
|
|
52
|
1 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
57
|
|
|
* Return the current element |
58
|
|
|
* @link http://php.net/manual/en/iterator.current.php |
59
|
|
|
* @return mixed Can return any type. |
60
|
|
|
*/ |
61
|
14 |
|
public function current() |
62
|
|
|
{ |
63
|
14 |
|
return $this->items->current(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
68
|
|
|
* Move forward to next element |
69
|
|
|
* @link http://php.net/manual/en/iterator.next.php |
70
|
|
|
* @return void Any returned value is ignored. |
71
|
|
|
*/ |
72
|
12 |
|
public function next() |
73
|
|
|
{ |
74
|
12 |
|
return $this->items->next(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
79
|
|
|
* Return the key of the current element |
80
|
|
|
* @link http://php.net/manual/en/iterator.key.php |
81
|
|
|
* @return mixed scalar on success, or null on failure. |
82
|
|
|
*/ |
83
|
1 |
|
public function key() |
84
|
|
|
{ |
85
|
1 |
|
return $this->items->key(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
90
|
|
|
* Checks if current position is valid |
91
|
|
|
* @link http://php.net/manual/en/iterator.valid.php |
92
|
|
|
* @return boolean The return value will be casted to boolean and then evaluated. |
93
|
|
|
* Returns true on success or false on failure. |
94
|
|
|
*/ |
95
|
15 |
|
public function valid() |
96
|
|
|
{ |
97
|
15 |
|
return $this->items->valid(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* (PHP 5 >= 5.0.0)<br/> |
102
|
|
|
* Rewind the Iterator to the first element |
103
|
|
|
* @link http://php.net/manual/en/iterator.rewind.php |
104
|
|
|
* @return void Any returned value is ignored. |
105
|
|
|
*/ |
106
|
13 |
|
public function rewind() |
107
|
|
|
{ |
108
|
13 |
|
return $this->items->rewind(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param ItemInterface $item |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
19 |
|
public function add(ItemInterface $item) |
116
|
|
|
{ |
117
|
19 |
|
$this->items->append($item); |
118
|
|
|
|
119
|
19 |
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return ItemInterface |
124
|
|
|
*/ |
125
|
6 |
|
public function newItem() |
126
|
|
|
{ |
127
|
6 |
|
return new Item(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
1 |
|
public function jsonSerialize() |
134
|
|
|
{ |
135
|
1 |
|
return $this->toArray(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return array |
140
|
|
|
*/ |
141
|
2 |
|
public function toArray() |
142
|
|
|
{ |
143
|
2 |
|
$items = []; |
144
|
|
|
|
145
|
2 |
|
foreach( $this->items as $item ) { |
146
|
2 |
|
$items[] = $item->toArray(); |
147
|
2 |
|
} |
148
|
|
|
|
149
|
2 |
|
$properties = parent::toArray(); |
150
|
2 |
|
$properties['items'] = $items; |
151
|
|
|
|
152
|
2 |
|
return $properties; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|