Skip to content

Commit

Permalink
Merge branch 'master' of github.com-sohaibilyas:sohaibilyas/facebook-…
Browse files Browse the repository at this point in the history
…php-sdk
  • Loading branch information
sohaibilyas committed May 12, 2020
2 parents 8b243d9 + b3b8b6f commit 37d3fce
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class Facebook

public function __construct(array $config = null)
{
if (!$config) {
if (! $config) {
throw new Exception('config array not provided to contructer');
}

if (!isset($config['app_id']) || $config['app_id'] == '') {
if (! isset($config['app_id']) || $config['app_id'] == '') {
throw new Exception('app_id not set in config array');
}

if (!isset($config['app_secret']) || $config['app_secret'] == '') {
if (! isset($config['app_secret']) || $config['app_secret'] == '') {
throw new Exception('app_secret not set in config array');
}

if (!isset($config['redirect_uri']) || $config['redirect_uri'] == '') {
if (! isset($config['redirect_uri']) || $config['redirect_uri'] == '') {
throw new Exception('redirect_uri not set in config array');
}

Expand All @@ -40,7 +40,7 @@ public function __construct(array $config = null)
}

$this->config = $config;
$this->client = new Client(['base_uri' => self::BASE_URL . '/' . $this->graphVersion]);
$this->client = new Client(['base_uri' => self::BASE_URL.'/'.$this->graphVersion]);
}

public function getConfig()
Expand All @@ -60,7 +60,7 @@ public function getAccessToken()

public function loggedIn()
{
if (!empty($this->accessToken)) {
if (! empty($this->accessToken)) {
return true;
}

Expand All @@ -69,7 +69,7 @@ public function loggedIn()
throw new Exception('state token did not match');
}

$this->accessToken = json_decode($this->client->get('/oauth/access_token?client_id=' . $this->config['app_id'] . '&client_secret=' . $this->config['app_secret'] . '&redirect_uri=' . $this->config['redirect_uri'] . '&code=' . $_GET['code'])->getBody())->access_token;
$this->accessToken = json_decode($this->client->get('/oauth/access_token?client_id='.$this->config['app_id'].'&client_secret='.$this->config['app_secret'].'&redirect_uri='.$this->config['redirect_uri'].'&code='.$_GET['code'])->getBody())->access_token;

return true;
}
Expand All @@ -83,12 +83,12 @@ public function getLoginUrl(array $permissions = [])
$this->state = bin2hex(random_bytes(20));
$_SESSION['state'] = $this->state;

return 'https://www.facebook.com/' . $this->graphVersion . '/dialog/oauth?client_id=' . $this->config['app_id'] . '&redirect_uri=' . $this->config['redirect_uri'] . '&scope=' . $permissions . '&state=' . $this->state;
return 'https://www.facebook.com/'.$this->graphVersion.'/dialog/oauth?client_id='.$this->config['app_id'].'&redirect_uri='.$this->config['redirect_uri'].'&scope='.$permissions.'&state='.$this->state;
}

public function post(string $path, array $params, string $accessToken = null)
{
$path = $path[0] == '/' ? $path : '/' . $path;
$path = $path[0] == '/' ? $path : '/'.$path;

$this->accessToken = $accessToken ? $accessToken : $this->accessToken;

Expand All @@ -97,7 +97,7 @@ public function post(string $path, array $params, string $accessToken = null)
$separator = '&';
}

$this->response = $this->client->post($path . $separator . 'access_token=' . $this->accessToken, [
$this->response = $this->client->post($path.$separator.'access_token='.$this->accessToken, [
'json' => $params,
]);

Expand All @@ -106,7 +106,7 @@ public function post(string $path, array $params, string $accessToken = null)

public function get(string $path, string $accessToken = null)
{
$path = $path[0] == '/' ? $path : '/' . $path;
$path = $path[0] == '/' ? $path : '/'.$path;

$this->accessToken = $accessToken ? $accessToken : $this->accessToken;

Expand All @@ -115,7 +115,7 @@ public function get(string $path, string $accessToken = null)
$separator = '&';
}

$this->response = $this->client->get($path . $separator . 'access_token=' . $this->accessToken);
$this->response = $this->client->get($path.$separator.'access_token='.$this->accessToken);

return $this;
}
Expand Down

0 comments on commit 37d3fce

Please sign in to comment.