Last active
August 29, 2015 14:05
-
-
Save hpatoio/d5d0c2a772b3fb5f8a80 to your computer and use it in GitHub Desktop.
Guzzle4 subscribers for access_token
This file contains 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
<?php | |
namespace Hpatoio\Bitly\Subscribers; | |
use GuzzleHttp\Event\EmitterInterface; | |
use GuzzleHttp\Event\SubscriberInterface; | |
use GuzzleHttp\Command\Event\PrepareEvent; | |
class AccessTokenSubscriber implements SubscriberInterface | |
{ | |
private $accessToken; | |
public function __construct($accessToken) { | |
$this->accessToken = $accessToken; | |
} | |
public function getEvents() | |
{ | |
return [ | |
'prepare' => ['onPrepare'], | |
]; | |
} | |
public function onPrepare(PrepareEvent $event) | |
{ | |
// AddParam method doesn't exist in the original version of GuzzleHttp\Command | |
$event->getCommand()->addParam("access_token", $this->getAccessToken()); | |
} | |
public function getAccessToken() { | |
return $this->accessToken; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment