duncan3dc/guzzle-tools

一些用于与Guzzle一起工作的工具

0.5.0 2023-04-11 17:04 UTC

This package is auto-updated.

Last update: 2024-09-11 20:11:42 UTC


README

一个PHP库,为Guzzle提供一些附加功能。

release build coverage

安装

安装此库的推荐方法是使用Composer

从您的项目根目录运行以下命令

$ composer require duncan3dc/guzzle-tools

快速示例

日志记录

当使用Guzzle时,我厌倦了每次快速调试时都要搜索请求/响应的解决方案,这个库使它变得容易

$client = \duncan3dc\Guzzle\Factory::getClient();

$client->request("GET", "http://example.com/");

运行上述命令将在命令行上输出以下内容

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GET / HTTP/1.1
User-Agent: GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.1.0RC3
Host: example.com
--------------------------------------------------------------------------------
HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html
Date: Mon, 09 Jan 2017 14:42:17 GMT
Etag: "359670651+gzip+ident"
Expires: Mon, 16 Jan 2017 14:42:17 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (ewr/15BD)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
</head>
<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is established to be used for illustrative examples in documents. You may use this
    domain in examples without prior coordination or asking for permission.</p>
    <p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

请求构建

从版本6.0.0开始,Guzzle不再提供构建请求实例以稍后发送的方法,这个库提供了一个简单的解决方案

$request = \duncan3dc\Guzzle\Request::make("GET", "https://example.com/", [
    "query" =>  [
        "date"  =>  date("Y-m-d"),
    ],
]);

# There's also an alias on the main factory class
$request = \duncan3dc\Guzzle\Factory::request("GET", "https://example.com/");

简单请求

当您只需要基本的GET/POST时,您可以使用Http

$response = \duncan3dc\Guzzle\Http::get("https://example.com/", [
    "date"  =>  date("Y-m-d"),
]);

$response = \duncan3dc\Guzzle\Http::post("https://example.com/", [
    "date"  =>  date("Y-m-d"),
]);

变更日志

自一开始就有变更日志

如何获得帮助

发现了错误?有疑问?或者不确定某事如何工作?
创建一个问题,我将尽力帮助您。
或者您可以在Twitter上找到我

duncan3dc/guzzle-tools for enterprise

作为Tidelift订阅的一部分提供

duncan3dc/guzzle-tools的维护者以及成千上万的其他包维护者正在与Tidelift合作,为您的应用程序构建所使用的开源依赖项提供商业支持和维护。节省时间,降低风险,提高代码质量,同时支付您使用的确切依赖项的维护者。 了解更多。