1
1
<?php
2
- declare (strict_types = 1 );
2
+
3
+ declare (strict_types=1 );
3
4
4
5
namespace Forensic \FeedParser \FeedItems ;
5
6
@@ -17,27 +18,27 @@ class BaseFeedItem
17
18
18
19
/**
19
20
* feed item type
20
- */
21
+ */
21
22
protected $ _type = null ;
22
23
23
24
/**
24
25
* feed item id
25
- */
26
+ */
26
27
protected $ _id = '' ;
27
28
28
29
/**
29
30
* feed item title
30
- */
31
+ */
31
32
protected $ _title = '' ;
32
33
33
34
/**
34
35
* url link to feed item's homepage
35
- */
36
+ */
36
37
protected $ _link = '' ;
37
38
38
39
/**
39
40
* feed item content
40
- */
41
+ */
41
42
protected $ _content = '' ;
42
43
43
44
/**
@@ -47,7 +48,7 @@ class BaseFeedItem
47
48
48
49
/**
49
50
* image associated with the feed item
50
- */
51
+ */
51
52
protected $ _image = [
52
53
'src ' => '' , //image src link
53
54
'link ' => '' , //url that this image links to, likely the feed item's homepage
@@ -56,7 +57,7 @@ class BaseFeedItem
56
57
57
58
/**
58
59
* media type associated with this item
59
- */
60
+ */
60
61
protected $ _enclosure = [
61
62
62
63
'type ' => '' , //enclose media type
@@ -73,22 +74,32 @@ class BaseFeedItem
73
74
74
75
/**
75
76
* time string describing when this feed item was last updated
76
- */
77
+ */
77
78
protected $ _lastUpdated = '' ;
78
79
80
+ /**
81
+ * timestamp describing when this feed item was created
82
+ */
83
+ protected $ _createdAtTimestamp = '' ;
84
+
85
+ /**
86
+ * timestamp describing when this feed item was last updated
87
+ */
88
+ protected $ _lastUpdatedTimestamp = '' ;
89
+
79
90
/**
80
91
* what category does this feed item belong to
81
- */
92
+ */
82
93
protected $ _category = '' ;
83
94
84
95
/**
85
96
* item's source
86
- */
97
+ */
87
98
protected $ _source = '' ;
88
99
89
100
/**
90
101
* who is the author of this item?
91
- */
102
+ */
92
103
protected $ _author = '' ;
93
104
94
105
/**
@@ -97,10 +108,14 @@ class BaseFeedItem
97
108
*@param DOMElement $item - the feed item node
98
109
*@param XPath $xpath - the xpath instance for the feed
99
110
*@param array $property_selectors - array of property selector maps
100
- */
101
- public function __construct (FeedItemTypes $ feed_item_type , DOMElement $ item , XPath $ xpath ,
102
- array $ property_selectors , array $ parser_options )
103
- {
111
+ */
112
+ public function __construct (
113
+ FeedItemTypes $ feed_item_type ,
114
+ DOMElement $ item ,
115
+ XPath $ xpath ,
116
+ array $ property_selectors ,
117
+ array $ parser_options
118
+ ) {
104
119
$ this ->_type = $ feed_item_type ;
105
120
106
121
$ xpath ->setContextNode ($ item );
@@ -113,12 +128,11 @@ public function __construct(FeedItemTypes $feed_item_type, DOMElement $item, XPa
113
128
*
114
129
*@param string $property - the property to retrieve
115
130
*@return string|null
116
- */
131
+ */
117
132
public function __get (string $ property )
118
133
{
119
134
$ this_property = '_ ' . $ property ;
120
- if (property_exists ($ this , $ this_property ))
121
- {
135
+ if (property_exists ($ this , $ this_property )) {
122
136
$ value = $ this ->{$ this_property };
123
137
if (is_array ($ value ))
124
138
return new ParameterBag ($ value );
@@ -132,23 +146,20 @@ public function __get(string $property)
132
146
/**
133
147
* converts the item to array
134
148
*@return array
135
- */
149
+ */
136
150
public function toArray ()
137
151
{
138
152
$ reflector = new ReflectionClass (get_class ($ this ));
139
153
$ props = $ reflector ->getProperties (ReflectionProperty::IS_PROTECTED );
140
154
141
155
$ result = [];
142
156
143
- foreach ($ props as $ prop )
144
- {
157
+ foreach ($ props as $ prop ) {
145
158
$ this_property_name = $ prop ->getName ();
146
159
$ property_name = substr ($ this_property_name , 1 ); //dont include the underscore
147
160
if ($ property_name === 'type ' ) {
148
161
$ result [$ property_name ] = $ this ->{$ this_property_name }->value ();
149
- }
150
-
151
- else {
162
+ } else {
152
163
$ result [$ property_name ] = $ this ->{$ this_property_name };
153
164
}
154
165
}
@@ -159,9 +170,9 @@ public function toArray()
159
170
/**
160
171
* convert the feed to json
161
172
*@return string
162
- */
173
+ */
163
174
public function toJSON ()
164
175
{
165
176
return json_encode ($ this ->toArray ());
166
177
}
167
- }
178
+ }
0 commit comments