[VD:OneDrive,Box] optimize function *_refreshToken()

This commit is contained in:
nao-pon
2016-11-18 09:17:18 +09:00
parent 27da675f39
commit ac3b41c048
2 changed files with 35 additions and 35 deletions
+17 -17
View File
@@ -228,23 +228,24 @@ class elFinderVolumeBox extends elFinderVolumeDriver
/**
* Get token and auto refresh.
*
* @param object $box Box API client
*
* @return true|string error message
*/
protected function _bd_refreshToken($token)
protected function _bd_refreshToken()
{
if ($token->expires < time()) {
if ($this->token->expires < time()) {
if (!$token = $this->session->get('BoxTokens')) {
$token = $this->token;
}
if (empty($token->data->refresh_token)) {
$this->session->remove('BoxTokens');
throw new \Exception(elFinder::ERROR_REAUTH_REQUIRE);
}
if (null === $this->options['client_id']) {
if (!$this->options['client_id']) {
$this->options['client_id'] = ELFINDER_BOX_CLIENTID;
}
if (null === $this->options['client_secret']) {
if (!$this->options['client_secret']) {
$this->options['client_secret'] = ELFINDER_BOX_CLIENTSECRET;
}
@@ -271,7 +272,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver
$result = curl_exec($curl);
if (false === $result) {
if (!$result) {
if (curl_errno($curl)) {
throw new \Exception('curl_setopt_array() failed: '.curl_error($curl));
} else {
@@ -283,7 +284,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver
$decoded = json_decode($result);
if (null === $decoded) {
if (!$decoded) {
throw new \Exception('json_decode() failed');
}
@@ -621,7 +622,7 @@ class elFinderVolumeBox extends elFinderVolumeDriver
if ($this->token) {
try {
$this->_bd_refreshToken($this->token);
$this->_bd_refreshToken();
} catch (Exception $e) {
$this->setError($e->getMessage());
$this->token = null;
@@ -745,15 +746,14 @@ class elFinderVolumeBox extends elFinderVolumeDriver
return $this->setError('Required option `accessToken` is undefined.');
}
if (!$this->token) {
try {
$this->token = json_decode($this->options['accessToken']);
$this->_bd_refreshToken($this->token);
} catch (Exception $e) {
$this->setError($e->getMessage());
try {
$this->token = json_decode($this->options['accessToken']);
$this->_bd_refreshToken();
} catch (Exception $e) {
$this->token = null;
$this->session->remove('BoxTokens');
return $this->setError($e->getMessage());
}
return $this->setError($e->getMessage());
}
if (empty($options['netkey'])) {