PHPackages                             f3-factory/fatfree-psr7-factory - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. f3-factory/fatfree-psr7-factory

ActiveLibrary[HTTP &amp; Networking](/categories/http)

f3-factory/fatfree-psr7-factory
===============================

PSR-7/17 factory adapter for the PHP fat-free framework

1.0.1(4mo ago)015MITPHPPHP &gt;=8.0

Since Feb 3Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/f3-factory/fatfree-psr7-factory)[ Packagist](https://packagist.org/packages/f3-factory/fatfree-psr7-factory)[ RSS](/packages/f3-factory-fatfree-psr7-factory/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

HTTP Message plugin for PHP Fat-Free Framework
----------------------------------------------

[](#http-message-plugin-for-php-fat-free-framework)

This is a plugin to enable [PSR-7](https://www.php-fig.org/psr/psr-7/) HTTP message usage by the framework core.

In order to do so, this package can register any [PSR-17](https://www.php-fig.org/psr/psr-17/) compatible HTTP message factory to the frameworks' core dependency injection container, that can be used to create and hydrate a Request (or ServerRequest) object from current framework globals, so it can be consumed by the route-handling controller or [any other package](https://packagist.org/providers/psr/http-factory-implementation).

Installation
------------

[](#installation)

This plugin requires:

- at least [`fatfree-core`](https://github.com/f3-factory/fatfree-core) version 4.0
- the DI `CONTAINER` enabled
- an actual HTTP message implementation package to be installed, i.e.
    - [`f3-factory/fatfree-psr7`](https://github.com/f3-factory/fatfree-psr7)
    - or [`nyholm/psr7`](https://packagist.org/packages/nyholm/psr7)
    - or any other [PSR7 package](https://packagist.org/providers/psr/http-message-implementation).
- a [PSR17](https://packagist.org/providers/psr/http-factory-implementation) HTTP message factory implementation (already included in `f3-factory/fatfree-psr7`)

To install this package run:

```
composer require f3-factory/fatfree-psr7-factory
```

### Register factory service

[](#register-factory-service)

The HTTP message objects (PSR-7) are created by a related PSR-17 factory.

At first, we need to register the PSR-17 factories for every PSR-7 interface. Some PSR-17 packages have different factories for each interface, some share the same for all of them.

This example uses the `Psr17Factory` from our own [fatfree-psr7](https://github.com/f3-factory/fatfree-psr7) package, which is very fast and of course fat-free.

To install it run `composer require f3-factory/fatfree-psr7` OR install any other PSR-7 and PSR-17 package you'd like to use instead.

In your bootstrap code or front controller (i.e. index.php):

```
// create the PSR17 adapter
$psrAdapter = F3\Http\MessageFactory::instance();
// register the factories:
$psrAdapter->register(
    requestFactory:       Psr17Factory::class,
    responseFactory:      Psr17Factory::class,
    serverRequestFactory: Psr17Factory::class,
    uploadedFileFactory:  Psr17Factory::class,
    uriFactory:           Psr17Factory::class,
    streamFactory:        Psr17Factory::class,
);
// register the concrete Request / Response objects
$psrAdapter->registerRequest(RequestInterface::class);
$psrAdapter->registerResponse(ResponseInterface::class);
$psrAdapter->registerServerRequest(ServerRequestInterface::class);
```

**NB:** Instead of the code above, you can use this included shortcut, which will execute the same sequence for you, but it only works with our own fatfree-psr7 package:

```
MessageFactory::registerDefaults()
```

Registering the **RequestInterface**, **ServerRequestInterface** and **ResponseInterface** bindings will tell the dependency injection container which shortcut to use to resolve and hydrate the objects accordingly when you type-hinting them in your route controller.

This is essential to make the created request objects use the provided make methods by this factory in order to hydrate the objects with the actual data prepared by the framework. Requests use makeRequest/makeServerRequest and are filled with the currently available data from the F3 hive and SERVER globals. The Response factory will check for an existing response object in the `RESPONSE` hive variable and uses that instead to ensure you can pass the response between middlewares, route handlers or any other runtime services via dependency injection. You should return this object in route/middleware handlers, so the framework can care about the rest.

Usage
-----

[](#usage)

You can receive the Request and Response objects from any point now, i.e. from route handlers via auto-injection:

```
$f3->route('GET /hallo-world', function(
    Base $f3,
    RequestInterface $request,
    ResponseInterface $response,
    StreamFactoryInterface $streamFactory
) {
    $agent = $request->getHeaderLine('User-Agent');
    return $response->withBody($streamFactory
        ->createStream('Your user agent is: '.$agent));
});
```

Alternatively you can create a new request object anywhere manually. These are going to be hydrated from the currently available $\_SERVER and hive data via:

```
$request = $f3->make(RequestInterface::class);
// or
$request = MessageFactory::instance()->makeRequest();

// for Server Request:
$serverRequest = $f3->make(ServerRequestInterface::class);
// or
$serverRequest = MessageFactory::instance()->makeServerRequest();
```

`Response` and the other classes should be instantiated via the PSR17 factory directly and do not need any special treatment by the framework core.

### Move uploaded files

[](#move-uploaded-files)

This is an example how to use the ServerRequest object to move an uploaded file.

```
$f3->route('POST /upload', function(Base $app, ServerRequestInterface $request)
{
    $dir = './uploads/';
    // handle uploaded files
    $files = $request->getUploadedFiles();
    foreach ($files as $fieldName => $file) {
        if ($file instanceof UploadedFile) {
            $file->moveTo($dir.$file->getClientFilename());
        }
    }
};
```

For more usage examples see original [PSR Http message readme](https://github.com/php-fig/http-message):

- [PSR-7 Interfaces Method List](https://github.com/php-fig/http-message/blob/master/docs/PSR7-Interfaces.md)
- [PSR-7 Usage Guide](https://github.com/php-fig/http-message/blob/master/docs/PSR7-Usage.md)

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance78

Regular maintenance activity

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~342 days

Total

2

Last Release

121d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84cac52f5889d2bf6e710f2139dfc884824b2d7ce9c48a3bfe90704a94c85722?d=identicon)[ikkez](/maintainers/ikkez)

---

Top Contributors

[![ikkez](https://avatars.githubusercontent.com/u/1177647?v=4)](https://github.com/ikkez "ikkez (9 commits)")

---

Tags

psr-7http-messagepsr-17F3fatfree

### Embed Badge

![Health badge](/badges/f3-factory-fatfree-psr7-factory/health.svg)

```
[![Health](https://phpackages.com/badges/f3-factory-fatfree-psr7-factory/health.svg)](https://phpackages.com/packages/f3-factory-fatfree-psr7-factory)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k296.6M807](/packages/symfony-psr-http-message-bridge)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[laminas/laminas-diactoros

PSR HTTP Message implementations

546105.8M965](/packages/laminas-laminas-diactoros)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

86874.0k94](/packages/httpsoft-http-message)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
