承接 saeedhosan/guzzle-handler 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

saeedhosan/guzzle-handler

Composer 安装命令:

composer require saeedhosan/guzzle-handler

包简介

The package adds middlewire to laravel event for http client

README 文档

README

A Guzzle handler and middleware that dispatches Laravel HTTP Client events.

Introduction

This package provides a Guzzle handler that automatically dispatches standard Laravel HTTP client events (RequestSending, ResponseReceived, ConnectionFailed) when making requests. This allows you to leverage Laravel's built-in event listeners, logging, and monitoring even when using a custom Guzzle client instead of the Http facade.

Requirements

  • PHP ^8.2
  • Guzzle ^7.9
  • Laravel Framework ^11.0, ^12.0, or ^13.0

Installation

Install the package via composer:

composer require saeedhosan/guzzle-handler

Usages

Using the HttpClientEvent Handler

The HttpClientEvent handler can be used to wrap an existing Guzzle handler (like CurlHandler or MockHandler) to ensure Laravel events are dispatched.

use GuzzleHttp\Client;
use SaeedHosan\GuzzleHandler\Handlers\HttpClientEvent;

$handler = HttpClientEvent::make()
    ->withHandler(new \GuzzleHttp\Handler\CurlHandler());

$client = new Client([
    'handler' => $handler,
]);

// This request will now dispatch RequestSending and ResponseReceived events
$client->get('https://example.com');

Using mapFailure Middleware

You can also use the Middleware::mapFailure to handle request rejections with a custom callback:

use GuzzleHttp\HandlerStack;
use SaeedHosan\GuzzleHandler\Middleware;

$stack = HandlerStack::create();
$stack->push(Middleware::mapFailure(function ($reason) {
    // Handle the failure (e.g., log it or increment a counter)
}));

$client = new Client(['handler' => $stack]);

Testing

Run the tests using the following command:

composer test

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固