1. Go to this page and download the library: Download pachico/slim-correlationid 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/ */
pachico / slim-correlationid example snippets
fn(request, response, next): response
/**
* This example will just resolve the current correlation id from the request header.
* If not present, then it will create one and append it to the request and the response.
*/
use \Pachico\SlimCorrelationId\Middleware;
$app = new \Slim\App();
$app->add(new Middleware\CorrelationId());
/**
* It is also possible to set which key in the request haader it will try to resolve it from.
*/
use \Pachico\SlimCorrelationId\Middleware;
$app = new \Slim\App();
$app->add(new Middleware\CorrelationId([
'header_key' => 'X-CustomCorrelation-Id'
]));
/**
* In this case, we pass a callable that will be executed right after the correlation id
* is resolved.
* It might be useful for registering it to dependency containers, or instantiate objects
* with the id (loggers, http clients, etc)
*/
use \Pachico\SlimCorrelationId\Middleware;
use \Pachico\SlimCorrelationId\Model;
$app = new \Slim\App();
$dummyObject = (object) [
'correlationIdObject' => null
];
$customCallable = function (Model\CorrelationId $correlationid) use ($dummyObject) {
$dummyObject->correlationIdObject = $correlationid;
};
$app->add(new Middleware\CorrelationId([], $customCallable));
/**
* How ids are generated can also be customized by injecting a custom Id generator,
* as long as it implements the IdGenerator interface.
*/
use \Pachico\SlimCorrelationId\Middleware;
$app = new \Slim\App();
$app->add(new Middleware\CorrelationId([], null, new MyCustomIdGenerator()));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.