summaryrefslogtreecommitdiff
path: root/lib/facebook-graph-sdk/src/Facebook/GraphNodes
diff options
context:
space:
mode:
Diffstat (limited to 'lib/facebook-graph-sdk/src/Facebook/GraphNodes')
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php85
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php4
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php5
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAlbum.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphApplication.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphCoverPhoto.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEdge.php44
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphGroup.php3
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphLocation.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNode.php18
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php4
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObjectFactory.php8
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php24
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphSessionInfo.php2
-rw-r--r--lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphUser.php14
19 files changed, 174 insertions, 53 deletions
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php
new file mode 100644
index 0000000..4338b65
--- /dev/null
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Copyright 2017 Facebook, Inc.
+ *
+ * You are hereby granted a non-exclusive, worldwide, royalty-free license to
+ * use, copy, modify, and distribute this software in source code or binary
+ * form for use in connection with the web services and APIs provided by
+ * Facebook.
+ *
+ * As with any software that integrates with the Facebook platform, your use
+ * of this software is subject to the Facebook Developer Principles and
+ * Policies [http://developers.facebook.com/policy/]. This copyright notice
+ * shall be included in all copies or substantial portions of the software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+namespace Facebook\GraphNodes;
+
+use DateTime;
+
+/**
+ * Birthday object to handle various Graph return formats
+ *
+ * @package Facebook
+ */
+class Birthday extends DateTime
+{
+ /**
+ * @var bool
+ */
+ private $hasDate = false;
+
+ /**
+ * @var bool
+ */
+ private $hasYear = false;
+
+ /**
+ * Parses Graph birthday format to set indication flags, possible values:
+ *
+ * MM/DD/YYYY
+ * MM/DD
+ * YYYY
+ *
+ * @link https://developers.facebook.com/docs/graph-api/reference/user
+ *
+ * @param string $date
+ */
+ public function __construct($date)
+ {
+ $parts = explode('/', $date);
+
+ $this->hasYear = count($parts) === 3 || count($parts) === 1;
+ $this->hasDate = count($parts) === 3 || count($parts) === 2;
+
+ parent::__construct($date);
+ }
+
+ /**
+ * Returns whether date object contains birth day and month
+ *
+ * @return bool
+ */
+ public function hasDate()
+ {
+ return $this->hasDate;
+ }
+
+ /**
+ * Returns whether date object contains birth year
+ *
+ * @return bool
+ */
+ public function hasYear()
+ {
+ return $this->hasYear;
+ }
+}
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php
index cac010b..424b7cf 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -69,7 +69,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate
return $this->items[$name];
}
- return $default ?: null;
+ return $default;
}
/**
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php
index 3fba815..31508ee 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -28,7 +28,6 @@ namespace Facebook\GraphNodes;
*
* @package Facebook
*/
-
class GraphAchievement extends GraphNode
{
/**
@@ -92,7 +91,7 @@ class GraphAchievement extends GraphNode
/**
* Returns the type of achievement.
*
- * @see https://developers.facebook.com/docs/graph-api/reference/v2.2/achievement
+ * @see https://developers.facebook.com/docs/graph-api/reference/achievement
*
* @return string
*/
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAlbum.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAlbum.php
index 50d1f2c..52f19b5 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAlbum.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAlbum.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphApplication.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphApplication.php
index 69b09bb..aa07c82 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphApplication.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphApplication.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphCoverPhoto.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphCoverPhoto.php
index ee60750..824275b 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphCoverPhoto.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphCoverPhoto.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEdge.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEdge.php
index 95f3284..f6f4970 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEdge.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEdge.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -153,35 +153,13 @@ class GraphEdge extends Collection
$this->validateForPagination();
// Do we have a paging URL?
- if (isset($this->metaData['paging'][$direction])) {
- // Graph returns the full URL with all the original params.
- // We just want the endpoint though.
- $pageUrl = $this->metaData['paging'][$direction];
-
- return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
- }
-
- // Do we have a cursor to work with?
- $cursorDirection = $direction === 'next' ? 'after' : 'before';
- $cursor = $this->getCursor($cursorDirection);
- if (!$cursor) {
- return null;
- }
-
- // If we don't know the ID of the parent node, this ain't gonna work.
- if (!$this->parentEdgeEndpoint) {
+ if (!isset($this->metaData['paging'][$direction])) {
return null;
}
- // We have the parent node ID, paging cursor & original request.
- // These were the ingredients chosen to create the perfect little URL.
- $pageUrl = $this->parentEdgeEndpoint . '?' . $cursorDirection . '=' . urlencode($cursor);
+ $pageUrl = $this->metaData['paging'][$direction];
- // Pull in the original params
- $originalUrl = $this->request->getUrl();
- $pageUrl = FacebookUrlManipulator::mergeUrlParams($originalUrl, $pageUrl);
-
- return FacebookUrlManipulator::forceSlashPrefix($pageUrl);
+ return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
}
/**
@@ -257,4 +235,18 @@ class GraphEdge extends Collection
return null;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function map(\Closure $callback)
+ {
+ return new static(
+ $this->request,
+ array_map($callback, $this->items, array_keys($this->items)),
+ $this->metaData,
+ $this->parentEdgeEndpoint,
+ $this->subclassName
+ );
+ }
}
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php
index 19ff2fb..a470d89 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphGroup.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphGroup.php
index 07a4dbd..6217bd4 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphGroup.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphGroup.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -167,5 +167,4 @@ class GraphGroup extends GraphNode
{
return $this->getField('venue');
}
-
}
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php
index a60a07a..3dfbd49 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphLocation.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphLocation.php
index 187a399..29215aa 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphLocation.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphLocation.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNode.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNode.php
index 0d2f504..061e744 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNode.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNode.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -62,10 +62,11 @@ class GraphNode extends Collection
foreach ($data as $k => $v) {
if ($this->shouldCastAsDateTime($k)
&& (is_numeric($v)
- || $k === 'birthday'
|| $this->isIso8601DateString($v))
) {
$items[$k] = $this->castToDateTime($v);
+ } elseif ($k === 'birthday') {
+ $items[$k] = $this->castToBirthday($v);
} else {
$items[$k] = $v;
}
@@ -149,7 +150,6 @@ class GraphNode extends Collection
'backdated_time',
'issued_at',
'expires_at',
- 'birthday',
'publish_time'
], true);
}
@@ -174,6 +174,18 @@ class GraphNode extends Collection
}
/**
+ * Casts a birthday value from Graph to Birthday
+ *
+ * @param string $value
+ *
+ * @return Birthday
+ */
+ public function castToBirthday($value)
+ {
+ return new Birthday($value);
+ }
+
+ /**
* Getter for $graphObjectMap.
*
* @return array
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php
index e1bedd9..6a37091 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -331,7 +331,7 @@ class GraphNodeFactory
$dataList = [];
foreach ($data['data'] as $graphNode) {
- $dataList[] = $this->safelyMakeGraphNode($graphNode, $subclassName, $parentKey, $parentNodeId);
+ $dataList[] = $this->safelyMakeGraphNode($graphNode, $subclassName);
}
$metaData = $this->getMetaData($data);
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php
index bb8f8e4..0633c40 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObjectFactory.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObjectFactory.php
index 94963a0..c0f6e04 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObjectFactory.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObjectFactory.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -23,6 +23,8 @@
*/
namespace Facebook\GraphNodes;
+use Facebook\Exceptions\FacebookSDKException;
+
/**
* Class GraphObjectFactory
*
@@ -56,7 +58,7 @@ class GraphObjectFactory extends GraphNodeFactory
{
return $this->makeGraphNode($subclassName);
}
-
+
/**
* Convenience method for creating a GraphEvent collection.
*
@@ -66,7 +68,7 @@ class GraphObjectFactory extends GraphNodeFactory
*/
public function makeGraphEvent()
{
- return $this->makeGraphObject(static::BASE_GRAPH_OBJECT_PREFIX . 'GraphEvent');
+ return $this->makeGraphNode(static::BASE_GRAPH_OBJECT_PREFIX . 'GraphEvent');
}
/**
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php
index ab8e31a..3dfb0e0 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -37,6 +37,8 @@ class GraphPage extends GraphNode
'best_page' => '\Facebook\GraphNodes\GraphPage',
'global_brand_parent_page' => '\Facebook\GraphNodes\GraphPage',
'location' => '\Facebook\GraphNodes\GraphLocation',
+ 'cover' => '\Facebook\GraphNodes\GraphCoverPhoto',
+ 'picture' => '\Facebook\GraphNodes\GraphPicture',
];
/**
@@ -100,6 +102,26 @@ class GraphPage extends GraphNode
}
/**
+ * Returns CoverPhoto of the Page.
+ *
+ * @return GraphCoverPhoto|null
+ */
+ public function getCover()
+ {
+ return $this->getField('cover');
+ }
+
+ /**
+ * Returns Picture of the Page.
+ *
+ * @return GraphPicture|null
+ */
+ public function getPicture()
+ {
+ return $this->getField('picture');
+ }
+
+ /**
* Returns the page access token for the admin user.
*
* Only available in the `/me/accounts` context.
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php
index bfd37fa..10274ec 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphSessionInfo.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphSessionInfo.php
index 3c9e2ff..df8dd35 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphSessionInfo.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphSessionInfo.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphUser.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphUser.php
index cb9ddbb..6e1ed8f 100644
--- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphUser.php
+++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphUser.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -91,6 +91,16 @@ class GraphUser extends GraphNode
}
/**
+ * Returns the email for the user as a string if present.
+ *
+ * @return string|null
+ */
+ public function getEmail()
+ {
+ return $this->getField('email');
+ }
+
+ /**
* Returns the gender for the user as a string if present.
*
* @return string|null
@@ -113,7 +123,7 @@ class GraphUser extends GraphNode
/**
* Returns the users birthday, if available.
*
- * @return \DateTime|null
+ * @return Birthday|null
*/
public function getBirthday()
{