Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 0b076fb

Browse files
authored
Merge pull request #643 from SammyK/patch-608-force-graph-version
Remove default Graph API version fallback
2 parents 3e8719d + 3f9fd16 commit 0b076fb

14 files changed

+51
-43
lines changed

src/Facebook/Authentication/OAuth2Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ class OAuth2Client
7474
/**
7575
* @param FacebookApp $app
7676
* @param FacebookClient $client
77-
* @param string|null $graphVersion The version of the Graph API to use.
77+
* @param string $graphVersion The version of the Graph API to use.
7878
*/
79-
public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion = null)
79+
public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion)
8080
{
8181
$this->app = $app;
8282
$this->client = $client;
83-
$this->graphVersion = $graphVersion ?: Facebook::DEFAULT_GRAPH_VERSION;
83+
$this->graphVersion = $graphVersion;
8484
}
8585

8686
/**

src/Facebook/Facebook.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class Facebook
5353
*/
5454
const VERSION = '6.0-dev';
5555

56-
/**
57-
* @const string Default Graph API version for requests.
58-
*/
59-
const DEFAULT_GRAPH_VERSION = 'v2.7';
60-
6156
/**
6257
* @const string The name of the environment variable that contains the app ID.
6358
*/
@@ -120,7 +115,7 @@ public function __construct(array $config = [])
120115
$config = array_merge([
121116
'app_id' => getenv(static::APP_ID_ENV_NAME),
122117
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
123-
'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
118+
'default_graph_version' => null,
124119
'enable_beta_mode' => false,
125120
'http_client_handler' => null,
126121
'persistent_data_handler' => null,
@@ -133,6 +128,9 @@ public function __construct(array $config = [])
133128
if (!$config['app_secret']) {
134129
throw new FacebookSDKException('Required "app_secret" key not supplied in config and could not find fallback environment variable "' . static::APP_SECRET_ENV_NAME . '"');
135130
}
131+
if (!$config['default_graph_version']) {
132+
throw new \InvalidArgumentException('Required "default_graph_version" key not supplied in config');
133+
}
136134

137135
$this->app = new FacebookApp($config['app_id'], $config['app_secret']);
138136
$this->client = new FacebookClient(
@@ -148,7 +146,6 @@ public function __construct(array $config = [])
148146
$this->setDefaultAccessToken($config['default_access_token']);
149147
}
150148

151-
// @todo v6: Throw an InvalidArgumentException if "default_graph_version" is not set
152149
$this->defaultGraphVersion = $config['default_graph_version'];
153150
}
154151

src/Facebook/FacebookRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function __construct(FacebookApp $app = null, $accessToken = null, $metho
102102
$this->setEndpoint($endpoint);
103103
$this->setParams($params);
104104
$this->setETag($eTag);
105-
$this->graphVersion = $graphVersion ?: Facebook::DEFAULT_GRAPH_VERSION;
105+
$this->graphVersion = $graphVersion;
106106
}
107107

108108
/**
@@ -490,7 +490,7 @@ public function getPostParams()
490490
/**
491491
* The graph version used for this request.
492492
*
493-
* @return string
493+
* @return string|null
494494
*/
495495
public function getGraphVersion()
496496
{

src/Facebook/Helpers/FacebookPageTabHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class FacebookPageTabHelper extends FacebookCanvasHelper
4343
*
4444
* @param FacebookApp $app The FacebookApp entity.
4545
* @param FacebookClient $client The client to make HTTP requests.
46-
* @param string|null $graphVersion The version of Graph to use.
46+
* @param string $graphVersion The version of Graph to use.
4747
*/
48-
public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion = null)
48+
public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion)
4949
{
5050
parent::__construct($app, $client, $graphVersion);
5151

src/Facebook/Helpers/FacebookSignedRequestFromInputHelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ abstract class FacebookSignedRequestFromInputHelper
5757
*
5858
* @param FacebookApp $app The FacebookApp entity.
5959
* @param FacebookClient $client The client to make HTTP requests.
60-
* @param string|null $graphVersion The version of Graph to use.
60+
* @param string $graphVersion The version of Graph to use.
6161
*/
62-
public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion = null)
62+
public function __construct(FacebookApp $app, FacebookClient $client, $graphVersion)
6363
{
6464
$this->app = $app;
65-
$graphVersion = $graphVersion ?: Facebook::DEFAULT_GRAPH_VERSION;
6665
$this->oAuth2Client = new OAuth2Client($this->app, $client, $graphVersion);
6766

6867
$this->instantiateSignedRequest();

src/Facebook/Url/FacebookUrlManipulator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ public static function mergeUrlParams($urlToStealFrom, $urlToAddTo)
142142
*
143143
* @param string|null $string
144144
*
145-
* @return string|null
145+
* @return string
146146
*/
147147
public static function forceSlashPrefix($string)
148148
{
149149
if (!$string) {
150-
return $string;
150+
return '';
151151
}
152152

153153
return strpos($string, '/') === 0 ? $string : '/' . $string;

tests/FacebookBatchRequestTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
namespace Facebook\Tests;
2525

26-
use Facebook\Facebook;
2726
use Facebook\FacebookApp;
2827
use Facebook\FacebookRequest;
2928
use Facebook\FacebookBatchRequest;
@@ -216,15 +215,14 @@ public function testBatchRequestEntitiesProperlyGetConvertedToAnArray($request,
216215
public function requestsAndExpectedResponsesProvider()
217216
{
218217
$headers = $this->defaultHeaders();
219-
$apiVersion = Facebook::DEFAULT_GRAPH_VERSION;
220218

221219
return [
222220
[
223221
new FacebookRequest(null, null, 'GET', '/foo', ['foo' => 'bar']),
224222
[
225223
'headers' => $headers,
226224
'method' => 'GET',
227-
'relative_url' => '/' . $apiVersion . '/foo?foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
225+
'relative_url' => '/foo?foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
228226
'name' => 'foo_name',
229227
],
230228
],
@@ -233,7 +231,7 @@ public function requestsAndExpectedResponsesProvider()
233231
[
234232
'headers' => $headers,
235233
'method' => 'POST',
236-
'relative_url' => '/' . $apiVersion . '/bar',
234+
'relative_url' => '/bar',
237235
'body' => 'bar=baz&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
238236
'name' => 'foo_name',
239237
],
@@ -243,7 +241,7 @@ public function requestsAndExpectedResponsesProvider()
243241
[
244242
'headers' => $headers,
245243
'method' => 'DELETE',
246-
'relative_url' => '/' . $apiVersion . '/bar?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
244+
'relative_url' => '/bar?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
247245
'name' => 'foo_name',
248246
],
249247
],
@@ -273,7 +271,7 @@ public function testBatchRequestsWithFilesGetConvertedToAnArray()
273271
$this->assertEquals([
274272
'headers' => $this->defaultHeaders(),
275273
'method' => 'POST',
276-
'relative_url' => '/' . Facebook::DEFAULT_GRAPH_VERSION . '/bar',
274+
'relative_url' => '/bar',
277275
'body' => 'message=foobar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
278276
'name' => 'foo_name',
279277
'attached_files' => $attachedFiles,
@@ -290,10 +288,9 @@ public function testPreppingABatchRequestProperlySetsThePostParams()
290288
$params = $batchRequest->getParams();
291289

292290
$expectedHeaders = json_encode($this->defaultHeaders());
293-
$version = Facebook::DEFAULT_GRAPH_VERSION;
294291
$expectedBatchParams = [
295-
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/' . $version . '\\/foo?access_token=bar_token&appsecret_proof=2ceec40b7b9fd7d38fff1767b766bcc6b1f9feb378febac4612c156e6a8354bd","name":"foo_name"},'
296-
. '{"headers":' . $expectedHeaders . ',"method":"POST","relative_url":"\\/' . $version . '\\/bar","body":"foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9"}]',
292+
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/foo?access_token=bar_token&appsecret_proof=2ceec40b7b9fd7d38fff1767b766bcc6b1f9feb378febac4612c156e6a8354bd","name":"foo_name"},'
293+
. '{"headers":' . $expectedHeaders . ',"method":"POST","relative_url":"\\/bar","body":"foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9"}]',
297294
'include_headers' => true,
298295
'access_token' => 'foo_token',
299296
'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',
@@ -317,10 +314,9 @@ public function testPreppingABatchRequestProperlyMovesTheFiles()
317314
$attachedFiles = implode(',', array_keys($files));
318315

319316
$expectedHeaders = json_encode($this->defaultHeaders());
320-
$version = Facebook::DEFAULT_GRAPH_VERSION;
321317
$expectedBatchParams = [
322-
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/' . $version . '\\/foo?access_token=bar_token&appsecret_proof=2ceec40b7b9fd7d38fff1767b766bcc6b1f9feb378febac4612c156e6a8354bd","name":"foo_name"},'
323-
. '{"headers":' . $expectedHeaders . ',"method":"POST","relative_url":"\\/' . $version . '\\/me\\/photos","body":"message=foobar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9","attached_files":"' . $attachedFiles . '"}]',
318+
'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/foo?access_token=bar_token&appsecret_proof=2ceec40b7b9fd7d38fff1767b766bcc6b1f9feb378febac4612c156e6a8354bd","name":"foo_name"},'
319+
. '{"headers":' . $expectedHeaders . ',"method":"POST","relative_url":"\\/me\\/photos","body":"message=foobar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9","attached_files":"' . $attachedFiles . '"}]',
324320
'include_headers' => true,
325321
'access_token' => 'foo_token',
326322
'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9',

tests/FacebookClientTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
namespace Facebook\Tests;
2525

2626
use Facebook\Exceptions\FacebookSDKException;
27-
use Facebook\Facebook;
2827
use Facebook\FacebookApp;
2928
use Facebook\FacebookRequest;
3029
use Facebook\FacebookBatchRequest;
@@ -165,7 +164,7 @@ public function testAFacebookBatchRequestWillProperlyBatchFiles()
165164

166165
list($url, $method, $headers, $body) = $this->fbClient->prepareRequestMessage($fbBatchRequest);
167166

168-
$this->assertEquals(FacebookClient::BASE_GRAPH_VIDEO_URL . '/' . Facebook::DEFAULT_GRAPH_VERSION, $url);
167+
$this->assertEquals(FacebookClient::BASE_GRAPH_VIDEO_URL, $url);
169168
$this->assertEquals('POST', $method);
170169
$this->assertContains('multipart/form-data; boundary=', $headers['Content-Type']);
171170
$this->assertContains('Content-Disposition: form-data; name="batch"', $body);

tests/FacebookRequestTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
namespace Facebook\Tests;
2525

26-
use Facebook\Facebook;
2726
use Facebook\FacebookApp;
2827
use Facebook\FacebookRequest;
2928
use Facebook\FileUpload\FacebookFile;
@@ -125,14 +124,14 @@ public function testAProperUrlWillBeGenerated()
125124

126125
$getUrl = $getRequest->getUrl();
127126
$expectedParams = 'foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9';
128-
$expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/foo?' . $expectedParams;
127+
$expectedUrl = '/foo?' . $expectedParams;
129128

130129
$this->assertEquals($expectedUrl, $getUrl);
131130

132-
$postRequest = new FacebookRequest($app, 'foo_token', 'POST', '/bar', ['foo' => 'bar']);
131+
$postRequest = new FacebookRequest($app, 'foo_token', 'POST', '/bar', ['foo' => 'bar'], null, 'v0.0');
133132

134133
$postUrl = $postRequest->getUrl();
135-
$expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/bar';
134+
$expectedUrl = '/v0.0/bar';
136135

137136
$this->assertEquals($expectedUrl, $postUrl);
138137
}
@@ -156,7 +155,7 @@ public function testAuthenticationParamsAreStrippedAndReapplied()
156155
$url = $request->getUrl();
157156

158157
$expectedParams = 'bar=baz&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9';
159-
$expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/foo?' . $expectedParams;
158+
$expectedUrl = '/foo?' . $expectedParams;
160159
$this->assertEquals($expectedUrl, $url);
161160

162161
$params = $request->getParams();

tests/FacebookTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Facebook\Authentication\AccessToken;
3030
use Facebook\GraphNodes\GraphEdge;
3131
use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload;
32-
use Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator;
3332
use Facebook\Tests\Fixtures\FooClientInterface;
3433
use Facebook\Tests\Fixtures\FooPersistentDataInterface;
3534
use Facebook\Tests\Fixtures\FooUrlDetectionInterface;
@@ -39,6 +38,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase
3938
protected $config = [
4039
'app_id' => '1337',
4140
'app_secret' => 'foo_secret',
41+
'default_graph_version' => 'v0.0',
4242
];
4343

4444
/**
@@ -50,6 +50,7 @@ public function testInstantiatingWithoutAppIdThrows()
5050
putenv(Facebook::APP_ID_ENV_NAME.'=');
5151
$config = [
5252
'app_secret' => 'foo_secret',
53+
'default_graph_version' => 'v0.0',
5354
];
5455
new Facebook($config);
5556
}
@@ -63,6 +64,19 @@ public function testInstantiatingWithoutAppSecretThrows()
6364
putenv(Facebook::APP_SECRET_ENV_NAME.'=');
6465
$config = [
6566
'app_id' => 'foo_id',
67+
'default_graph_version' => 'v0.0',
68+
];
69+
new Facebook($config);
70+
}
71+
72+
/**
73+
* @expectedException \InvalidArgumentException
74+
*/
75+
public function testInstantiatingWithoutDefaultGraphVersionThrows()
76+
{
77+
$config = [
78+
'app_id' => 'foo_id',
79+
'app_secret' => 'foo_secret',
6680
];
6781
new Facebook($config);
6882
}

0 commit comments

Comments
 (0)