{"id":37000961,"url":"https://github.com/polymorphine/message","last_synced_at":"2026-01-14T00:06:22.053Z","repository":{"id":55677094,"uuid":"218475729","full_name":"polymorphine/message","owner":"polymorphine","description":"HTTP Message library implementing PSR-7 interface with PSR-17 factories","archived":false,"fork":false,"pushed_at":"2025-01-28T03:58:36.000Z","size":146,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-08-19T02:59:55.765Z","etag":null,"topics":["http","psr-17","psr-7","request","response"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polymorphine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-30T08:14:25.000Z","updated_at":"2025-01-28T03:58:39.000Z","dependencies_parsed_at":"2023-01-22T21:01:00.626Z","dependency_job_id":null,"html_url":"https://github.com/polymorphine/message","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/polymorphine/message","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polymorphine%2Fmessage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polymorphine%2Fmessage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polymorphine%2Fmessage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polymorphine%2Fmessage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polymorphine","download_url":"https://codeload.github.com/polymorphine/message/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polymorphine%2Fmessage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","psr-17","psr-7","request","response"],"created_at":"2026-01-14T00:06:21.351Z","updated_at":"2026-01-14T00:06:22.018Z","avatar_url":"https://github.com/polymorphine.png","language":"PHP","readme":"# Polymorphine/Message\n[![Latest stable release](https://poser.pugx.org/polymorphine/message/version)](https://packagist.org/packages/polymorphine/message)\n[![Build status](https://github.com/polymorphine/message/workflows/build/badge.svg)](https://github.com/polymorphine/message/actions)\n[![Coverage status](https://coveralls.io/repos/github/polymorphine/message/badge.svg?branch=develop)](https://coveralls.io/github/polymorphine/message?branch=develop)\n[![PHP version](https://img.shields.io/packagist/php-v/polymorphine/message.svg)](https://packagist.org/packages/polymorphine/message)\n[![LICENSE](https://img.shields.io/github/license/polymorphine/message.svg?color=blue)](LICENSE)\n### PSR-7 Http message implementation\n\n### Installation with [Composer](https://getcomposer.org/)\n```bash\ncomposer require polymorphine/message\n```\n\n### Basic usage\n\nPublic API of base classes in this package is an implementation of [PSR-7: HTTP message interfaces](https://www.php-fig.org/psr/psr-7/)\nand won't be described here. Below you'll find description of object instantiation methods and\ntheir parameter formatting specific to this package.\n\n#### PSR-17 Factories\nNot every aspect of created objects can be changed with mutation methods (like in `UriInterface`),\nthat's where the need for common factory interfaces came from. Packages that want to rely on abstract\npsr/message interface, and retain control of passing immutable parameters to encapsulated objects from\nwithin their classes will depend on [PSR-17: HTTP Factories](https://www.php-fig.org/psr/psr-17/).\nFor interoperability reasons Package includes implementations of these [factories](src/Factory).\n\n#### Direct instantiation\nConstructor instantiation for each of the classes described below allows to create fully configured\nobjects, and since some of them contains many encapsulated parameters instantiating such object might\nbe tedious and unreadable. For some, frequently created objects static constructors are provided to\npass some predefined parameters.\n\n##### ServerRequest\nThe straight forward way is to instantiate [`ServerRequest`](src/ServerRequest.php) from\nserver globals using `ServerRequest::fromGlobals()` named constructor and optionally overriding\nits parameters passing array with `server`, `get`, `post`, `cookie` or `files` keys:\n\n```php\nuse Polymorphine\\Message\\ServerRequest;\n\n$override['get'] = ['id' =\u003e 123];\n$request = ServerRequest::fromGlobals($override);\n```\n\nThis will be most typical way to create ServerRequest instance. Because complete ServerRequest\ncontains large amount of data, other methods of instantiation in production application use cases\nwould require much more effort, and they'll be used mostly for testing with only necessary values\nprovided. For example instead overriding server provided data you can fake it entirely by passing\nfilled arrays to factory's constructor:\n\n```php\nuse Polymorphine\\Message\\ServerRequest;\nuse Polymorphine\\Message\\ServerData;\n\n$request = new ServerRequest::fromServerData(new ServerData([\n    'server' =\u003e [...],\n    'get'    =\u003e [...],\n    'post'   =\u003e [...],\n    'cookie' =\u003e [...],\n    'files'  =\u003e [...]\n]));\n```\n\nOr create new instance directly passing various parameters: request method string, `UriInterface`,\n`StreamInterface` body, headers array and parameters with `UploadedFileInterface` array, protocol\nversion, parsed body, cookie array... etc. Check [`ServerRequest`](src/ServerRequest.php) constructor\nphpDoc and some of its [parameters implementations](#uri-stream--uploadedfile) for more details.\n\n##### Request \u0026 Response\n[`Request`](src/Request.php) can be created with constructor similar to used in `ServerRequest`,\nbut `$params` array uses only `version` and `target` keys that defaults to `1.1` and string resolved\nfrom `$uri` parameter.\n\n[`Response`](src/Response.php) comes with several convenient static constructors that create instance\npreconfigured with status code or specific headers (usually `Content-Type`). Default constructor\nparameters are similar to `Request` constructor where method and Uri were replaced by status code,\nand `reason` phrase instead `target` in params.\n\n##### Uri, Stream \u0026 UploadedFile\nDefault constructor for [`Uri`](src/Uri.php) requires array of segments, which is not convenient, but\nstatic `Uri::fromString()` method will create instance by parsing supplied string. \n\nConstructor for [`Stream`](src/Stream.php) takes stream resource type, but two static methods will\nhelp creating one - either with uri and access mode or with body string to encapsulate.\n\n[`UploadedFile`](src/UploadedFile.php) all constructor parameters can be derived from server's `$_FILES`\nsuperglobal. Actually all, except `StreamInterface`, could be passed directly. Secondary constructor\nmethod - `UploadedFile::fromFileArray()` - is a convenient way of translating superglobal into class\ninstance creating stream instance in the process.\n\nNote that for multiple files superglobal data structure is populated in somewhat transposed fashion,\nso extracting it to create multiple instances of `UploadedFile` requires some iterations over its\nnested structure. Since these objects will be used mostly as server request property, instances for\nmultiple files are created within [`ServerData`](src/ServerData.php) object. You can use this class\nto create the array of multiple uploaded files from transposed array (normally `$_FILES`) if you\nwant to do it separately:\n\n```php\n$serverData    = new ServerData(['files' =\u003e $_FILES]);\n$uploadedFiles = $serverData-\u003euploadeFiles();\n```\n\n##### UploadedFile for non-SAPI environments\n[`UploadedFileFactory`](src/Factory/UploadedFileFactory.php) by default creates `UploadedFile` instance\nfor web server environments, which support `$_FILES` superglobal and security mechanism that can tell\nwhether given file was really uploaded or not (you cannot simply pick any file in the filesystem and\nmove it somewhere else). In case of other types of http servers (like command line scripts listening\nfor http requests in some event loop), you cannot use `move_uploaded_file()` function and need to\nhandle this process differently.\n\nPackage includes [`NonSAPIUploadedFile`](src/NonSAPIUploadedFile.php) that can move file (stream) in\nnon-SAPI environments, but security part (recognising that file was uploaded) depends on implementation\nand should be resolved internally (when creating stream).\nYou can create its instance directly or with factory that was instantiated with specific sapi name\n(for example: `cli`) or empty string. You can also resolve it automatically and create either\n`UploadedFile` or `NonSAPIUploadedFile` depending on predefined `PHP_SAPI` constant:\n\n```php\n$factory = new UploadedFileFactory(PHP_SAPI);\n$file    = $factory-\u003ecreateUploadedFile($stream);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymorphine%2Fmessage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolymorphine%2Fmessage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymorphine%2Fmessage/lists"}