{"id":15693749,"url":"https://github.com/robbieaverill/psr7-adapters","last_synced_at":"2025-05-08T04:54:55.629Z","repository":{"id":62536433,"uuid":"78723468","full_name":"robbieaverill/psr7-adapters","owner":"robbieaverill","description":"PSR-7 compliant request and response interfaces for SilverStripe using Guzzle","archived":false,"fork":false,"pushed_at":"2023-05-10T23:22:22.000Z","size":41,"stargazers_count":1,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T04:54:49.266Z","etag":null,"topics":["adapters","psr-7","silverstripe"],"latest_commit_sha":null,"homepage":null,"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/robbieaverill.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-12T08:26:02.000Z","updated_at":"2022-10-05T04:43:50.000Z","dependencies_parsed_at":"2024-10-24T01:15:39.383Z","dependency_job_id":"2f7f292b-3519-454f-b996-37ae1e109f54","html_url":"https://github.com/robbieaverill/psr7-adapters","commit_stats":{"total_commits":32,"total_committers":6,"mean_commits":5.333333333333333,"dds":0.34375,"last_synced_commit":"a9a298fe71d04cdc283edda2ad8a5ded3dc83093"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robbieaverill%2Fpsr7-adapters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robbieaverill%2Fpsr7-adapters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robbieaverill%2Fpsr7-adapters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robbieaverill%2Fpsr7-adapters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robbieaverill","download_url":"https://codeload.github.com/robbieaverill/psr7-adapters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253002851,"owners_count":21838640,"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","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":["adapters","psr-7","silverstripe"],"created_at":"2024-10-03T18:48:18.489Z","updated_at":"2025-05-08T04:54:55.606Z","avatar_url":"https://github.com/robbieaverill.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# robbie/psr7-adapters\n\n[![Build Status](https://travis-ci.org/robbieaverill/psr7-adapters.svg?branch=master)](https://travis-ci.org/robbieaverill/psr7-adapters) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/robbieaverill/psr7-adapters/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/robbieaverill/psr7-adapters/?branch=master) [![codecov](https://codecov.io/gh/robbieaverill/psr7-adapters/branch/master/graph/badge.svg)](https://codecov.io/gh/robbieaverill/psr7-adapters)\n\n\nPSR-7 compliant, immutable adapter interfaces for SilverStripe HTTP classes.\n\n## Requirements\n\n* `silverstripe/framework` ^4.0\n* `guzzlehttp/psr7`\n\n## Installation\n\nInstall with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require robbie/psr7-adapters\n```\n\nAdd `?flush=1` to your browser URL, `flush=1` to your `sake` command arguments or `--flush` to your [`ssconsole`](https://github.com/silverleague/silverstripe-console).\n\n## Use\n\n### Converting to PSR-7\n\nThis module works by providing either a `HTTPRequest` or a `HTTPResponse` class that is pre-configured and ready to be sent to the client/server to the corresponding adapter class:\n\n* `HTTPRequest` uses the `Robbie\\Psr7\\HttpRequestAdapter` class\n* `HTTPResponse` uses the `Robbie\\Psr7\\HttpResponseAdapter` class\n\nTo retrieve a bootstrapped PSR-7 `ServerRequestInterface` or `ResponseInterface` you can call `-\u003etoPsr7($request)` on either of these classes, for example:\n\n```php\n\u003c?php\n\n$myResponse = new \\SilverStripe\\Control\\HTTPResponse(\n    json_encode(['success' =\u003e true, 'message' =\u003e 'Your request was successful!']),\n    200,\n    'OK'\n);\n\n/** @var \\Psr\\Http\\Message\\ResponseInterface $response */\n$response = (new \\Robbie\\Psr7\\HttpResponseAdapter)-\u003etoPsr7($myResponse);\n```\n\nFrom here you can use any of the PSR-7 interface methods, and the results will be immutable:\n\n```php\n\u003c?php\n\n$newResponse = $response-\u003ewithHeader('Content-Type', 'application/json');\n$newResponse = $newResponse-\u003ewithHeader('X-Custom-Header', 'my-value-here');\n\n// $response !== $newResponse -\u003e #psr7-ftw\n```\n\nThe same concept applies to the `HttpRequestAdapter`, for example:\n\n```php\n\u003c?php\n\n# Context: PageController\nuse Robbie\\Psr7\\HttpRequestAdapter;\n\n// ...\n\n$request = $this-\u003egetRequest();\n$adapter = new HttpRequestAdapter;\n$psrInterface = $adapter-\u003etoPsr7($request);\n\n// Outputs all your initial request headers:\nprint_r($psrInterface-\u003egetHeaders());\n```\n\n### Converting from PSR-7\n\nTo return a PSR-7 interface back to either an `HTTPRequest` or `HTTPResponse` class you simply need to do the same thing as going *to*, only use `-\u003efromPsr7($input)` instead:\n\n```php\n\u003c?php\n\n// $requestInterface is an instance of Psr\\Http\\Message\\ServerRequestInterface\n$httpRequest = (new HttpRequestAdapter)-\u003efromPsr7($requestInterface);\n```\n\n`$httpRequest` is now a `SilverStripe\\Control\\HTTPRequest` instance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobbieaverill%2Fpsr7-adapters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobbieaverill%2Fpsr7-adapters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobbieaverill%2Fpsr7-adapters/lists"}