Skip to content

Commit 656eb73

Browse files
author
Joel Butcher
committed
fix service provider
1 parent 495ff67 commit 656eb73

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

config/config.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

33
return [
4-
'client_id' => env('FACEBOOK_APP_ID'),
5-
'client_secret' => env('FACEBOOK_APP_SECRET'),
6-
'enable_beta_mode' => env('FACEBOOK_ENABLE_BETA', false),
7-
'default_graph_version' => env('FACEBOOK_GRAPH_VERSION', 'v10'),
4+
'app_id' => env('FACEBOOK_APP_ID'),
5+
'app_secret' => env('FACEBOOK_APP_SECRET'),
6+
'redirect_uri' => env('FACEBOOK_REDIRECT_URI'),
7+
'graph_version' => env('FACEBOOK_GRAPH_VERSION', 'v11.0'),
8+
'beta_mode' => env('FACEBOOK_ENABLE_BETA', false),
89
];

src/FacebookServiceProvider.php

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace JoelButcher\Facebook;
44

5-
use Facebook\Facebook;
6-
use Facebook\HttpClients\FacebookGuzzleHttpClient;
7-
use Facebook\HttpClients\FacebookHttpClientInterface;
85
use Facebook\PersistentData\PersistentDataInterface;
6+
use Facebook\Url\UrlDetectionHandler;
7+
use Facebook\Url\UrlDetectionInterface;
8+
use Http\Client\HttpClient;
99
use Illuminate\Contracts\Foundation\Application;
1010
use Illuminate\Support\ServiceProvider;
11+
use JoelButcher\Facebook\Facades\Facebook as FacebookFacade;
1112

1213
class FacebookServiceProvider extends ServiceProvider
1314
{
@@ -19,14 +20,14 @@ class FacebookServiceProvider extends ServiceProvider
1920
public function register(): void
2021
{
2122
$this->mergeConfig();
22-
$this->registerDefaultPersistentDataHandler();
2323
$this->registerDefaultHttpClient();
24+
$this->registerUrlDetectionHandler();
25+
$this->registerDefaultPersistentDataHandler();
2426
$this->registerFacebook();
25-
$this->registerFacebookWrapper();
2627

27-
// Register the Facebook Graph facade to allow method passthrough via __callStatic.
28-
// E.g. \JoelButcher\Facebook\Facebook::getClient()
29-
$this->app->singleton('facebook-graph', fn (Application $app) => $app[Facebook::class]);
28+
$this->app->singleton('facebook-graph', function (Application $app) {
29+
return $app[Facebook::class];
30+
});
3031
}
3132

3233
/**
@@ -70,23 +71,39 @@ protected function getConfigPath(): string
7071
}
7172

7273
/**
73-
* Register a default binding for the persistent data interface.
74+
* Register a default binding for the Facebook HTTP client interface.
7475
*
7576
* @return void
7677
*/
77-
protected function registerDefaultPersistentDataHandler(): void
78+
protected function registerDefaultHttpClient(): void
7879
{
79-
$this->app->singleton(PersistentDataInterface::class, fn () => null);
80+
$this->app->singleton(HttpClient::class, function () {
81+
return null;
82+
});
8083
}
8184

8285
/**
83-
* Register a default binding for the Facebook HTTP client interface.
86+
* Register the default URL Protection handler for the Facebook SDK.
8487
*
8588
* @return void
8689
*/
87-
protected function registerDefaultHttpClient(): void
90+
protected function registerUrlDetectionHandler(): void
8891
{
89-
$this->app->singleton(FacebookHttpClientInterface::class, fn () => new FacebookGuzzleHttpClient);
92+
$this->app->singleton(UrlDetectionInterface::class, function () {
93+
return new UrlDetectionHandler;
94+
});
95+
}
96+
97+
/**
98+
* Register a default binding for the persistent data interface.
99+
*
100+
* @return void
101+
*/
102+
protected function registerDefaultPersistentDataHandler(): void
103+
{
104+
$this->app->singleton(PersistentDataInterface::class, function () {
105+
return null;
106+
});
90107
}
91108

92109
/**
@@ -102,26 +119,15 @@ protected function registerFacebook(): void
102119
// a controller)
103120
$this->app->singleton(Facebook::class, function (Application $app) {
104121
return new Facebook([
105-
'app_id' => $app['config']->get('facebook.client_id'),
106-
'app_secret' => $app['config']->get('facebook.client_secret'),
107-
'enable_beta_mode' => $app['config']->get('facebook.enable_beta_mode'),
108-
'default_graph_version' => $app['config']->get('facebook.api_version'),
122+
'app_id' => $app['config']->get('facebook.app_id'),
123+
'app_secret' => $app['config']->get('facebook.app_secret'),
124+
'redirect_uri' => $app['config']->get('facebook.redirect_uri'),
125+
'default_graph_version' => $app['config']->get('facebook.graph_version'),
126+
'enable_beta_mode' => $app['config']->get('facebook.beta_mode'),
109127
'persistent_data_handler' => $app[PersistentDataInterface::class],
110-
'http_client_handler' => $app[FacebookHttpClientInterface::class],
128+
'http_client' => $app[HttpClient::class],
129+
'url_detection_handler' => $app[UrlDetectionInterface::class],
111130
]);
112131
});
113132
}
114-
115-
/**
116-
* Register a binding for the Facebook Graph PHP SDK wrapper.
117-
*
118-
* @return void
119-
*/
120-
protected function registerFacebookWrapper(): void
121-
{
122-
// Register the Facebook Graph manager as a wrapper for the Facebook SDK.
123-
$this->app->singleton(Facebook:: class, function (Application $app) {
124-
return new Facebook($app[Facebook::class]);
125-
});
126-
}
127133
}

0 commit comments

Comments
 (0)