songshenzong / http-client
基于 Guzzle 的 PHP HTTP 客户端扩展
此包的官方仓库似乎已不存在,因此该包已被冻结。
v1.0.0
2018-04-20 07:47 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.3
- songshenzong/support: ^1.0.0
Requires (Dev)
- laravel/framework: 5.6.*
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2021-12-08 18:46:12 UTC
README
HttpClient 是基于 Guzzle 的 PHP HTTP 客户端扩展,你可以使用 Guzzle 的所有方法,其优点包括:
- 静态使用 Guzzle 的所有方法。
- 以数组或对象形式访问
Response
。 - IDE 提示更友好。
- 其他方法,如
uri
等。 - 支持 Laravel,如
Queues
、Notifications
等。 - 始终与 Guzzle 同步。
$uri = HttpClient::uri('https://packagist.org.cn/search.json', ['q' => 'songshenzong']); // https://packagist.org.cn/search.json?q=songshenzong $response = HttpClient::request('GET', $uri); // $response = HttpClient::get($uri); // $response = HttpClient::post($uri); // $response = HttpClient::put($uri); // $response = HttpClient::delete($uri); print_r($response->toArray()); // Array // ( // [results] => Array // ) echo $response['total']; // 12 echo $response->total; // 12 var_dump($response->isJson()); // bool(true) var_dump($response->isXml()); // bool(false) var_dump($response->isSerialized()); // bool(false) print_r($response->serialize()); // s:2732:"{"results":[{"name":"songshenzong... var_dump($response->unserialize()); // false | object | array echo $response->getStatusCode(); // 200 echo $response->getHeaderLine('content-type'); // application/json echo $response->getBody(); // {"results":[{"name":"songshenzong...} // Send an asynchronous request. $promise = HttpClient::requestAsync('GET', $uri)->then(function ($response) { $response = new \Songshenzong\HttpClient\Response($response); echo $response['total']; }); $promise->wait();
安装
安装最新稳定版
composer require songshenzong/http-client
您可以使用 composer 进行更新
composer update
Laravel 队列
CurlJob::dispatch('GET', 'https://packagist.org.cn/search.json?q=songshenzong'); CurlJob::dispatchNow('GET', 'https://packagist.org.cn/search.json?q=songshenzong');
Laravel 通知
Notification::send($user, new CurlNotification('GET', 'https://packagist.org.cn/search.json?q=songshenzong'));
示例
/** * Get the notification's delivery channels. * * @param $notifiable * * @return array */ public function via($notifiable): array { return [HttpClientChannel::class]; } /** * @param $notifiable * * @return mixed */ public function toHttp($notifiable) { return HttpClient::request('GET', 'https://packagist.org.cn/search.json?q=songshenzong'); }
文档
HttpClient 是基于 Guzzle 的 PHP HTTP 客户端扩展,你可以使用 Guzzle 的所有方法。
支持
如果您在 Wiki 中找不到答案,请避免发布问题。您可以在 Songshenzong.com 上寻求支持。
许可证
此包采用 BSD 3-Clause 许可证。