PHP code example of tourze / request-id-bundle

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

    

tourze / request-id-bundle example snippets


// In your controllers, you can access the request ID:
use RequestIdBundle\Service\RequestIdStorage;

class MyController
{
    public function index(RequestIdStorage $requestIdStorage)
    {
        $currentRequestId = $requestIdStorage->getRequestId();
        // Use the request ID...
    }
}

// The message will automatically carry the current request ID
$messageBus->dispatch(new MyMessage());

// In message handlers, the original request ID is available:
public function handleMessage(MyMessage $message, RequestIdStorage $requestIdStorage)
{
    $originalRequestId = $requestIdStorage->getRequestId();
    // Process with original request context...
}

// In your commands:
use RequestIdBundle\Service\RequestIdStorage;

class MyCommand extends Command
{
    private RequestIdStorage $requestIdStorage;

    public function __construct(RequestIdStorage $requestIdStorage)
    {
        $this->requestIdStorage = $requestIdStorage;
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $commandRequestId = $this->requestIdStorage->getRequestId(); // CLI[uuid]
        // Use request ID...
    }
}

$logger->info('Processing user request', ['user_id' => 123]);
// Log output will