Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
FIX: token regeneration GET request
Browse files Browse the repository at this point in the history
  • Loading branch information
kjschubert committed Jun 6, 2016
1 parent 6be6688 commit a0a7396
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ The PHP GIS Wrapper is tested with PHP unit. All the tests can be found in the f
If you send a pull request, please make sure that your code is covered and run phpunit in the root folder before you commit. Normally phpunit will automatically recognize the file phpunit.xml in the root folder.

# Changelog
## 0.2.3
- Fixed the token regeneration when a GET request runs with an expired token
## 0.2.2
- Fixed an issue in the parameter validation, which occured when parameters of different methods had the same name
## 0.2.1
Expand Down
26 changes: 13 additions & 13 deletions src/GET.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ class GET
* @throws NoResponseException
*/
public static function request($url, $auth) {
// init curl request
$req = curl_init();
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);

$attempts = 0;
$res = false;
while(!$res && $attempts < 3) {
$res = @file_get_contents($url . 'access_token=' . $auth->getToken());
if($res !== false) {
while($res === false && $attempts < 3) {
curl_setopt($req, CURLOPT_URL, $url . 'access_token=' . $auth->getToken());
$res = curl_exec($req);
if(curl_getinfo($req, CURLINFO_HTTP_CODE) == 401 && $attempts < 2) {
$auth->getNewToken();
$res = false;
} elseif($res) {
$res = json_decode($res);
if($res !== null) {
if(isset($res->status)) {
if($res->status->code == '401' && $attempts < 2) {
$res = false;
$auth->getNewToken();
}
}
} else {
$res = false;
}
if($res === null) $res = false;
}
$attempts++;
}

// validate response
if($res === false) {
throw new NoResponseException("Could not load endpoint " . $url);
Expand Down

0 comments on commit a0a7396

Please sign in to comment.