2
2
3
3
namespace JoelButcher \Facebook ;
4
4
5
- use Facebook \Facebook ;
6
- use Facebook \HttpClients \FacebookGuzzleHttpClient ;
7
- use Facebook \HttpClients \FacebookHttpClientInterface ;
8
5
use Facebook \PersistentData \PersistentDataInterface ;
6
+ use Facebook \Url \UrlDetectionHandler ;
7
+ use Facebook \Url \UrlDetectionInterface ;
8
+ use Http \Client \HttpClient ;
9
9
use Illuminate \Contracts \Foundation \Application ;
10
10
use Illuminate \Support \ServiceProvider ;
11
+ use JoelButcher \Facebook \Facades \Facebook as FacebookFacade ;
11
12
12
13
class FacebookServiceProvider extends ServiceProvider
13
14
{
@@ -19,14 +20,14 @@ class FacebookServiceProvider extends ServiceProvider
19
20
public function register (): void
20
21
{
21
22
$ this ->mergeConfig ();
22
- $ this ->registerDefaultPersistentDataHandler ();
23
23
$ this ->registerDefaultHttpClient ();
24
+ $ this ->registerUrlDetectionHandler ();
25
+ $ this ->registerDefaultPersistentDataHandler ();
24
26
$ this ->registerFacebook ();
25
- $ this ->registerFacebookWrapper ();
26
27
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
+ } );
30
31
}
31
32
32
33
/**
@@ -70,23 +71,39 @@ protected function getConfigPath(): string
70
71
}
71
72
72
73
/**
73
- * Register a default binding for the persistent data interface.
74
+ * Register a default binding for the Facebook HTTP client interface.
74
75
*
75
76
* @return void
76
77
*/
77
- protected function registerDefaultPersistentDataHandler (): void
78
+ protected function registerDefaultHttpClient (): void
78
79
{
79
- $ this ->app ->singleton (PersistentDataInterface::class, fn () => null );
80
+ $ this ->app ->singleton (HttpClient::class, function () {
81
+ return null ;
82
+ });
80
83
}
81
84
82
85
/**
83
- * Register a default binding for the Facebook HTTP client interface .
86
+ * Register the default URL Protection handler for the Facebook SDK .
84
87
*
85
88
* @return void
86
89
*/
87
- protected function registerDefaultHttpClient (): void
90
+ protected function registerUrlDetectionHandler (): void
88
91
{
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
+ });
90
107
}
91
108
92
109
/**
@@ -102,26 +119,15 @@ protected function registerFacebook(): void
102
119
// a controller)
103
120
$ this ->app ->singleton (Facebook::class, function (Application $ app ) {
104
121
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 ' ),
109
127
'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],
111
130
]);
112
131
});
113
132
}
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
- }
127
133
}
0 commit comments