Skip to content

Instantly share code, notes, and snippets.

@hpatoio
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpatoio/d5d0c2a772b3fb5f8a80 to your computer and use it in GitHub Desktop.
Save hpatoio/d5d0c2a772b3fb5f8a80 to your computer and use it in GitHub Desktop.
Guzzle4 subscribers for access_token
<?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