PHPackages                             polymorphine/message - 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. polymorphine/message

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

polymorphine/message
====================

PSR-7 Http message implementation

1.2.5(1y ago)025MITPHPPHP ^7.4 || ^8.0

Since Oct 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/polymorphine/message)[ Packagist](https://packagist.org/packages/polymorphine/message)[ RSS](/packages/polymorphine-message/feed)WikiDiscussions develop Synced 3d ago

READMEChangelog (9)Dependencies (3)Versions (10)Used By (0)

Polymorphine/Message
====================

[](#polymorphinemessage)

[![Latest stable release](https://camo.githubusercontent.com/9c575835966ca701469bbb33d2f98db17f1a34f95a2a246d894b47007a8b693a/68747470733a2f2f706f7365722e707567782e6f72672f706f6c796d6f727068696e652f6d6573736167652f76657273696f6e)](https://packagist.org/packages/polymorphine/message)[![Build status](https://github.com/polymorphine/message/workflows/build/badge.svg)](https://github.com/polymorphine/message/actions)[![Coverage status](https://camo.githubusercontent.com/928711cfb87f55646c09d1eb9d3395835526d7f1b4764846cf565219bd20609d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f706f6c796d6f727068696e652f6d6573736167652f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/polymorphine/message?branch=develop)[![PHP version](https://camo.githubusercontent.com/b0d759bce1d079a4f4d06d8793a0e9551875f251334ec252d67f5ce9a2bc6b6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706f6c796d6f727068696e652f6d6573736167652e737667)](https://packagist.org/packages/polymorphine/message)[![LICENSE](https://camo.githubusercontent.com/f85791631ca5d1662eaf161b94a08939ff6d3b0cb6853d7a891484a3ddfcec71/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706f6c796d6f727068696e652f6d6573736167652e7376673f636f6c6f723d626c7565)](LICENSE)

### PSR-7 Http message implementation

[](#psr-7-http-message-implementation)

### Installation with [Composer](https://getcomposer.org/)

[](#installation-with-composer)

```
composer require polymorphine/message
```

### Basic usage

[](#basic-usage)

Public API of base classes in this package is an implementation of [PSR-7: HTTP message interfaces](https://www.php-fig.org/psr/psr-7/)and won't be described here. Below you'll find description of object instantiation methods and their parameter formatting specific to this package.

#### PSR-17 Factories

[](#psr-17-factories)

Not every aspect of created objects can be changed with mutation methods (like in `UriInterface`), that's where the need for common factory interfaces came from. Packages that want to rely on abstract psr/message interface, and retain control of passing immutable parameters to encapsulated objects from within their classes will depend on [PSR-17: HTTP Factories](https://www.php-fig.org/psr/psr-17/). For interoperability reasons Package includes implementations of these [factories](src/Factory).

#### Direct instantiation

[](#direct-instantiation)

Constructor instantiation for each of the classes described below allows to create fully configured objects, and since some of them contains many encapsulated parameters instantiating such object might be tedious and unreadable. For some, frequently created objects static constructors are provided to pass some predefined parameters.

##### ServerRequest

[](#serverrequest)

The straight forward way is to instantiate [`ServerRequest`](src/ServerRequest.php) from server globals using `ServerRequest::fromGlobals()` named constructor and optionally overriding its parameters passing array with `server`, `get`, `post`, `cookie` or `files` keys:

```
use Polymorphine\Message\ServerRequest;

$override['get'] = ['id' => 123];
$request = ServerRequest::fromGlobals($override);
```

This will be most typical way to create ServerRequest instance. Because complete ServerRequest contains large amount of data, other methods of instantiation in production application use cases would require much more effort, and they'll be used mostly for testing with only necessary values provided. For example instead overriding server provided data you can fake it entirely by passing filled arrays to factory's constructor:

```
use Polymorphine\Message\ServerRequest;
use Polymorphine\Message\ServerData;

$request = new ServerRequest::fromServerData(new ServerData([
    'server' => [...],
    'get'    => [...],
    'post'   => [...],
    'cookie' => [...],
    'files'  => [...]
]));
```

Or create new instance directly passing various parameters: request method string, `UriInterface`, `StreamInterface` body, headers array and parameters with `UploadedFileInterface` array, protocol version, parsed body, cookie array... etc. Check [`ServerRequest`](src/ServerRequest.php) constructor phpDoc and some of its [parameters implementations](#uri-stream--uploadedfile) for more details.

##### Request &amp; Response

[](#request--response)

[`Request`](src/Request.php) can be created with constructor similar to used in `ServerRequest`, but `$params` array uses only `version` and `target` keys that defaults to `1.1` and string resolved from `$uri` parameter.

[`Response`](src/Response.php) comes with several convenient static constructors that create instance preconfigured with status code or specific headers (usually `Content-Type`). Default constructor parameters are similar to `Request` constructor where method and Uri were replaced by status code, and `reason` phrase instead `target` in params.

##### Uri, Stream &amp; UploadedFile

[](#uri-stream--uploadedfile)

Default constructor for [`Uri`](src/Uri.php) requires array of segments, which is not convenient, but static `Uri::fromString()` method will create instance by parsing supplied string.

Constructor for [`Stream`](src/Stream.php) takes stream resource type, but two static methods will help creating one - either with uri and access mode or with body string to encapsulate.

[`UploadedFile`](src/UploadedFile.php) all constructor parameters can be derived from server's `$_FILES`superglobal. Actually all, except `StreamInterface`, could be passed directly. Secondary constructor method - `UploadedFile::fromFileArray()` - is a convenient way of translating superglobal into class instance creating stream instance in the process.

Note that for multiple files superglobal data structure is populated in somewhat transposed fashion, so extracting it to create multiple instances of `UploadedFile` requires some iterations over its nested structure. Since these objects will be used mostly as server request property, instances for multiple files are created within [`ServerData`](src/ServerData.php) object. You can use this class to create the array of multiple uploaded files from transposed array (normally `$_FILES`) if you want to do it separately:

```
$serverData    = new ServerData(['files' => $_FILES]);
$uploadedFiles = $serverData->uploadeFiles();
```

##### UploadedFile for non-SAPI environments

[](#uploadedfile-for-non-sapi-environments)

[`UploadedFileFactory`](src/Factory/UploadedFileFactory.php) by default creates `UploadedFile` instance for web server environments, which support `$_FILES` superglobal and security mechanism that can tell whether given file was really uploaded or not (you cannot simply pick any file in the filesystem and move it somewhere else). In case of other types of http servers (like command line scripts listening for http requests in some event loop), you cannot use `move_uploaded_file()` function and need to handle this process differently.

Package includes [`NonSAPIUploadedFile`](src/NonSAPIUploadedFile.php) that can move file (stream) in non-SAPI environments, but security part (recognising that file was uploaded) depends on implementation and should be resolved internally (when creating stream). You can create its instance directly or with factory that was instantiated with specific sapi name (for example: `cli`) or empty string. You can also resolve it automatically and create either `UploadedFile` or `NonSAPIUploadedFile` depending on predefined `PHP_SAPI` constant:

```
$factory = new UploadedFileFactory(PHP_SAPI);
$file    = $factory->createUploadedFile($stream);
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance42

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

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

Recently: every ~211 days

Total

9

Last Release

472d ago

PHP version history (3 changes)1.0.0PHP ^7.1

1.1.0PHP ^7.4

1.1.1PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b83b30083b2ca0951558f0516ded598877c690f2be60cf949d9be3fdf0389ca?d=identicon)[shudd3r](/maintainers/shudd3r)

---

Top Contributors

[![shudd3r](https://avatars.githubusercontent.com/u/9908030?v=4)](https://github.com/shudd3r "shudd3r (69 commits)")

---

Tags

httppsr-17psr-7requestresponse

### Embed Badge

![Health badge](/badges/polymorphine-message/health.svg)

```
[![Health](https://phpackages.com/badges/polymorphine-message/health.svg)](https://phpackages.com/packages/polymorphine-message)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[spiral/roadrunner-http

RoadRunner: HTTP and PSR-7 worker

779.2M48](/packages/spiral-roadrunner-http)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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