Cheetah
GraphEdge.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook\GraphNodes;
25 
29 
35 class GraphEdge extends Collection
36 {
40  protected $request;
41 
45  protected $metaData = [];
46 
51 
55  protected $subclassName;
56 
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 
81  public function getParentGraphEdge()
82  {
84  }
85 
91  public function getSubClassName()
92  {
93  return $this->subclassName;
94  }
95 
101  public function getMetaData()
102  {
103  return $this->metaData;
104  }
105 
111  public function getNextCursor()
112  {
113  return $this->getCursor('after');
114  }
115 
121  public function getPreviousCursor()
122  {
123  return $this->getCursor('before');
124  }
125 
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 
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 
163  }
164 
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 
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 
206  public function getNextPageRequest()
207  {
208  return $this->getPaginationRequest('next');
209  }
210 
218  public function getPreviousPageRequest()
219  {
220  return $this->getPaginationRequest('previous');
221  }
222 
230  public function getTotalCount()
231  {
232  if (isset($this->metaData['summary']['total_count'])) {
233  return $this->metaData['summary']['total_count'];
234  }
235 
236  return null;
237  }
238 
242  public function map(\Closure $callback)
243  {
244  return new static(
246  array_map($callback, $this->items, array_keys($this->items)),
250  );
251  }
252 }
Facebook\GraphNodes\GraphEdge\getMetaData
getMetaData()
Definition: GraphEdge.php:101
Facebook\Url\FacebookUrlManipulator\baseGraphUrlEndpoint
static baseGraphUrlEndpoint($urlToTrim)
Definition: FacebookUrlManipulator.php:163
Facebook\GraphNodes\GraphEdge\getPaginationUrl
getPaginationUrl($direction)
Definition: GraphEdge.php:151
Facebook\Exceptions\FacebookSDKException
Definition: FacebookSDKException.php:32
Facebook\GraphNodes\GraphEdge
Definition: GraphEdge.php:36
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
php
Facebook\GraphNodes\GraphEdge\getTotalCount
getTotalCount()
Definition: GraphEdge.php:230
Facebook\GraphNodes\GraphEdge\getPreviousCursor
getPreviousCursor()
Definition: GraphEdge.php:121
Facebook\GraphNodes\GraphEdge\getNextCursor
getNextCursor()
Definition: GraphEdge.php:111
Facebook\Url\FacebookUrlManipulator
Definition: FacebookUrlManipulator.php:32
Facebook\GraphNodes\GraphEdge\$subclassName
$subclassName
Definition: GraphEdge.php:55
Facebook\GraphNodes\GraphEdge\getParentGraphEdge
getParentGraphEdge()
Definition: GraphEdge.php:81
Facebook\GraphNodes\GraphEdge\getSubClassName
getSubClassName()
Definition: GraphEdge.php:91
Facebook\GraphNodes\GraphEdge\getPaginationRequest
getPaginationRequest($direction)
Definition: GraphEdge.php:186
Facebook\GraphNodes\GraphEdge\getNextPageRequest
getNextPageRequest()
Definition: GraphEdge.php:206
Facebook\GraphNodes\GraphEdge\getCursor
getCursor($direction)
Definition: GraphEdge.php:133
Facebook\GraphNodes\GraphEdge\getPreviousPageRequest
getPreviousPageRequest()
Definition: GraphEdge.php:218
Facebook\GraphNodes\GraphEdge\__construct
__construct(FacebookRequest $request, array $data=[], array $metaData=[], $parentEdgeEndpoint=null, $subclassName=null)
Definition: GraphEdge.php:66
Facebook\GraphNodes\GraphEdge\$request
$request
Definition: GraphEdge.php:40
Facebook\GraphNodes\GraphEdge\map
map(\Closure $callback)
Definition: GraphEdge.php:242
Facebook\GraphNodes\GraphEdge\$metaData
$metaData
Definition: GraphEdge.php:45
Facebook\GraphNodes\Collection
Definition: Collection.php:40
Facebook\GraphNodes\GraphEdge\validateForPagination
validateForPagination()
Definition: GraphEdge.php:170
Facebook\GraphNodes\GraphEdge\$parentEdgeEndpoint
$parentEdgeEndpoint
Definition: GraphEdge.php:50
Facebook\GraphNodes
Definition: Birthday.php:24
Facebook\FacebookRequest
Definition: FacebookRequest.php:40