| @@ 14-35 (lines=22) @@ | ||
| 11 | use GuzzleHttp\Event\RequestEvents; |
|
| 12 | use GuzzleHttp\Event\SubscriberInterface; |
|
| 13 | ||
| 14 | class CorrelationIdSubscriber implements SubscriberInterface |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @var CorrelationIdProvider |
|
| 18 | */ |
|
| 19 | private $provider; |
|
| 20 | ||
| 21 | public function __construct(CorrelationIdProvider $provider) |
|
| 22 | { |
|
| 23 | $this->provider = $provider; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function getEvents() |
|
| 27 | { |
|
| 28 | return ['before' => ['onBefore', RequestEvents::PREPARE_REQUEST - 10]]; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function onBefore(BeforeEvent $event, $name) |
|
| 32 | { |
|
| 33 | $event->getRequest()->addHeader(AbstractApiResponse::X_CORRELATION_ID, $this->provider->getCorrelationId()); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 13-34 (lines=22) @@ | ||
| 10 | use GuzzleHttp\Event\RequestEvents; |
|
| 11 | use GuzzleHttp\Event\SubscriberInterface; |
|
| 12 | ||
| 13 | class TokenSubscriber implements SubscriberInterface |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * @var TokenProvider |
|
| 17 | */ |
|
| 18 | private $provider; |
|
| 19 | ||
| 20 | public function __construct(TokenProvider $provider) |
|
| 21 | { |
|
| 22 | $this->provider = $provider; |
|
| 23 | } |
|
| 24 | ||
| 25 | public function getEvents() |
|
| 26 | { |
|
| 27 | return ['before' => ['onBefore', RequestEvents::PREPARE_REQUEST - 15]]; |
|
| 28 | } |
|
| 29 | ||
| 30 | public function onBefore(BeforeEvent $event, $name) |
|
| 31 | { |
|
| 32 | $event->getRequest()->addHeader('Authorization', 'Bearer ' . $this->provider->getToken()->getToken()); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||