Skip to content

Commit db9c1fe

Browse files
committed
Merge branch '5.x'
2 parents 43af15c + 61a19c3 commit db9c1fe

12 files changed

+193
-31
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ Starting with version 5, the Facebook PHP SDK follows [SemVer](http://semver.org
2020

2121
Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes loaded with lots of new features and a friendlier API.
2222

23+
- 5.6.1 (2017-08-16)
24+
- Fixed doc block syntax that interfered with Doctrine (#844)
25+
- 5.6.0 (2017-07-23)
26+
- Bump Graph API version to v2.10 (#829)
27+
- 5.5.0 (2017-04-20)
28+
- Added support for batch options (#713)
29+
- Bump Graph API version to v2.9.
30+
- 5.4.4 (2017-01-19)
31+
- Added the `application/octet-stream` MIME type for SRT files (#734)
32+
- 5.4.3 (2016-12-30)
33+
- Fixed a bug that would throw a type error in `GraphEdge` in some cases (#715)
34+
- 5.4.2 (2016-11-15)
35+
- Added check for [PHP 7 CSPRNG](http://php.net/manual/en/function.random-bytes.php) first to keep mcrypt deprecation messages from appearing in PHP 7.1 (#692)
36+
- 5.4.1 (2016-10-18)
37+
- Fixed a bug that was not properly parsing response headers when they contained the colon `:` character. (#679)
2338
- 5.4.0 (2016-10-12)
2439
- Bump Graph API version to v2.8.
2540
- Auto-cast `cover` field to `GraphCoverPhoto` and `picture` field to `GraphPicture` in `GraphPage`. (#655)

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Code of Conduct
2+
3+
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated.

CONTRIBUTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ Contributing
33

44
Contributions are **welcome** and will be fully **credited**.
55

6-
We accept contributions via Pull Requests on [Github](https://github.com/facebook/facebook-php-sdk-v4).
6+
We accept contributions via Pull Requests on [Github](https://github.com/facebook/php-graph-sdk/pull/new).
7+
8+
The current stable major version is v5. The v6 is under active development.
9+
10+
This means any new feature MUST target v6 (`master` branch).
11+
12+
The v5 (`5.x` branch) is maintained only for bug fixes, node/edge updates or documentation improvements.
13+
14+
## Code of Conduct
15+
The code of conduct is described in [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md)
716

817

918
## Pull Requests

docs/reference/Facebook.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,23 @@ $batchResponse = $fb->sendBatchRequest($requests);
327327

328328
[See a full batch example](../examples/batch_request.md).
329329

330+
## newBatchRequest()
331+
```php
332+
public Facebook\FacebookBatchRequest newBatchRequest(
333+
string|AccessToken|null $accessToken,
334+
string|null $graphVersion
335+
)
336+
```
337+
338+
Instantiates an empty `Facebook\FacebookBatchRequest`.
339+
To populate it use the [`Facebook\FacebookBatchRequest::add()`](FacebookBatchRequest.md#add) method.
340+
341+
The `$accessToken` and `$graphVersion` arguments are the same as `get()` above.
342+
If any of the requests contained in the batch request does not have either the `$accessToken` or the `$graphVersion` set,
343+
it fallbacks to the values provided in the instantiation of the batch request.
344+
345+
[See a full batch example](../examples/batch_request.md).
346+
330347
## getRedirectLoginHelper()
331348
```php
332349
public Facebook\Helper\FacebookRedirectLoginHelper getRedirectLoginHelper()

docs/reference/FacebookBatchRequest.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Represents a batch request that will be sent to the Graph API.
44

55
## Facebook\FacebookBatchRequest
66

7-
You can instantiate a new `FacebookBatchRequest` entity directly by sending the arguments to the constructor.
7+
You can instantiate a new `FacebookBatchRequest` entity directly by sending the arguments to the constructor or
8+
by using the [`Facebook\Facebook::newBatchRequest()`](Facebook.md#newBatchRequest) factory method.
89

910
```php
1011
use Facebook\FacebookBatchRequest;
@@ -61,9 +62,9 @@ Since the `Facebook\FacebookBatchRequest` is extended from the [`Facebook\Facebo
6162
### add()
6263
```php
6364
public add(
64-
array|Facebook\FacebookBatchRequest $request,
65-
string|null $name
66-
)
65+
array|Facebook\FacebookBatchRequest $request,
66+
string|null $name
67+
)
6768
```
6869
Adds a request to be sent in the batch request. The `$request` can be a single [`Facebook\FacebookRequest`](FacebookRequest.md) or an array of `Facebook\FacebookRequest`'s.
6970

docs/reference/GraphNode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $response = $fb->get('/something');
2626
$graphNode = $response->getGraphNode();
2727

2828
// Get the response typed as a GraphUser
29-
$user = $response->getGraphUser());
29+
$user = $response->getGraphUser();
3030

3131
// Get the response typed as a GraphPage
3232
$page = $response->getGraphPage();
@@ -162,7 +162,7 @@ Returns the `hometown` property for the user as a `Facebook\GraphNode\GraphPage`
162162

163163
### getSignificantOther()
164164
```php
165-
public Facebook\GraphNode\GraphUser|null getHometown()
165+
public Facebook\GraphNode\GraphUser|null getSignificantOther()
166166
```
167167
Returns the `significant_other` property for the user as a `Facebook\GraphNode\GraphUser` if present.
168168

src/Authentication/OAuth2Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public function debugToken($accessToken)
125125
* Generates an authorization URL to begin the process of authenticating a user.
126126
*
127127
* @param string $redirectUrl The callback URL to redirect to.
128-
* @param array $scope An array of permissions to request.
129128
* @param string $state The CSPRNG-generated CSRF value.
129+
* @param array $scope An array of permissions to request.
130130
* @param array $params An array of parameters to generate URL.
131131
* @param string $separator The separator to use in http_build_query().
132132
*

src/Exception/FacebookResponseException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ public static function create(FacebookResponse $response)
113113
// API Throttling
114114
case 4:
115115
case 17:
116+
case 32:
116117
case 341:
118+
case 613:
117119
return new static($response, new FacebookThrottleException($message, $code));
118120

119121
// Duplicate Post

src/Facebook.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,27 @@ public function sendBatchRequest(array $requests, $accessToken = null, $graphVer
482482
return $this->lastResponse = $this->client->sendBatchRequest($batchRequest);
483483
}
484484

485+
/**
486+
* Instantiates an empty FacebookBatchRequest entity.
487+
*
488+
* @param AccessToken|string|null $accessToken The top-level access token. Requests with no access token
489+
* will fallback to this.
490+
* @param string|null $graphVersion The Graph API version to use.
491+
* @return FacebookBatchRequest
492+
*/
493+
public function newBatchRequest($accessToken = null, $graphVersion = null)
494+
{
495+
$accessToken = $accessToken ?: $this->defaultAccessToken;
496+
$graphVersion = $graphVersion ?: $this->defaultGraphVersion;
497+
498+
return new FacebookBatchRequest(
499+
$this->app,
500+
[],
501+
$accessToken,
502+
$graphVersion
503+
);
504+
}
505+
485506
/**
486507
* Instantiates a new FacebookRequest entity.
487508
*

src/FacebookBatchRequest.php

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ public function __construct(FacebookApp $app = null, array $requests = [], $acce
6262
}
6363

6464
/**
65-
* A a new request to the array.
65+
* Adds a new request to the array.
6666
*
6767
* @param FacebookRequest|array $request
68-
* @param string|null $name
68+
* @param string|null|array $options Array of batch request options e.g. 'name', 'omit_response_on_success'.
69+
* If a string is given, it is the value of the 'name' option.
6970
*
7071
* @return FacebookBatchRequest
7172
*
7273
* @throws \InvalidArgumentException
7374
*/
74-
public function add($request, $name = null)
75+
public function add($request, $options = null)
7576
{
7677
if (is_array($request)) {
7778
foreach ($request as $key => $req) {
@@ -85,17 +86,28 @@ public function add($request, $name = null)
8586
throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.');
8687
}
8788

89+
if (null === $options) {
90+
$options = [];
91+
} elseif (!is_array($options)) {
92+
$options = ['name' => $options];
93+
}
94+
8895
$this->addFallbackDefaults($request);
96+
97+
// File uploads
98+
$attachedFiles = $this->extractFileAttachments($request);
99+
100+
$name = isset($options['name']) ? $options['name'] : null;
101+
102+
unset($options['name']);
103+
89104
$requestToAdd = [
90105
'name' => $name,
91106
'request' => $request,
107+
'options' => $options,
108+
'attached_files' => $attachedFiles,
92109
];
93110

94-
// File uploads
95-
$attachedFiles = $this->extractFileAttachments($request);
96-
if ($attachedFiles) {
97-
$requestToAdd['attached_files'] = $attachedFiles;
98-
}
99111
$this->requests[] = $requestToAdd;
100112

101113
return $this;
@@ -189,8 +201,15 @@ public function convertRequestsToJson()
189201
{
190202
$requests = [];
191203
foreach ($this->requests as $request) {
192-
$attachedFiles = isset($request['attached_files']) ? $request['attached_files'] : null;
193-
$requests[] = $this->requestEntityToBatchArray($request['request'], $request['name'], $attachedFiles);
204+
$options = [];
205+
206+
if (null !== $request['name']) {
207+
$options['name'] = $request['name'];
208+
}
209+
210+
$options += $request['options'];
211+
212+
$requests[] = $this->requestEntityToBatchArray($request['request'], $options, $request['attached_files']);
194213
}
195214

196215
return json_encode($requests);
@@ -215,14 +234,22 @@ public function validateBatchRequestCount()
215234
/**
216235
* Converts a Request entity into an array that is batch-friendly.
217236
*
218-
* @param FacebookRequest $request The request entity to convert.
219-
* @param string|null $requestName The name of the request.
220-
* @param string|null $attachedFiles Names of files associated with the request.
237+
* @param FacebookRequest $request The request entity to convert.
238+
* @param string|null|array $options Array of batch request options e.g. 'name', 'omit_response_on_success'.
239+
* If a string is given, it is the value of the 'name' option.
240+
* @param string|null $attachedFiles Names of files associated with the request.
221241
*
222242
* @return array
223243
*/
224-
public function requestEntityToBatchArray(FacebookRequest $request, $requestName = null, $attachedFiles = null)
244+
public function requestEntityToBatchArray(FacebookRequest $request, $options = null, $attachedFiles = null)
225245
{
246+
247+
if (null === $options) {
248+
$options = [];
249+
} elseif (!is_array($options)) {
250+
$options = ['name' => $options];
251+
}
252+
226253
$compiledHeaders = [];
227254
$headers = $request->getHeaders();
228255
foreach ($headers as $name => $value) {
@@ -242,18 +269,12 @@ public function requestEntityToBatchArray(FacebookRequest $request, $requestName
242269
$batch['body'] = $body;
243270
}
244271

245-
if (isset($requestName)) {
246-
$batch['name'] = $requestName;
247-
}
272+
$batch += $options;
248273

249-
if (isset($attachedFiles)) {
274+
if (null !== $attachedFiles) {
250275
$batch['attached_files'] = $attachedFiles;
251276
}
252277

253-
// @TODO Add support for "omit_response_on_success"
254-
// @TODO Add support for "depends_on"
255-
// @TODO Add support for JSONP with "callback"
256-
257278
return $batch;
258279
}
259280

0 commit comments

Comments
 (0)