1. Go to this page and download the library: Download khovanskiy/yii2-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/ */
khovanskiy / yii2-request-id example snippets
use khovanskiy\yii2requestid\NginxRequestIdGenerator;
use khovanskiy\yii2requestid\RequestIdGenerator;
use khovanskiy\yii2requestid\RequestIdBootstrap;
use khovanskiy\yii2requestid\RequestIdLogFormatter;
return [
// Другие настройки...
'container' => [
'singletons' => [
RequestIdGenerator::class => NginxRequestIdGenerator::class,
],
],
// Другие настройки...
];
use khovanskiy\yii2requestid\RequestIdService;
// Получение сервиса через DI-контейнер
$requestIdService = Yii::$app->get(RequestIdService::class);
// Устанавливает или возвращает текущий Request ID.
// Если ID ещё не задан, будет сгенерирован новый.
// При необходимости можно передать собственный Request ID.
$requestIdService->setRequestId();
$requestIdService->setRequestId('Test_request_id');
$currentRequestId = $requestIdService->getRequestId();
echo "Текущий Request ID: " . $currentRequestId;
namespace app\components\RequestId;
use khovanskiy\yii2requestid\RequestIdGenerator;
class CustomRequestIdGenerator implements RequestIdGenerator
{
public function generateRequestId(): string
{
// Ваш собственный алгоритм генерации Request ID
return uniqid('req_', true);
}
}
use khovanskiy\yii2requestid\RequestIdGenerator;
use app\components\RequestId\CustomRequestIdGenerator;
return [
// Другие настройки...
'container' => [
'singletons' => [
RequestIdGenerator::class => CustomRequestIdGenerator::class,
],
],
// Другие настройки...
];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.