PHPackages                             tebe/http-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. tebe/http-factory

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

tebe/http-factory
=================

HTTP Factory provides automatic detection for Composer packages implementing the PSR-17 standard

v3.0.0(3y ago)44.2k2[1 issues](https://github.com/tbreuss/http-factory/issues)1MITPHPPHP &gt;=8.0

Since Oct 11Pushed 3y ago2 watchersCompare

[ Source](https://github.com/tbreuss/http-factory)[ Packagist](https://packagist.org/packages/tebe/http-factory)[ RSS](/packages/tebe-http-factory/feed)WikiDiscussions master Synced yesterday

READMEChangelog (8)Dependencies (9)Versions (12)Used By (1)

🏭 HTTP-Factory
==============

[](#factory-http-factory)

[![Travis](https://camo.githubusercontent.com/cc1c73e8dc8c230dce5511f6b034559538571c3c5ece9fd65a3fa026f4239879/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f746272657573732f687474702d666163746f72792e737667)](https://travis-ci.org/tbreuss/http-factory)[![Scrutinizer](https://camo.githubusercontent.com/ee0e88d5d4e16e93c7a9f07276b438f8c216902be5a3e25c7c2a87ddac2a3f2e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f746272657573732f687474702d666163746f72792e737667)](https://scrutinizer-ci.com/g/tbreuss/http-factory/)[![Packagist](https://camo.githubusercontent.com/ea978edeb8d92d52a939d024fecbc8bb9fbf26df56b5a4c6d2d4b8d8b1267fe9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746562652f687474702d666163746f72792e737667)](https://packagist.org/packages/tebe/http-factory)[![GitHub (pre-)release](https://camo.githubusercontent.com/a468ff6af08244d6d5b163aec9eac4c8b198efa9f0e5488db3d61bb3310609df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f746272657573732f687474702d666163746f72792f616c6c2e737667)](https://github.com/tbreuss/http-factory/releases)[![License](https://camo.githubusercontent.com/a96c8c4c9d50b18339f232e048c79a1517cc21cc2016a1880d4db83bfdca1df4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746272657573732f687474702d666163746f72792e737667)](https://github.com/tbreuss/http-factory/blob/master/LICENSE)[![PHP from Packagist](https://camo.githubusercontent.com/f4ef584be3c5fe73d91ff5b21a1815c6decdc54adfd03b3ae47a44abced1176b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746562652f687474702d666163746f72792e737667)](https://packagist.org/packages/tebe/http-factory)

HTTP-Factory is a PHP package that implements [PSR-17 HTTP factories](https://www.php-fig.org/psr/psr-17/) interface. It acts as a simple facade to provide easy access to concrete HTTP factory packets. As its main feature it offers support for auto-discovery of the supported factories.

All PSR-17 interfaces are implemented:

- Psr\\Http\\Message\\ResponseFactoryInterface
- Psr\\Http\\Message\\ServerRequestFactoryInterface
- Psr\\Http\\Message\\StreamFactoryInterface
- Psr\\Http\\Message\\UploadedFileFactoryInterface
- Psr\\Http\\Message\\UriFactoryInterface

Additionally, it implements a createServerRequestFromGlobals method, which is not part of PSR-17.

Auto-discovering PSR-7 packages
-------------------------------

[](#auto-discovering-psr-7-packages)

The package features auto-discovery support for the following PSR-7 packages:

1. laminas/laminas-diactoros
2. guzzlehttp/psr7
3. slim/slim
4. nyholm/psr7

The auto-discovery mechanism assumes that you are using one (and only one) of the above PSR-7 packages in your project. The first detected PSR-17 package will then be used for all interface factory methods.

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

[](#installation)

When starting a new project one of the following PSR-7 packages must be installed.

```
$ composer require laminas/laminas-diactoros
$ composer require guzzlehttp/psr7
$ composer require slim/slim
$ composer require nyholm/psr7
```

When using the "nyholm/psr7" package you have to require the "nyholm/psr7-server" package, too.

```
$ composer require nyholm/psr7-server
```

Then install the HTTP-Factory package.

```
$ composer require tebe/http-factory
```

You can now use HTTP-Factory in the codebase of your project like so:

```
use Tebe\HttpFactory\HttpFactory;

$factory = new HttpFactory();

# creates a ResponseInterface
$factory->createResponse(int $code = 200, string $reasonPhrase = '');

# creates a ServerRequestInterface
$factory->createServerRequest(string $method, $uri, array $serverParams = []);

# creates a ServerRequestInterface
$factory->createServerRequestFromGlobals();

# creates a StreamInterface
$factory->createStream(string $content = '');

# creates a StreamInterface
$factory->createStreamFromFile(string $filename, string $mode = 'r');

# creates a StreamInterface
$factory->createStreamFromResource($resource);

# creates an UriInterface
$factory->createUri(string $uri = '');

# creates an UploadedFileInterface
$factory->createUploadedFile(
    StreamInterface $stream,
    int $size = null,
    int $error = \UPLOAD_ERR_OK,
    string $clientFilename = null,
    string $clientMediaType = null
);
```

Usage
-----

[](#usage)

### Using constructor

[](#using-constructor)

```
use Tebe\HttpFactory\HttpFactory;

$factory = new HttpFactory();
$response = $factory->createResponse(200);
echo $response->getStatusCode();
```

### Using static instance method

[](#using-static-instance-method)

```
use Tebe\HttpFactory\HttpFactory;

$response = HttpFactory::instance()->createResponse(200);
echo $response->getStatusCode();
```

### Using own strategies

[](#using-own-strategies)

```
use Tebe\HttpFactory\HttpFactory;

HttpFactory::setStrategies([
    DiactorosFactory::class,
    GuzzleFactory::class,
    SlimFactory::class
]);

$response = HttpFactory::instance()->createResponse(200);
echo $response->getStatusCode();
```

### Using own factory

[](#using-own-factory)

```
use Tebe\HttpFactory\HttpFactory;
use Tebe\HttpFactory\FactoryInterface;

class MyFactory implements FactoryInterface
{
    // implement interface methods
}

$factory = new HttpFactory();
$factory->setFactory(new MyFactory());
$response = $factory->createResponse(200);
echo $response->getStatusCode();
```

Tests
-----

[](#tests)

Run PHPUnit:

```
$ composer phpunit
```

Run PHP\_CodeSniffer:

```
$ composer phpcs
```

Run PHP Code Beautifier and Fixer:

```
$ composer phpcbf
```

Run PHPUnit and PHP\_CodeSniffer together:

```
$ composer test
```

Suggestions
-----------

[](#suggestions)

Any suggestions? Open an issue.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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 ~221 days

Recently: every ~382 days

Total

8

Last Release

1269d ago

Major Versions

v0.9.0 → v1.0.02018-11-02

v1.1.0 → v2.0.02022-10-01

v2.0.1 → v3.0.02023-01-10

PHP version history (4 changes)v0.8.0PHP ^7.0

v0.9.0PHP ^7.1

v2.0.0PHP &gt;=7.4

v3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e132a58c242510a02375872984be505a6b1adcf152214c0e96fb291d929c74ac?d=identicon)[thomasbreuss](/maintainers/thomasbreuss)

---

Top Contributors

[![tbreuss](https://avatars.githubusercontent.com/u/1334161?v=4)](https://github.com/tbreuss "tbreuss (43 commits)")

---

Tags

auto-discoverydiscoveryfactoryhacktoberfesthttp-factorymiddlewarepsr-17psr17httppsr-7middlewarePSR-11psr-17psr-15

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/tebe-http-factory/health.svg)

```
[![Health](https://phpackages.com/badges/tebe-http-factory/health.svg)](https://phpackages.com/packages/tebe-http-factory)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M125](/packages/mezzio-mezzio)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

587.2M101](/packages/laminas-laminas-stratigility)[middlewares/utils

Common utils for PSR-15 middleware packages

503.7M94](/packages/middlewares-utils)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

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

PHPackages © 2026

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