{"id":16389215,"url":"https://github.com/ddeboer/message-decorator","last_synced_at":"2026-06-17T12:31:45.262Z","repository":{"id":32581059,"uuid":"36164133","full_name":"ddeboer/message-decorator","owner":"ddeboer","description":"Decorators for PSR-7 HTTP Messages","archived":false,"fork":false,"pushed_at":"2015-05-24T09:06:39.000Z","size":100,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T16:05:30.926Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://php-http.org","language":"PHP","has_issues":false,"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/ddeboer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-24T09:01:29.000Z","updated_at":"2016-01-26T12:53:24.000Z","dependencies_parsed_at":"2022-07-16T18:00:31.378Z","dependency_job_id":null,"html_url":"https://github.com/ddeboer/message-decorator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ddeboer/message-decorator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddeboer%2Fmessage-decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddeboer%2Fmessage-decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddeboer%2Fmessage-decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddeboer%2Fmessage-decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddeboer","download_url":"https://codeload.github.com/ddeboer/message-decorator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddeboer%2Fmessage-decorator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34449277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"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":[],"created_at":"2024-10-11T04:31:56.500Z","updated_at":"2026-06-17T12:31:45.247Z","avatar_url":"https://github.com/ddeboer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Message Decorator\n\n[![Latest Version](https://img.shields.io/github/release/php-http/message-decorator.svg?style=flat-square)](https://github.com/php-http/message-decorator/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Build Status](https://img.shields.io/travis/php-http/message-decorator.svg?style=flat-square)](https://travis-ci.org/php-http/message-decorator)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/message-decorator.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message-decorator)\n[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/message-decorator.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/message-decorator)\n[![HHVM Status](https://img.shields.io/hhvm/php-http/message-decorator.svg?style=flat-square)](http://hhvm.h4cc.de/package/php-http/message-decorator)\n[![Total Downloads](https://img.shields.io/packagist/dt/php-http/message-decorator.svg?style=flat-square)](https://packagist.org/packages/php-http/message-decorator)\n\n**Decorators for PSR-7 HTTP Messages.**\n\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require php-http/message-decorator\n```\n\n\n## Usage\n\nThis package provides an easy way to decorate PSR-7 messages. While the decorator classes themselves are not abstract, they only make sense when they are extended to add custom logic:\n\n``` php\nuse Http\\Message\\RequestDecorator;\n\nclass MyRequestDecorator extends RequestDecorator\n{\n    public function isThisAPostRequest()\n    {\n        return $this-\u003egetMethod() === 'POST';\n    }\n}\n\n$request = new MyRequestDecorator($decoratedRequest);\n```\n\nIf you override the constructor, make sure that you accept a message argument (either request or response):\n\n``` php\nuse Http\\Message\\ResponseDecorator;\nuse Psr\\Http\\Message\\ResponseInterface;\n\nclass MyResponseDecorator extends ResponseDecorator\n{\n    public function __construct(ResponseInterface $message)\n    {\n        parent::__construct($message);\n\n        // some custom logic\n    }\n}\n```\n\nThe decorated messages are stored under a private `$message` property. To ease acces to this property, there is a public `getMessage` method available in both decorators.\n\n``` php\nuse Http\\Message\\ResponseDecorator;\n\nclass MyResponseDecorator extends ResponseDecorator\n{\n    public function stringifyResponse()\n    {\n        return (string) $this-\u003egetMessage()-\u003egetBody();\n    }\n}\n```\n\nSince the underlying message is immutable as well, there is no risk that you can alter it, so exposing it is safe. However the decorators are completely transparent, so there are rare cases when you want to access the original message.\n\n\n**Note:** Hence the immutability of both the decorators and the underlying messages, every writting operation causes two object cloning which definitely mean a bigger performance hit.\n\n\n## Testing\n\n``` bash\n$ phpspec run\n```\n\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n\n## Security\n\nIf you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org).\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddeboer%2Fmessage-decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddeboer%2Fmessage-decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddeboer%2Fmessage-decorator/lists"}