PHP code example of oat-sa / lib-correlation-ids-guzzle
1. Go to this page and download the library: Download oat-sa/lib-correlation-ids-guzzle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oat-sa / lib-correlation-ids-guzzle example snippets
declare(strict_types=1);
use OAT\Library\CorrelationIds\Registry\CorrelationIdsRegistry;
use OAT\Library\CorrelationIds\Registry\CorrelationIdsRegistryInterface;
use OAT\Library\CorrelationIdsGuzzle\Factory\GuzzleClientFactory;
use OAT\Library\CorrelationIdsGuzzle\Middleware\CorrelationIdsGuzzleMiddleware;
/** @var CorrelationIdsRegistryInterface $registry */
$registry = new CorrelationIdsRegistry(...);
$clientFactory = new GuzzleClientFactory(new CorrelationIdsGuzzleMiddleware($registry)));
$client = $clientFactory->create(['some' => 'options']);
...
$client->request('GET', 'http://example.com'); // Will forward correlation ids as request headers automatically.
declare(strict_types=1);
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use OAT\Library\CorrelationIds\Registry\CorrelationIdsRegistry;
use OAT\Library\CorrelationIds\Registry\CorrelationIdsRegistryInterface;
use OAT\Library\CorrelationIdsGuzzle\Middleware\CorrelationIdsGuzzleMiddleware;
/** @var CorrelationIdsRegistryInterface $registry */
$registry = new CorrelationIdsRegistry(...);
$handlerStack = HandlerStack::create();
$handlerStack->push(Middleware::mapRequest(new CorrelationIdsGuzzleMiddleware($registry)));
$client = new Client(['handler' => $handlerStack]);
...
$client->request('GET', 'http://example.com'); // Will forward correlation ids as request headers automatically.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.