PHP code example of dpodsiadlo / ldt

1. Go to this page and download the library: Download dpodsiadlo/ldt 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/ */

    

dpodsiadlo / ldt example snippets


'providers' => [
	...
    DPodsiadlo\LDT\Providers\LDTServiceProvider::class,
]

protected $middleware = [
    ...
    \DPodsiadlo\LDT\Middleware\LogSender::class,        
];

use Log; //Laravel Log Facade

...

Log::emergency($error);
Log::alert($error);
Log::critical($error);
Log::error($error);
Log::warning($error);
Log::notice($error);
Log::info($error);
Log::debug($error);


use DPodsiadlo\LDT\LDT;
use DPodsiadlo\LDT\Log\Request;
use DPodsiadlo\LDT\Log\Response;

...

$params = ["param1" => "someValue"];
$targetUrl = "https://third-party-service.com";

$context = stream_context_create([
        'http' => [
            'header' => "Accept: */*\r\nContent-Type: application/json\r\nUser-Agent: API-WRAPER/1.0\r\n",
            'method' => "POST",
            'content' => json_encode($params),
            'ignore_errors' => true
        ]
    ]);


$res = file_get_contents($targetUrl, false, $context);


if (!empty($http_response_header)) {

    $status = (int)explode(' ', $http_response_header[0])[1];

    LDT::log(new Request($targetUrl, "POST", $params), new Response($res, $status, $http_response_header]), true);
}


use DPodsiadlo\LDT\LDT;
use DPodsiadlo\LDT\Log\Request;
use DPodsiadlo\LDT\Log\Response;

...

$params = ["param1" => "someValue"];
$targetUrl = "https://third-party-service.com";

$context = stream_context_create([
        'http' => [
            'header' => "Accept: */*\r\nContent-Type: application/json\r\nUser-Agent: API-WRAPER/1.0\r\n",
            'method' => "POST",
            'content' => json_encode($params),
            'ignore_errors' => true
        ]
    ]);


$res = file_get_contents($targetUrl, false, $context);


if (!empty($http_response_header)) {

    $status = (int)explode(' ', $http_response_header[0])[1];

    LDT::log(new Request($targetUrl, "POST", $params), new Response($res, $status, $http_response_header]), true, "third-party-log");
}