PHP code example of jenky / hermes
1. Go to this page and download the library: Download jenky/hermes 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/ */
jenky / hermes example snippets bash
php artisan vendor:publish
bash
php artisan vendor:publish --provider="Jenky\Hermes\HermesServiceProvider"
php
'default' => [
'middleware' => [
Jenky\Hermes\Middleware\RequestEvent::class,
],
],
php
'middleware' => [
// This won't work properly
GuzzleHttp\Middleware::log(logs(), new GuzzleHttp\MessageFormatter),
],
php
'default' => [
'tap' => [
App\Http\Client\CustomizeHandlerStack::class,
],
],
php
namespace App\Http\Client;
use Psr\Http\Message\RequestInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
class CustomizeHandlerStack
{
/**
* Customize the given handler stack instance.
*
* @param \GuzzleHttp\HandlerStack $stack
* @return void
*/
public function __invoke(HandlerStack $stack)
{
$stack->before('add_foo', Middleware::mapRequest(function (RequestInterface $request) {
return $request->withHeader('X-Baz', 'Qux');
}, 'add_baz');
}
}
php
namespace App\Support;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use Illuminate\Log\LogManager;
class LogMiddleware
{
/**
* The logger manager instance.
*
* @var \Illuminate\Log\LogManager
*/
protected $logger;
/**
* Create new log middleware instance.
*
* @param \Illuminate\Log\LogManager $logger
* @return void
*/
public function __construct(LogManager $logger)
{
$this->logger = $logger;
}
/**
* Customize the given handle stack instance.
*
* @param \GuzzleHttp\HandlerStack $stack
* @return void
*/
public function __invoke(HandlerStack $stack, ?string $channel = null, string $level = 'debug')
{
$stack->push(Middleware::log(
$this->logger->channel($channel), new MessageFormatter, $level
));
}
}
php
'default' => [
'tap' => [
App\Http\Client\LogMiddleware::class.':slack',
],
],
php
$response['name'];
// or
$response->name;