From 028a02bdb7a872460ee168c5b772ae3444b51433 Mon Sep 17 00:00:00 2001 From: adrian7 Date: Mon, 2 Oct 2017 21:36:32 +0300 Subject: [PATCH] support for setting custom persistent data handler --- src/API/Facebook/App.php | 26 +++++++++++++++++++----- src/API/Facebook/GraphAccessProvider.php | 9 +++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/API/Facebook/App.php b/src/API/Facebook/App.php index 43fdd24..49c73f6 100644 --- a/src/API/Facebook/App.php +++ b/src/API/Facebook/App.php @@ -7,6 +7,7 @@ namespace DevLib\API\Facebook; +use Facebook\Facebook; use Facebook\Authentication\OAuth2Client; use Facebook\Exceptions\FacebookSDKException; use Facebook\Exceptions\FacebookResponseException; @@ -50,12 +51,13 @@ class App{ protected $provider; /** - * FB Login Constructor. + * FB App Constructor. * * @param $appId * @param $appSecret * @param $callbackURL * @param array $permissions + * @param null $persistentDataHandler * @param string $defaultGraphVersion */ public function __construct( @@ -63,17 +65,23 @@ public function __construct( $appSecret, $callbackURL, $permissions=['id', 'email'], - $defaultGraphVersion='v2.10' + $persistentDataHandler=NULL, + $defaultGraphVersion='latest' ) { $this->appId = $appId; $this->callbackUrl = $callbackURL; + $defaultGraphVersion = ( 'latest' == $defaultGraphVersion ) ? + Facebook::DEFAULT_GRAPH_VERSION : + $defaultGraphVersion; + //init provider $this->provider = GraphAccessProvider::getInstance([ - 'app_id' => $appId, - 'app_secret' => $appSecret, - 'default_graph_version' => $defaultGraphVersion + 'app_id' => $appId, + 'app_secret' => $appSecret, + 'persistent_data_handler' => $persistentDataHandler, + 'default_graph_version' => $defaultGraphVersion ]); //init redirect helper @@ -84,6 +92,14 @@ public function __construct( } + public static function create(){ + //TODO Allow creation using static + } + + public static function withGraphAccessProvider(GraphAccessProvider $provider){ + //TODO + } + /** * @param $message * @param string $type diff --git a/src/API/Facebook/GraphAccessProvider.php b/src/API/Facebook/GraphAccessProvider.php index 3bdfdac..f8c493b 100644 --- a/src/API/Facebook/GraphAccessProvider.php +++ b/src/API/Facebook/GraphAccessProvider.php @@ -69,15 +69,18 @@ protected function __construct(Facebook $facebook) { /** * Retrieve a graph access provider instance * @param array $params + * @param null|string $instanceId * - * @return GraphAccessProvider + * @return mixed */ - public static function getInstance(array $params){ + public static function getInstance(array $params, $instanceId=NULL){ if( ! isset($params['app_id']) or ! isset($params['app_secret']) ) throw new \InvalidArgumentException("Missing app_id or app_secret from input params... ."); - $instanceId = substr(strval($params['app_id']), 0, 7); + $instanceId = empty($instanceId) ? + substr( strval($params['app_id']), 0, 7 ) : + $instanceId; if( ! isset( self::$instances[$instanceId] ) ){