1 | <?php |
||
35 | class GraphEdge extends Collection |
||
36 | { |
||
37 | /** |
||
38 | * @var FacebookRequest The original request that generated this data. |
||
39 | */ |
||
40 | protected $request; |
||
41 | |||
42 | /** |
||
43 | * @var array An array of Graph meta data like pagination, etc. |
||
44 | */ |
||
45 | protected $metaData = []; |
||
46 | |||
47 | /** |
||
48 | * @var string|null The parent Graph edge endpoint that generated the list. |
||
49 | */ |
||
50 | protected $parentEdgeEndpoint; |
||
51 | |||
52 | /** |
||
53 | * @var string|null The subclass of the child GraphNode's. |
||
54 | */ |
||
55 | protected $subclassName; |
||
56 | |||
57 | /** |
||
58 | * Init this collection of GraphNode's. |
||
59 | * |
||
60 | * @param FacebookRequest $request The original request that generated this data. |
||
61 | * @param array $data An array of GraphNode's. |
||
62 | * @param array $metaData An array of Graph meta data like pagination, etc. |
||
63 | * @param string|null $parentEdgeEndpoint The parent Graph edge endpoint that generated the list. |
||
64 | * @param string|null $subclassName The subclass of the child GraphNode's. |
||
65 | */ |
||
66 | public function __construct(FacebookRequest $request, array $data = [], array $metaData = [], $parentEdgeEndpoint = null, $subclassName = null) |
||
67 | { |
||
68 | $this->request = $request; |
||
69 | $this->metaData = $metaData; |
||
70 | $this->parentEdgeEndpoint = $parentEdgeEndpoint; |
||
71 | $this->subclassName = $subclassName; |
||
72 | |||
73 | parent::__construct($data); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Gets the parent Graph edge endpoint that generated the list. |
||
78 | * |
||
79 | * @return string|null |
||
80 | */ |
||
81 | public function getParentGraphEdge() |
||
85 | |||
86 | /** |
||
87 | * Gets the subclass name that the child GraphNode's are cast as. |
||
88 | * |
||
89 | * @return string|null |
||
90 | */ |
||
91 | public function getSubClassName() |
||
95 | |||
96 | /** |
||
97 | * Returns the raw meta data associated with this GraphEdge. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function getMetaData() |
||
105 | |||
106 | /** |
||
107 | * Returns the next cursor if it exists. |
||
108 | * |
||
109 | * @return string|null |
||
110 | */ |
||
111 | public function getNextCursor() |
||
115 | |||
116 | /** |
||
117 | * Returns the previous cursor if it exists. |
||
118 | * |
||
119 | * @return string|null |
||
120 | */ |
||
121 | public function getPreviousCursor() |
||
125 | |||
126 | /** |
||
127 | * Returns the cursor for a specific direction if it exists. |
||
128 | * |
||
129 | * @param string $direction The direction of the page: after|before |
||
130 | * |
||
131 | * @return string|null |
||
132 | */ |
||
133 | public function getCursor($direction) |
||
134 | { |
||
135 | if (isset($this->metaData['paging']['cursors'][$direction])) { |
||
136 | return $this->metaData['paging']['cursors'][$direction]; |
||
137 | } |
||
138 | |||
139 | return null; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Generates a pagination URL based on a cursor. |
||
144 | * |
||
145 | * @param string $direction The direction of the page: next|previous |
||
146 | * |
||
147 | * @return string|null |
||
148 | * |
||
149 | * @throws FacebookSDKException |
||
150 | */ |
||
151 | public function getPaginationUrl($direction) |
||
152 | { |
||
153 | $this->validateForPagination(); |
||
154 | |||
155 | // Do we have a paging URL? |
||
156 | if (!isset($this->metaData['paging'][$direction])) { |
||
157 | return null; |
||
158 | } |
||
159 | |||
160 | $pageUrl = $this->metaData['paging'][$direction]; |
||
161 | |||
162 | return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Validates whether or not we can paginate on this request. |
||
167 | * |
||
168 | * @throws FacebookSDKException |
||
169 | */ |
||
170 | public function validateForPagination() |
||
171 | { |
||
172 | if ($this->request->getMethod() !== 'GET') { |
||
173 | throw new FacebookSDKException('You can only paginate on a GET request.', 720); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Gets the request object needed to make a next|previous page request. |
||
179 | * |
||
180 | * @param string $direction The direction of the page: next|previous |
||
181 | * |
||
182 | * @return FacebookRequest|null |
||
183 | * |
||
184 | * @throws FacebookSDKException |
||
185 | */ |
||
186 | public function getPaginationRequest($direction) |
||
187 | { |
||
188 | $pageUrl = $this->getPaginationUrl($direction); |
||
189 | if (!$pageUrl) { |
||
|
|||
190 | return null; |
||
191 | } |
||
192 | |||
193 | $newRequest = clone $this->request; |
||
194 | $newRequest->setEndpoint($pageUrl); |
||
195 | |||
196 | return $newRequest; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Gets the request object needed to make a "next" page request. |
||
201 | * |
||
202 | * @return FacebookRequest|null |
||
203 | * |
||
204 | * @throws FacebookSDKException |
||
205 | */ |
||
206 | public function getNextPageRequest() |
||
210 | |||
211 | /** |
||
212 | * Gets the request object needed to make a "previous" page request. |
||
213 | * |
||
214 | * @return FacebookRequest|null |
||
215 | * |
||
216 | * @throws FacebookSDKException |
||
217 | */ |
||
218 | public function getPreviousPageRequest() |
||
222 | |||
223 | /** |
||
224 | * The total number of results according to Graph if it exists. |
||
225 | * |
||
226 | * This will be returned if the summary=true modifier is present in the request. |
||
227 | * |
||
228 | * @return int|null |
||
229 | */ |
||
230 | public function getTotalCount() |
||
238 | } |
||
239 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: