fast-forward/http-factory 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fast-forward/http-factory

最新稳定版本:v1.2.0

Composer 安装命令:

composer require fast-forward/http-factory

包简介

Fast Forward PSR-7 HTTP Factory utility classes

README 文档

README

PHP Version Composer Package Tests Coverage Docs License GitHub Sponsors

PSR-11 PSR-17

A Fast Forward service provider and helper-factory package for PSR-17 and PSR-7 HTTP objects, built on top of Nyholm PSR-7 and Nyholm ServerRequestCreator.

Designed to work out of the box with the php-fast-forward/container autowiring system.

📦 Installation

composer require fast-forward/http-factory

Features

  • Reuses one Nyholm\Psr7\Factory\Psr17Factory instance for the standard PSR-17 interfaces
  • Registers Nyholm\Psr7Server\ServerRequestCreator and exposes ServerRequestInterface::class via fromGlobals()
  • Exposes FastForward\Http\Message\Factory\ResponseFactoryInterface for HTML, JSON, text, redirect, and no-content helpers
  • Exposes FastForward\Http\Message\Factory\StreamFactoryInterface for payload-aware JSON stream helpers
  • Keeps returned objects PSR-7 compatible

Usage

There are two similarly named response and stream factory interfaces:

  • Psr\Http\Message\ResponseFactoryInterface and Psr\Http\Message\StreamFactoryInterface for plain PSR-17 behavior
  • FastForward\Http\Message\Factory\ResponseFactoryInterface and FastForward\Http\Message\Factory\StreamFactoryInterface for Fast Forward helper methods

If you’re using fast-forward/container:

use FastForward\Container\container;
use FastForward\Config\ArrayConfig;
use FastForward\Container\ContainerInterface;

$config = new ArrayConfig([
    ContainerInterface::class => [
        // Reference the service provider by class name
        HttpMessageFactoryServiceProvider::class,
    ],
]);

$container = container($config);

$requestFactory = $container->get(Psr\Http\Message\RequestFactoryInterface::class);
$serverRequest = $container->get(Psr\Http\Message\ServerRequestInterface::class);
$responseFactory = $container->get(FastForward\Http\Message\Factory\ResponseFactoryInterface::class);
$streamFactory = $container->get(FastForward\Http\Message\Factory\StreamFactoryInterface::class);

$request = $requestFactory->createRequest('GET', '/health');

$jsonResponse = $responseFactory->createResponseFromPayload(['ok' => true]);
$htmlResponse = $responseFactory->createResponseFromHtml('<h1>Hello</h1>');
$redirectResponse = $responseFactory->createResponseRedirect('/login');
$noContentResponse = $responseFactory->createResponseNoContent();

$acceptedResponse = $responseFactory
    ->createResponse(202)
    ->withHeader('Content-Type', 'application/json; charset=utf-8')
    ->withBody($streamFactory->createStreamFromPayload(['queued' => true]));

Services Registered

The following services will be automatically registered in your container when using HttpMessageFactoryServiceProvider:

Service Interface Implementation Source
Psr\Http\Message\RequestFactoryInterface Nyholm\Psr7\Factory\Psr17Factory (via alias)
Psr\Http\Message\ResponseFactoryInterface Nyholm\Psr7\Factory\Psr17Factory (via alias)
Psr\Http\Message\ServerRequestFactoryInterface Nyholm\Psr7\Factory\Psr17Factory (via alias)
Psr\Http\Message\StreamFactoryInterface Nyholm\Psr7\Factory\Psr17Factory (via alias)
Psr\Http\Message\UploadedFileFactoryInterface Nyholm\Psr7\Factory\Psr17Factory (via alias)
Psr\Http\Message\UriFactoryInterface Nyholm\Psr7\Factory\Psr17Factory (via alias)
Nyholm\Psr7Server\ServerRequestCreatorInterface Nyholm\Psr7Server\ServerRequestCreator (via alias)
FastForward\Http\Message\Factory\ResponseFactoryInterface FastForward\Http\Message\Factory\ResponseFactory (via alias)
FastForward\Http\Message\Factory\StreamFactoryInterface FastForward\Http\Message\Factory\StreamFactory (via alias)
Nyholm\Psr7\Factory\Psr17Factory Registered via InvokableFactory
Nyholm\Psr7Server\ServerRequestCreator Registered via InvokableFactory, with dependencies
FastForward\Http\Message\Factory\ResponseFactory Registered via InvokableFactory
FastForward\Http\Message\Factory\StreamFactory Registered via InvokableFactory
Psr\Http\Message\ServerRequestInterface Created by calling fromGlobals() on ServerRequestCreator via MethodFactory

Documentation

The Sphinx documentation under docs/ covers:

  • beginner installation and quickstart flows
  • concrete ResponseFactory and StreamFactory classes
  • common response and payload-stream scenarios
  • alias mapping, compatibility, dependencies, and troubleshooting

License

This package is open-source software licensed under the MIT License.

Contributing

Contributions, issues, and feature requests are welcome!
Feel free to open a GitHub Issue or submit a Pull Request.

统计信息

  • 总下载量: 342
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固