Created
August 18, 2015 01:38
-
-
Save gsherwood/524a798cb1caf26f9ad2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat temp.php | |
<?php | |
class Client extends GuzzleClient implements ClientInterface { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = []) { | |
$duration = isset($options['timeout']) ? $options['timeout'] : NULL; | |
$options['query']['token'] = $user->acquireToken($duration); | |
try { | |
$response = $this->send($this->createRequest($method, $url, $options)); | |
return $response; | |
} | |
catch (ApiException $exception) { | |
// If the token is invalid, we should delete it from storage so that a | |
// fresh token is fetched on the next request. | |
if ($exception->getCode() == 401) { | |
// Ensure the token will be deleted. | |
$user->invalidateToken(); | |
} | |
throw $exception; | |
} | |
} | |
} | |
$ phpcbf temp.php --standard=PSR2 | |
Changing into directory *removed* | |
Processing temp.php [PHP => 205 tokens in 25 lines]... DONE in 8ms (15 fixable violations) | |
=> Fixing file: 0/15 violations remaining [made 5 passes]... DONE in 41ms | |
Patched 1 file | |
Time: 76ms; Memory: 4.5Mb | |
$ cat temp.php | |
<?php | |
class Client extends GuzzleClient implements ClientInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function authenticatedRequest($method = 'GET', $url = null, UserInterface $user, $options = []) | |
{ | |
$duration = isset($options['timeout']) ? $options['timeout'] : null; | |
$options['query']['token'] = $user->acquireToken($duration); | |
try { | |
$response = $this->send($this->createRequest($method, $url, $options)); | |
return $response; | |
} catch (ApiException $exception) { | |
// If the token is invalid, we should delete it from storage so that a | |
// fresh token is fetched on the next request. | |
if ($exception->getCode() == 401) { | |
// Ensure the token will be deleted. | |
$user->invalidateToken(); | |
} | |
throw $exception; | |
} | |
} | |
} | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment