webclient/ext-cookie

PSR-18 HTTP客户端的Cookies扩展

v2.0.1 2022-11-12 17:34 UTC

This package is auto-updated.

Last update: 2024-09-12 21:52:25 UTC


README

Latest Stable Version Total Downloads License PHP

webclient/ext-cookie

PSR-18 HTTP客户端的Cookie扩展。

安装

安装此包和您喜欢的 psr-18实现

composer require webclient/ext-cookie:^2.0

使用

<?php

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Webclient\Extension\Cookie\CookieClientDecorator;
use Webclient\Extension\Cookie\Cookie\Storage;

/** 
 * @var ClientInterface $client Your PSR-18 HTTP Client
 * @var Storage $storage Cookies storage. You may extends this class for implements your storage
 */
$http = new CookieClientDecorator($client, $storage);

/** @var RequestInterface $request */
$response = $http->sendRequest($request);

提供的Cookies存储

  • \Webclient\Extension\Cookie\Cookie\ArrayStorage - 存储在内存中的Cookies。
  • \Webclient\Extension\Cookie\Cookie\NetscapeCookieFile - 存储在文件中(格式)。