PHP code example of oat-sa / lib-correlation-ids
1. Go to this page and download the library: Download oat-sa/lib-correlation-ids 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 example snippets
declare(strict_types=1);
use Psr\Http\Message\RequestInterface;
use OAT\Library\CorrelationIds\Builder\CorrelationIdsRegistryBuilder;
use OAT\Library\CorrelationIds\Generator\CorrelationIdGenerator;
$builder = new CorrelationIdsRegistryBuilder(new CorrelationIdGenerator());
/** @var RequestInterface $request */
$registry = $builder->buildFromRequestHeaders($request->getHeaders());
...
$registry->getCurrentCorrelationId(); // current correlation id
$registry->getParentCorrelationId(); // parent correlation id (nullable)
$registry->getRootCorrelationId(); // root correlation id (nullable)
declare(strict_types=1);
use OAT\Library\CorrelationIds\Builder\CorrelationIdsRegistryBuilder;
use OAT\Library\CorrelationIds\Generator\CorrelationIdGenerator;
$builder = new CorrelationIdsRegistryBuilder(new CorrelationIdGenerator());
$registry = $builder->build(
'parentCorrelationId', // optional
'rootCorrelationId' // optional
);