PHP code example of qandidate / stack-request-id

1. Go to this page and download the library: Download qandidate/stack-request-id 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/ */

    

qandidate / stack-request-id example snippets

5
use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel($env, $debug);
$kernel->loadClassCache();

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
5
use Qandidate\Stack\RequestId;
use Qandidate\Stack\UuidRequestIdGenerator;
use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel($env, $debug);

// Stack it!
$generator = new UuidRequestIdGenerator(1337);
$stack = new RequestId($kernel, $generator);

$kernel->loadClassCache();

$request = Request::createFromGlobals();
$response = $stack->handle($request);
$response->send();
$kernel->terminate($request, $response);
5
$generator = new UuidRequestIdGenerator(1337);
$stack = new RequestId($kernel, $generator);
$stack->enableResponseHeader();
5
$stack->enableResponseHeader('My-Custom-Request-Id');
5
$generator = new UuidRequestIdGenerator(1337);
$stack = new RequestId($kernel, $generator, 'X-Request-Id', 'My-Custom-Request-Id');
5
$kernel = new AppKernel('dev', true);

$generator = new UuidRequestIdGenerator(1337);
$stack = (new Stack\Builder)
    ->push('Qandidate\Stack\RequestId', $generator, 'X-Request-Id', 'X-Request-Id')
    ->resolve($kernel);

$kernel->loadClassCache();

$request = Request::createFromGlobals();
$response = $stack->handle($request);
$response->send();
$kernel->terminate($request, $response);
XML
<service id="qandidate.stack.request_id.monolog_processor" class="Qandidate\Stack\RequestId\MonologProcessor">
  <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="255" />
  <tag name="monolog.processor" />
</service>