1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Phraseanet SDK. |
5
|
|
|
* |
6
|
|
|
* (c) Alchemy <[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 PhraseanetSDK\Entity; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use PhraseanetSDK\EntityManager; |
16
|
|
|
|
17
|
|
|
class Feed |
18
|
|
|
{ |
19
|
|
|
|
20
|
1 |
|
public static function fromList(EntityManager $entityManager, array $values) |
21
|
|
|
{ |
22
|
1 |
|
$feeds = array(); |
23
|
|
|
|
24
|
1 |
|
foreach ($values as $value) { |
25
|
1 |
|
$feeds[$value->id] = self::fromValue($entityManager, $value); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
1 |
|
return $feeds; |
29
|
|
|
} |
30
|
|
|
|
31
|
2 |
|
public static function fromValue(EntityManager $entityManager, \stdClass $value) |
32
|
|
|
{ |
33
|
2 |
|
return new self($entityManager, $value); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var EntityManager |
38
|
|
|
*/ |
39
|
|
|
protected $entityManager; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \stdClass |
43
|
|
|
*/ |
44
|
|
|
protected $source; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var \DateTime|null |
48
|
|
|
*/ |
49
|
|
|
protected $createdOn; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var \DateTime|null |
53
|
|
|
*/ |
54
|
|
|
protected $updatedOn; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param EntityManager $entityManager |
58
|
|
|
* @param \stdClass $source |
59
|
|
|
*/ |
60
|
2 |
|
public function __construct(EntityManager $entityManager, \stdClass $source) |
61
|
|
|
{ |
62
|
2 |
|
$this->entityManager = $entityManager; |
63
|
2 |
|
$this->source = $source; |
64
|
2 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \stdClass |
68
|
|
|
*/ |
69
|
|
|
public function getRawData() |
70
|
|
|
{ |
71
|
2 |
|
return $this->source; |
72
|
|
|
} |
73
|
2 |
|
|
74
|
|
|
/** |
75
|
|
|
* The feed id |
76
|
|
|
* |
77
|
|
|
* @return integer |
78
|
|
|
*/ |
79
|
|
|
public function getId() |
80
|
|
|
{ |
81
|
2 |
|
return $this->source->id; |
82
|
|
|
} |
83
|
2 |
|
|
84
|
|
|
/** |
85
|
|
|
* The feed title |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getTitle() |
90
|
|
|
{ |
91
|
2 |
|
return $this->source->title; |
92
|
|
|
} |
93
|
2 |
|
|
94
|
|
|
/** |
95
|
|
|
* The feed icon |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getIcon() |
100
|
|
|
{ |
101
|
2 |
|
return $this->source->icon; |
102
|
|
|
} |
103
|
2 |
|
|
104
|
|
|
/** |
105
|
|
|
* The feed subtitle |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getSubTitle() |
110
|
|
|
{ |
111
|
2 |
|
return $this->source->subtitle; |
112
|
|
|
} |
113
|
2 |
|
|
114
|
|
|
/** |
115
|
|
|
* Get the total entries of the feed |
116
|
|
|
* |
117
|
|
|
* @return integer |
118
|
|
|
*/ |
119
|
|
|
public function getTotalEntries() |
120
|
|
|
{ |
121
|
2 |
|
return $this->source->total_entries; |
122
|
|
|
} |
123
|
2 |
|
|
124
|
|
|
/** |
125
|
|
|
* Creation date |
126
|
|
|
* |
127
|
|
|
* @return \DateTime |
128
|
|
|
*/ |
129
|
|
|
public function getCreatedOn() |
130
|
|
|
{ |
131
|
2 |
|
return $this->createdOn ?: $this->createdOn = new \DateTime($this->source->created_on); |
132
|
|
|
} |
133
|
2 |
|
|
134
|
|
|
/** |
135
|
|
|
* Last updated date |
136
|
|
|
* |
137
|
|
|
* @return \DateTime |
138
|
|
|
*/ |
139
|
|
|
public function getUpdatedOn() |
140
|
|
|
{ |
141
|
2 |
|
return $this->updatedOn ?: $this->updatedOn = new \DateTime($this->source->updated_on); |
142
|
|
|
} |
143
|
2 |
|
|
144
|
|
|
/** |
145
|
|
|
* Tell whether the feed is public or not |
146
|
|
|
* |
147
|
|
|
* @return Boolean |
148
|
|
|
*/ |
149
|
|
|
public function isPublic() |
150
|
|
|
{ |
151
|
2 |
|
return $this->source->public; |
152
|
|
|
} |
153
|
2 |
|
|
154
|
|
|
/** |
155
|
|
|
* Tell whether the feed is a read only feed |
156
|
|
|
* |
157
|
|
|
* @return Boolean |
158
|
|
|
*/ |
159
|
|
|
public function isReadonly() |
160
|
|
|
{ |
161
|
2 |
|
return $this->source->readonly; |
162
|
|
|
} |
163
|
2 |
|
|
164
|
|
|
/** |
165
|
|
|
* Tell whether the feed is deletable |
166
|
|
|
* |
167
|
|
|
* @return Boolean |
168
|
|
|
*/ |
169
|
|
|
public function isDeletable() |
170
|
|
|
{ |
171
|
|
|
return $this->source->deletable; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param int $offset |
176
|
|
|
* @param int $perPage |
177
|
|
|
* @return FeedEntry[]|ArrayCollection |
178
|
|
|
*/ |
179
|
|
|
public function getEntries($offset = 0, $perPage = 0) |
180
|
|
|
{ |
181
|
|
|
return $this->entityManager |
|
|
|
|
182
|
|
|
->getRepository('entry') |
183
|
|
|
->findByFeed($this->getId(), $offset, $perPage); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: