{"id":21850319,"url":"https://github.com/terrylinooo/psr-http","last_synced_at":"2025-10-13T02:42:59.724Z","repository":{"id":44556938,"uuid":"266921201","full_name":"terrylinooo/psr-http","owner":"terrylinooo","description":"PSR-7, 15, 17 implementation.","archived":false,"fork":false,"pushed_at":"2023-06-06T08:30:52.000Z","size":302,"stargazers_count":18,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-13T02:42:59.402Z","etag":null,"topics":["php-psr","psr-15","psr-17","psr-7"],"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/terrylinooo.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-26T02:01:40.000Z","updated_at":"2025-08-17T14:37:36.000Z","dependencies_parsed_at":"2024-01-26T22:00:50.678Z","dependency_job_id":"da1386ea-e1ac-4dc6-968f-09e83cf938e2","html_url":"https://github.com/terrylinooo/psr-http","commit_stats":{"total_commits":102,"total_committers":2,"mean_commits":51.0,"dds":0.07843137254901966,"last_synced_commit":"b674a9b46e87a80f55a0aa6c21b1abe540bde409"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/terrylinooo/psr-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fpsr-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fpsr-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fpsr-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fpsr-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terrylinooo","download_url":"https://codeload.github.com/terrylinooo/psr-http/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terrylinooo%2Fpsr-http/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014015,"owners_count":26085345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["php-psr","psr-15","psr-17","psr-7"],"created_at":"2024-11-28T00:17:03.891Z","updated_at":"2025-10-13T02:42:59.702Z","avatar_url":"https://github.com/terrylinooo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSR 7, 15, 17 Implementation and Examples\n\n![build](https://github.com/terrylinooo/psr-http/workflows/build/badge.svg) [![codecov](https://img.shields.io/codecov/c/github/terrylinooo/psr-http.svg)](https://codecov.io/gh/terrylinooo/psr-http) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/terrylinooo/psr-http/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/terrylinooo/psr-http/?branch=master) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\nThis library is a PSR HTTP implementation created for [Shieldon firewall 2](https://github.com/terrylinooo/shieldon) , following up the PSR (PHP Standard Recommendation) documents by one hundred percent.\n\n- **PSR-7** (HTTP Message Interfaces)\n- **PSR-15** (HTTP Server Request Handlers)\n- **PSR-17** (HTTP Factories)\n\n### Test Status\n\nShiledon PSR-HTTP library is strictly tested by unit tests contain almost all conditions that might be happened, if you find any bug or something that can improve this library, please let me know.\n\n| Test suite | Status |\n| --- | --- |\n| Repository built-in tests | [![Build Status](https://travis-ci.org/terrylinooo/psr-http.svg?branch=master)](https://travis-ci.org/terrylinooo/psr-http) \n| [PSR-7 integration tests](https://github.com/terrylinooo/psr7-integration-tests) | [![Build Status](https://travis-ci.org/terrylinooo/psr7-integration-tests.svg?branch=shieldon-psr-http)](https://travis-ci.org/terrylinooo/psr7-integration-tests) \n\n\nYou can use it on any framework which is compatible with those PSRs.\n\n## Install\n\n```php\ncomposer require shieldon/psr-http\n```\n\n## Test\n```bash\ncomposer install\ncomposer test\n```\n\n## Quick Start\n\nThe simplest way to start implementing PSR-7 on your PHP applications, let's check out the examples below.\n\n*Create a server request.* \n\n```php\n\n$serverRequest = ServerRequestFactory::fromGlobal();\n```\n\n*Create a  request.*\n\n```php\n$request = RequestFactory::fromNew();\n```\n\n*Create a server response*\n\n```php\n$response = ResponseFactory::fromNew();\n```\n\n\n*Create a URI.*\n\n```php\n// Create a URI contains visitor's information.\n\n/**\n *  Assume a visior is viewing your website page, \n *  for example, https://yoursite/en/post1.html\n */\n$uri = UriFactory::fromGlobal();\n\necho $uri-\u003egetPath();\n// Outputs: /en/post1.html\n\n// Create a URI just a new instance.\n$uri = UriFactory::fromNew();\n\necho $uri-\u003egetPath();\n// Outputs: \n```\n\n*Create a stream instance.*\n\n```php\n// Create a stream just a new instance.\n$stream = StreamFactory::fromNew();\n```\n\n*Create an array with UploadedFile structure.*\n\n```php\n// Let's see the following example, \n// assume we have a superglobal $_FILES looks like this.\n$_FILES = [\n    'foo' =\u003e [\n        'name' =\u003e 'example1.jpg',\n        'type' =\u003e 'image/jpeg',\n        'tmp_name' =\u003e '/tmp/php200A.tmp',\n        'error' =\u003e 0,\n        'size' =\u003e 100000,\n    ]\n];\n\n$uploadFileArr = UploadedFileFactory::fromGlobal();\n\necho $uploadFileArr['foo']-\u003egetClientFilename();\n// Outputs: example1.jpg\n```\n\n## Table of Contents\n- ### **PSR-17**: *HTTP Factories*\n    - #### [RequestFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-RequestFactory-Example)\n        - [createRequest](https://github.com/terrylinooo/psr-http/wiki/RequestFactory:-createRequest-Example)\n        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/RequestFactory:-fromNew-Example)  `(Non-PSR)`\n    - #### [ServerRequestFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-ServerRequestFactory-Example)\n        - [createServerRequest](https://github.com/terrylinooo/psr-http/wiki/ServerRequestFactory:-createServerRequest-Example)\n        - [::fromGlobal](https://github.com/terrylinooo/psr-http/wiki/ServerRequestFactory:-fromGlobal-Example) `(Non-PSR)`\n    - #### [ResponseFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-ResponseFactory-Example)\n        - [createResponse](https://github.com/terrylinooo/psr-http/wiki/ResponseFactory:-createResponse-Example)\n        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/ResponseFactory:-fromNew-Example)  `(Non-PSR)`\n    - #### [StreamFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-StreamFactory-Example)\n        - [createStream](https://github.com/terrylinooo/psr-http/wiki/StreamFactory:-createStream-Example)\n        - [createStreamFromFile](https://github.com/terrylinooo/psr-http/wiki/StreamFactory:-createStreamFromFile-Example)\n        - [createStreamFromResource](https://github.com/terrylinooo/psr-http/wiki/StreamFactory:-createStreamFromResource-Example)\n        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/UploadedFileFactory:-fromNew-Example)  `(Non-PSR)`\n    - #### [UploadedFileFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-UploadedFileFactory-Example)\n        - [createUploadedFile](https://github.com/terrylinooo/psr-http/wiki/UploadedFileFactory:-createUploadedFile-Example)\n        - [::fromGlobal](https://github.com/terrylinooo/psr-http/wiki/UploadedFileFactory:-fromGlobal-Example)  `(Non-PSR)`\n    - #### [UriFactory](https://github.com/terrylinooo/psr-http/wiki/PSR-17:-UriFactory-Example)\n        - [createUri](https://github.com/terrylinooo/psr-http/wiki/UriFactory:-createUri-Example)\n        - [::fromGlobal](https://github.com/terrylinooo/psr-http/wiki/UriFactory:-fromGlobal-Example)  `(Non-PSR)`\n        - [::fromNew](https://github.com/terrylinooo/psr-http/wiki/UriFactory:-fromNew-Example)  `(Non-PSR)`\n- ### **PSR-7**: *HTTP Message Interfaces*\n    - #### [Message](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Message-Example)\n        - [getProtocolVersion](https://github.com/terrylinooo/psr-http/wiki/Message:-getProtocolVersion-Example)\n        - [withProtocolVersion](https://github.com/terrylinooo/psr-http/wiki/Message:-withProtocolVersion-Example)\n        - [setHeaders](https://github.com/terrylinooo/psr-http/wiki/Message:-setHeaders-Example) `(Non-PSR)`\n        - [getHeaders](https://github.com/terrylinooo/psr-http/wiki/Message:-getHeaders-Example)\n        - [hasHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-hasHeader-Example)\n        - [getHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-getHeader-Example)\n        - [getHeaderLine](https://github.com/terrylinooo/psr-http/wiki/Message:-getHeaderLine-Example)\n        - [withHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-withHeader-Example)\n        - [withAddedHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-withAddedHeader-Example)\n        - [withoutHeader](https://github.com/terrylinooo/psr-http/wiki/Message:-withoutHeader-Example)\n        - [getBody](https://github.com/terrylinooo/psr-http/wiki/Message:-getBody-Example)\n        - [withBody](https://github.com/terrylinooo/psr-http/wiki/Message:-withBody-Example)\n    - #### [Request](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Request-Example) *(externds Message)*\n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/Request:-__construct-Example) `(Non-PSR)`\n        - [getRequestTarget](https://github.com/terrylinooo/psr-http/wiki/Request:-getRequestTarget-Example)\n        - [withRequestTarget](https://github.com/terrylinooo/psr-http/wiki/Request:-withRequestTarget-Example)\n        - [getMethod](https://github.com/terrylinooo/psr-http/wiki/Request:-getMethod-Example)\n        - [withMethod](https://github.com/terrylinooo/psr-http/wiki/Request:-withMethod-Example)\n        - [getUri](https://github.com/terrylinooo/psr-http/wiki/Request:-getUri-Example)\n        - [withUri](https://github.com/terrylinooo/psr-http/wiki/Request:-withUri-Example)\n    - #### [ServerRequest](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-ServerRequest-Example) *(externds Request)*\n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-__construct-Example) `(Non-PSR)`\n        - [getServerParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getServerParams-Example)\n        - [getCookieParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getCookieParams-Example)\n        - [withCookieParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withCookieParams-Example)\n        - [getQueryParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getQueryParams-Example)\t\n        - [withQueryParams](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withQueryParams-Example)\t\n        - [getUploadedFiles](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getUploadedFiles-Example)\t\n        - [withUploadedFiles](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withUploadedFiles-Example)\t\n        - [getParsedBody](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getParsedBody-Example) (See explanation below)\n        - [withParsedBody](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withParsedBody-Example)\t\n        - [getAttributes](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getAttributes-Example)\t\n        - [getAttribute](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-getAttribute-Example)\n        - [withAttribute](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withAttribute-Example)\t\n        - [withoutAttribute](https://github.com/terrylinooo/psr-http/wiki/ServerRequest:-withoutAttribute-Example)\n    - #### [Response](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Response-Example) *(externds Message)*\n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/Request:-__construct-Example) `(Non-PSR)`\n        - [getStatusCode](https://github.com/terrylinooo/psr-http/wiki/Request:-getStatusCode-Example)\n        - [withStatus](https://github.com/terrylinooo/psr-http/wiki/Request:-withStatus-Example)\t\n        - [getReasonPhrase](https://github.com/terrylinooo/psr-http/wiki/Request:-getReasonPhrase-Example)\n    - #### [Stream](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Stream-Example) \n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/Stream:-__construct-Example) `(Non-PSR)`\n        - [isWritable](https://github.com/terrylinooo/psr-http/wiki/Stream:-isWritable-Example)\n        - [isReadable](https://github.com/terrylinooo/psr-http/wiki/Stream:-isReadable-Example)\n        - [isSeekable](https://github.com/terrylinooo/psr-http/wiki/Stream:-isSeekable-Example)\n        - [close](https://github.com/terrylinooo/psr-http/wiki/Stream:-close-Example)\n        - [detach](https://github.com/terrylinooo/psr-http/wiki/Stream:-detach-Example)\n        - [getSize](https://github.com/terrylinooo/psr-http/wiki/Stream:-getSize-Example)\n        - [tell](https://github.com/terrylinooo/psr-http/wiki/Stream:-tell-Example)\n        - [eof](https://github.com/terrylinooo/psr-http/wiki/Stream:-eof-Example)\n        - [seek](https://github.com/terrylinooo/psr-http/wiki/Stream:-seek-Example)\n        - [rewind](https://github.com/terrylinooo/psr-http/wiki/Stream:-rewind-Example)\n        - [write](https://github.com/terrylinooo/psr-http/wiki/Stream:-write-Example)\n        - [read](https://github.com/terrylinooo/psr-http/wiki/Stream:-read-Example)\n        - [getContents](https://github.com/terrylinooo/psr-http/wiki/Stream:-getContents-Example)\n        - [getMetadata](https://github.com/terrylinooo/psr-http/wiki/Stream:-getMetadata-Example)\n        - [__toString](https://github.com/terrylinooo/psr-http/wiki/Stream:-__toString-Example)\n    - #### [UploadedFile](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-UploadedFile-Example)\n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-__construct-Example) `(Non-PSR)`\n        - [getStream](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getStream-Example)\n        - [moveTo](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-moveTo-Example)\n        - [getSize](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getSize-Example)\n        - [getError](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getError-Example)\n        - [getClientFilename](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getClientFilename-Example)\n        - [getClientMediaType](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getClientMediaType-Example)\n        - [getErrorMessage](https://github.com/terrylinooo/psr-http/wiki/UploadedFile:-getErrorMessage-Example) `(Non-PSR)`\n    - #### [Uri](https://github.com/terrylinooo/psr-http/wiki/PSR-7:-Uri-Example)\n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/Uri:-__construct-Example) `(Non-PSR)`\n        - [getScheme](https://github.com/terrylinooo/psr-http/wiki/Uri:-getScheme-Example) \n        - [getAuthority](https://github.com/terrylinooo/psr-http/wiki/Uri:-getAuthority-Example) \n        - [getUserInfo](https://github.com/terrylinooo/psr-http/wiki/Uri:-getUserInfo-Example) \n        - [getHost](https://github.com/terrylinooo/psr-http/wiki/Uri:-getHost-Example) \n        - [getPort](https://github.com/terrylinooo/psr-http/wiki/Uri:-getPort-Example) \n        - [getPath](https://github.com/terrylinooo/psr-http/wiki/Uri:-getPath-Example) \n        - [getQuery](https://github.com/terrylinooo/psr-http/wiki/Uri:-getQuery-Example) \n        - [getFragment](https://github.com/terrylinooo/psr-http/wiki/Uri:-getFragment-Example) \n        - [withScheme](https://github.com/terrylinooo/psr-http/wiki/Uri:-withScheme-Example) \n        - [withUserInfo](https://github.com/terrylinooo/psr-http/wiki/Uri:-withUserInfo-Example) \n        - [withHost](https://github.com/terrylinooo/psr-http/wiki/Uri:-withHost-Example) \n        - [withPort](https://github.com/terrylinooo/psr-http/wiki/Uri:-withPort-Example) \n        - [withPath](https://github.com/terrylinooo/psr-http/wiki/Uri:-withPath-Example) \n        - [withQuery](https://github.com/terrylinooo/psr-http/wiki/Uri:-withQuery-Example) \n        - [withFragment](https://github.com/terrylinooo/psr-http/wiki/Uri:-withFragment-Example) \n        - [__toString](https://github.com/terrylinooo/psr-http/wiki/Uri:-__toString-Example) \n- ### **PSR-15**: *HTTP Server Request Handlers*\n    - #### [RequestHandler](https://github.com/terrylinooo/psr-http/wiki/PSR-15:-RequestHandler-Example)\n        - [__construct](https://github.com/terrylinooo/psr-http/wiki/RequestHandler:-__construct-Example) `(Non-PSR)`\n        - [add](https://github.com/terrylinooo/psr-http/wiki/RequestHandler:-add-Example)\n        - [handle](https://github.com/terrylinooo/psr-http/wiki/RequestHandler:-handle-Example)\n    - #### [Middleware](https://github.com/terrylinooo/psr-http/wiki/PSR-15:-Middleware-Example)\n        - [process](https://github.com/terrylinooo/psr-http/wiki/Middleware:-process-Example)\n\n\nIf you are looking for combined examples, see [unit testing](https://github.com/terrylinooo/psr-http/tree/master/tests).\n\n### The Behavior of Handling Request Body\n\nShieldon PSR-HTTP is ready for RESTful, the following content explains how PRS-HTTP deals with the request body.\n\nThe `getParsedBody` method will return:\n\n- **(A)** An array of the superglobal *$_POST* if the request request method is `POST` and the Content-Type is one of the following types:\n    - `multipart/form-data`\n    - `application/x-www-form-urlencode`\n    \n\n- **(B)** A JSON object if the request fit to the following conditions.\n    - The request Content-Type is `application/json`\n    - The request body is a valid *JSON-formatted* string.\n    - The request method is not `GET`.\n\n- **(C)** An array parsed from HTTP build query:\n    - The condition is neither A or B.\n    - The request method is not `GET`.\n\n- **(D)** `null` if the condition is none of above.\n\n#### Summary\n\n| Condition| Method | Content-type | Parsed-body |\n| --- | --- | --- | --- |\n| A | POST | multipart/form-data\u003cbr /\u003eapplication/x-www-form-urlencode | array |\n| B | ALL excepts GET | application/json | object  |\n| C | ALL excepts GET | All excepts A or B | array |\n| D | - | - | null |\n\nHope this helps.\n\n--- \n\n## Author\n\nShieldon PSR HTTP library is brought to you by [Terry L.](https://terryl.in) from Taiwan.\n\n## License\n\nMIT\n\n## References\n\n- [PSR-7](https://www.php-fig.org/psr/psr-7/) (HTTP Message Interfaces)\n- [PSR-15](https://www.php-fig.org/psr/psr-15/) (HTTP Server Request Handlers)\n- [PSR-17](https://www.php-fig.org/psr/psr-17/) (HTTP Factories)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrylinooo%2Fpsr-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterrylinooo%2Fpsr-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterrylinooo%2Fpsr-http/lists"}