mjelamanov / psr17-httplug
httplug 的消息工厂的 PSR-17 适配器
1.1.1
2021-11-07 13:15 UTC
Requires
- php: >=7.0
- php-http/message-factory: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.5
- http-interop/http-factory-tests: >=0.5.0
- php-http/message: >=1.7
Provides
This package is auto-updated.
Last update: 2024-09-07 19:40:15 UTC
README
php-http/message-factory 的 PSR-17 适配器 php-http/message-factory
此包提供了 PSR-18 的所有实现,除了 Psr\Http\Message\ServerRequestFactoryInterface
和 Psr\Http\Message\UploadedFileFactoryInterface
,因为 php-http/message-factory 包没有类似的工厂
需求
PHP 7.0 或更高版本。
安装
$ composer require mjelamanov/psr17-httplug
RequestFactory
use Mjelamanov\Psr17Httplug\RequestFactory; use Http\Message\MessageFactory\GuzzleMessageFactory; // A php-http's request factory implementation $requestFactory = new RequestFactory(new GuzzleMessageFactory()); $request = $requestFactory->createRequest('GET', 'http://example.com');
StreamFactory
use Mjelamanov\Psr17Httplug\StreamFactory; use Http\Message\StreamFactory\GuzzleStreamFactory; // A php-http's stream factory implementation $streamFactory = new StreamFactory(new GuzzleStreamFactory()); // Create from string $stream = $streamFactory->createStream(json_encode(['test' => true])); // Create from resource $stream = $streamFactory->createStreamFromResource(fopen('path/to/file', 'r')); // Create from file $stream = $streamFactory->createStreamFromFile('path/to/file', 'r');
UriFactory
use Mjelamanov\Psr17Httplug\UriFactory; use Http\Message\StreamFactory\GuzzleUriFactory; // A php-http's uri factory implementation $uriFactory = new UriFactory(new GuzzleUriFactory()); $uri = $uriFactory->createUri('http://example.com');
ResponseFactory
use Mjelamanov\Psr17Httplug\ResponseFactory; use Http\Message\StreamFactory\GuzzleMessageFactory; // A php-http's response factory implementation $responseFactory = new ResponseFactory(new GuzzleMessageFactory()); $response = $responseFactory->createResponse(200, 'OK');
测试
composer test
许可证
MIT 许可证。阅读 LICENSE 文件。