webclient / helper-form
用于创建带有文件的PSR-7请求的帮助程序
v1.0.1
2020-11-04 11:56 UTC
Requires
- php: >=7.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.7
- phpunit/phpunit: >=6.5
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-fileinfo: Need for defining mime types
- psr/http-factory-implementation: Choice your favorite psr-17 implementation
This package is auto-updated.
Last update: 2024-09-04 20:29:36 UTC
README
webclient/helper-form
用于创建带有文件的PSR-7请求的帮助程序。
安装
安装此包以及您喜欢的 psr-17实现。
composer require webclient/helper-form:^1.0
现在创建PSR-18 HTTP客户端的文件请求非常简单!
用法
<?php use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamFactoryInterface; use Webclient\Helper\Form\Wizard; /** * @var RequestFactoryInterface $requestFactory * @var StreamFactoryInterface $streamFactory */ $wizard = new Wizard($requestFactory, $streamFactory); $fh = fopen('/home/user42/.ssh/id_psa.pub', 'r+'); /** @var RequestInterface $request */ $request = $wizard ->createForm('http://localhost:8080/path?query=webclient#fragment', 'POST') ->addField('sign_up[login]', 'user42') ->addField('sign_up[password]', '$ecr3t') ->uploadFromString('about', 'hi!', 'about.txt', 'text/plain; charset=UTF-8') ->uploadFromFile('photo', '/home/user42/images/DCIM_4564.JPEG', 'image/jpeg', 'avatar.jpg') ->uploadFromResource('public_ssh_key', $fh, 'id_sra.pub', 'text/plain') ->createRequest() ;