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

Add PHP 8.1 Support #1265

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
}
],
"require": {
"php": "^5.4|^7.0"
"php": "^8.1",
"guzzlehttp/guzzle": "^7.4"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.8",
"guzzlehttp/guzzle": "~5.0"
"phpunit/phpunit": "^9.5.10",
"mockery/mockery": "^1.4.4",
"phpspec/prophecy-phpunit": "^v2.0.0"
},
"suggest": {
"paragonie/random_compat": "Provides a better CSPRNG option in PHP 5",
Expand All @@ -26,8 +27,7 @@
"autoload": {
"psr-4": {
"Facebook\\": "src/Facebook/"
},
"files": ["src/Facebook/polyfills.php"]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/FacebookApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ In order to make requests to the Graph API, you need to [create a Facebook app](
To instantiate a new `Facebook\FacebookApp` entity, pass the app ID and app secret to the constructor.

```php
$fbApp = new Facebook\FacebookApp('{app-id}', '{app-secret}');
$fbApp = new Facebook\Application('{app-id}', '{app-secret}');
```

Alternatively you can obtain the `Facebook\FacebookApp` entity from the [`Facebook\Facebook`](Facebook.md) super service class.

```php
$fb = new Facebook\Facebook([/* . . . */]);
$fbApp = $fb->getApp();
$fbApp = $fb->getApplication();
```

You'll rarely be using the `FacebookApp` entity directly unless you're doing some extreme customizations of the SDK for PHP. But this entity plays an important role in the internal workings of the SDK for PHP.
Expand Down Expand Up @@ -46,7 +46,7 @@ Returns the app secret.
The `Facebook\FacebookApp` entity can be serialized and unserialized.

```php
$fbApp = new Facebook\FacebookApp('foo-app-id', 'foo-app-secret');
$fbApp = new Facebook\Application('foo-app-id', 'foo-app-secret');

$serializedFacebookApp = serialize($fbApp);
// C:29:"Facebook\\FacebookApp":54:{a:2:{i:0;s:10:"foo-app-id";i:1;s:14:"foo-app-secret";}}
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/FacebookBatchRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ You can instantiate a new `FacebookBatchRequest` entity directly by sending the
by using the [`Facebook\Facebook::newBatchRequest()`](Facebook.md#newBatchRequest) factory method.

```php
use Facebook\FacebookBatchRequest;
use Facebook\BatchRequest;

$request = new FacebookBatchRequest(
$request = new BatchRequest(
Facebook\FacebookApp $app,
array $requests,
string|null $accessToken,
Expand Down Expand Up @@ -86,7 +86,7 @@ $requests = [
'foo' => $fb->request('GET', '/me'),
'bar' => $fb->request('POST', '/me/feed', [/* */]),
];
$batchRequest = new Facebook\FacebookBatchRequest($fb->getApp(), $requests, '{access-token}');
$batchRequest = new Facebook\BatchRequest($fb->getApplication(), $requests, '{access-token}');

var_dump($batchRequest[0]);
/*
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/FacebookClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $fbClient = $fb->getClient();
Alternatively you could instantiate a new `Facebook\FacebookClient` service directly.

```php
$fbClient = new Facebook\FacebookClient($httpClientHandler, $enableBeta = false);
$fbClient = new Facebook\Client($httpClientHandler, $enableBeta = false);
```

The Graph API has a number of different base URL's based on what request you want to send. For example, if you wanted to send requests to the beta version of Graph, you'd need to send requests to [https://graph.beta.facebook.com](https://graph.beta.facebook.com) instead [https://graph.facebook.com](https://graph.facebook.com). And if you wanted to upload a video, that request would need to be sent to [https://graph-video.facebook.com](https://graph-video.facebook.com).
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/FacebookFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ The `FacebookFile` entity represents a local or remote file to be uploaded with
There are two ways to instantiate a `FacebookFile` entity. One way is to instantiate it directly:

```php
use Facebook\FileUpload\FacebookFile;
use Facebook\FileUpload\File;

$myFileToUpload = new FacebookFile('/path/to/file.jpg');
$myFileToUpload = new File('/path/to/file.jpg');
```

Alternatively, you can use the `fileToUpload()` factory on the `Facebook\Facebook` super service to instantiate a new `FacebookFile` entity.
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/FacebookRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Represents a request that will be sent to the Graph API.
You can instantiate a new `FacebookRequest` entity directly by sending the arguments to the constructor.

```php
use Facebook\FacebookRequest;
use Facebook\Request;

$request = new FacebookRequest(
$request = new Request(
Facebook\FacebookApp $app,
string $accessToken,
string $method,
Expand All @@ -27,8 +27,8 @@ The `FacebookRequest` entity does not actually make any calls to the Graph API,
Usage:

```php
$fbApp = new Facebook\FacebookApp('{app-id}', '{app-secret}');
$request = new Facebook\FacebookRequest($fbApp, '{access-token}', 'GET', '/me');
$fbApp = new Facebook\Application('{app-id}', '{app-secret}');
$request = new Facebook\Request($fbApp, '{access-token}', 'GET', '/me');

// OR

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/FacebookVideo.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ The `FacebookVideo` entity represents a local or remote video file to be uploade
There are two ways to instantiate a `FacebookVideo` entity. One way is to instantiate it directly:

```php
use Facebook\FileUpload\FacebookVideo;
use Facebook\FileUpload\Video;

$myVideoFileToUpload = new FacebookVideo('/path/to/video-file.mp4');
$myVideoFileToUpload = new Video('/path/to/video-file.mp4');
```

Alternatively, you can use the `videoToUpload()` factory on the `Facebook\Facebook` super service to instantiate a new `FacebookVideo` entity.
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/PersistentDataInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ $fb = new Facebook\Facebook([
Alternatively, if you're working with the `Facebook\Helpers\FacebookRedirectLoginHelper` directly, you can inject your custom handler via the constructor.

```php
use Facebook\Helpers\FacebookRedirectLoginHelper;
use Facebook\Helpers\RedirectLoginHelper;

$myPersistentDataHandler = new MyLaravelPersistentDataHandler();
$helper = new FacebookRedirectLoginHelper($fbApp, $myPersistentDataHandler);
$helper = new RedirectLoginHelper($fbApp, $myPersistentDataHandler);
```

## Method Reference
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/PseudoRandomStringGeneratorInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ $fb = new Facebook\Facebook([
Alternatively, if you're working with the `Facebook\Helpers\FacebookRedirectLoginHelper` directly, you can inject your custom generator via the constructor.

```php
use Facebook\Helpers\FacebookRedirectLoginHelper;
use Facebook\Helpers\RedirectLoginHelper;

$myPseudoRandomStringGenerator = new MyCustomPseudoRandomStringGenerator();
$helper = new FacebookRedirectLoginHelper($fbApp, null, null, $myPseudoRandomStringGenerator);
$helper = new RedirectLoginHelper($fbApp, null, null, $myPseudoRandomStringGenerator);
```

## Method Reference
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/SignedRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `Facebook\SignedRequest` entity represents a signed request.
To instantiate a new `Facebook\SignedRequest` entity, pass the [`Facebook\FacebookApp`](FacebookApp.md) entity and raw signed request to the constructor.

```php
$fbApp = new Facebook\FacebookApp('{app-id}', '{app-secret}');
$fbApp = new Facebook\Application('{app-id}', '{app-secret}');
$signedRequest = new Facebook\SignedRequest($fbApp, 'raw.signed_request');
```

Expand Down Expand Up @@ -70,7 +70,7 @@ public string make(array $payload)
Generates a valid raw signed request as a string that contains the data from the `$payload` array. The signature is signed using the app secret from the `Facebook\FacebookApp` entity. This can be useful for testing purposes.

```php
$fbApp = new Facebook\FacebookApp('{app-id}', '{app-secret}');
$fbApp = new Facebook\Application('{app-id}', '{app-secret}');
$signedRequest = new Facebook\SignedRequest($fbApp);

$payload = [
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/UrlDetectionInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ $fb = new Facebook\Facebook([
Alternatively, if you're working with the `Facebook\Helpers\FacebookRedirectLoginHelper` directly, you can inject your custom handler via the constructor.

```php
use Facebook\Helpers\FacebookRedirectLoginHelper;
use Facebook\Helpers\RedirectLoginHelper;

$myUrlDetectionHandler = new MyLaravelUrlDetectionHandler();
$helper = new FacebookRedirectLoginHelper($fbApp, null, $myUrlDetectionHandler);
$helper = new RedirectLoginHelper($fbApp, null, $myUrlDetectionHandler);
```

## Method Reference
Expand Down
49 changes: 14 additions & 35 deletions src/Facebook/FacebookApp.php → src/Facebook/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,39 @@
* DEALINGS IN THE SOFTWARE.
*
*/

namespace Facebook;

use Facebook\Authentication\AccessToken;
use Facebook\Exceptions\FacebookSDKException;

class FacebookApp implements \Serializable
/**
* Class Application
*
* @package Facebook
*/
class Application
{
/**
* @var string The app ID.
*/
protected $id;
protected string $id;

/**
* @var string The app secret.
*/
protected $secret;
protected string $secret;

/**
* @param string $id
* @param string $secret
*
* @throws FacebookSDKException
*/
public function __construct($id, $secret)
public function __construct(string $id, string $secret)
{
if (!is_string($id)
// Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
&& !is_int($id)) {
throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.');
}
// We cast as a string in case a valid int was set on a 64-bit system and this is unserialised on a 32-bit system
$this->id = (string) $id;
$this->id = $id;
$this->secret = $secret;
}

Expand All @@ -61,7 +62,7 @@ public function __construct($id, $secret)
*
* @return string
*/
public function getId()
public function getId(): string
{
return $this->id;
}
Expand All @@ -71,7 +72,7 @@ public function getId()
*
* @return string
*/
public function getSecret()
public function getSecret(): string
{
return $this->secret;
}
Expand All @@ -81,30 +82,8 @@ public function getSecret()
*
* @return AccessToken
*/
public function getAccessToken()
public function getAccessToken(): AccessToken
{
return new AccessToken($this->id . '|' . $this->secret);
}

/**
* Serializes the FacebookApp entity as a string.
*
* @return string
*/
public function serialize()
{
return implode('|', [$this->id, $this->secret]);
}

/**
* Unserializes a string as a FacebookApp entity.
*
* @param string $serialized
*/
public function unserialize($serialized)
{
list($id, $secret) = explode('|', $serialized);

$this->__construct($id, $secret);
}
}
Loading