{"id":23434928,"url":"https://github.com/gpslab/payload","last_synced_at":"2025-10-09T20:09:44.277Z","repository":{"id":62512137,"uuid":"92380867","full_name":"gpslab/payload","owner":"gpslab","description":"The simple infrastructure component for create payload message","archived":false,"fork":false,"pushed_at":"2020-01-11T18:41:31.000Z","size":39,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-13T09:45:27.798Z","etag":null,"topics":["cqrs","domain-event","infrastructure","payload","payload-message","php"],"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/gpslab.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":"2017-05-25T08:14:06.000Z","updated_at":"2021-04-21T15:03:58.000Z","dependencies_parsed_at":"2022-11-02T10:16:47.268Z","dependency_job_id":null,"html_url":"https://github.com/gpslab/payload","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/gpslab/payload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fpayload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fpayload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fpayload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fpayload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpslab","download_url":"https://codeload.github.com/gpslab/payload/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fpayload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265224170,"owners_count":23730348,"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":["cqrs","domain-event","infrastructure","payload","payload-message","php"],"created_at":"2024-12-23T12:34:03.924Z","updated_at":"2025-10-09T20:09:39.240Z","avatar_url":"https://github.com/gpslab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://img.shields.io/packagist/v/gpslab/payload.svg?maxAge=3600\u0026label=stable)](https://packagist.org/packages/gpslab/payload)\n[![Total Downloads](https://img.shields.io/packagist/dt/gpslab/payload.svg?maxAge=3600)](https://packagist.org/packages/gpslab/payload)\n[![Build Status](https://img.shields.io/travis/gpslab/payload.svg?maxAge=3600)](https://travis-ci.org/gpslab/payload)\n[![Coverage Status](https://img.shields.io/coveralls/gpslab/payload.svg?maxAge=3600)](https://coveralls.io/github/gpslab/payload?branch=master)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/gpslab/payload.svg?maxAge=3600)](https://scrutinizer-ci.com/g/gpslab/payload/?branch=master)\n[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/5f0a79de-cc65-4e9b-b9ab-bcb16aedcdec.svg?maxAge=3600\u0026label=SLInsight)](https://insight.sensiolabs.com/projects/5f0a79de-cc65-4e9b-b9ab-bcb16aedcdec)\n[![StyleCI](https://styleci.io/repos/92380867/shield?branch=master)](https://styleci.io/repos/92380867)\n[![License](https://img.shields.io/packagist/l/gpslab/payload.svg?maxAge=3600)](https://github.com/gpslab/payload)\n\n# The simple infrastructure component for create payload message\n\n## Installation\n\nPretty simple with [Composer](http://packagist.org), run:\n\n```sh\ncomposer require gpslab/payload\n```\n\n## Usage\n\nThis library automatically fill the properties of the object with payload data.\n\nFor example, create a simple message\n\n```php\nclass SimpleMessage extends PayloadMessage\n{\n    public $id = 0;\n\n    public $name = '';\n}\n```\n\nFill the message\n\n```php\n$message = new SimpleMessage([\n    'id' =\u003e 123,\n    'name' =\u003e 'foo',\n]);\n\n$message-\u003eid; // 123\n$message-\u003ename; // foo\n$message-\u003epayload(); // ['id' =\u003e 123, 'name' =\u003e 'foo']\n```\n\n\u003e **Note**\n\u003e\n\u003e All fields specified in the payload must exist.\n\n### Protected properties\n\nYou can use protected properties for data. It's convenient to make the properties as read-only.\n\n```php\nclass SimpleMessage extends PayloadMessage\n{\n    protected $id = 0;\n\n    protected $name = '';\n\n    public function id()\n    {\n        return $this-\u003eid;\n    }\n\n    public function name()\n    {\n        return $this-\u003ename;\n    }\n}\n```\n\nFill the message\n\n```php\n$message = new SimpleMessage([\n    'id' =\u003e 123,\n    'name' =\u003e 'foo',\n]);\n\n$message-\u003eid(); // 123\n$message-\u003ename(); // foo\n$message-\u003epayload(); // ['id' =\u003e 123, 'name' =\u003e 'foo']\n```\n\n\u003e **Note**\n\u003e\n\u003e For fill private properties you must use setters.\n\n### Property setters\n\nYou can mark properties as private and use setters for fill it. This will ensure the security of data and control their\ntype. You can mark the setters as protected to close the class from changes from the outside.\n\n```php\nclass SimpleMessage extends PayloadMessage\n{\n    private $id = 0;\n\n    private $name = '';\n\n    public function id(): integer\n    {\n        return $this-\u003eid;\n    }\n\n    protected function setId(integer $id)\n    {\n        $this-\u003eid = $id;\n    }\n\n    public function name(): string\n    {\n        return $this-\u003ename;\n    }\n\n    protected function setName(string $name)\n    {\n        $this-\u003ename = $name;\n    }\n}\n```\n\nFill the message\n\n```php\n$message = new SimpleMessage([\n    'id' =\u003e 123,\n    'name' =\u003e 'foo',\n]);\n\n$message-\u003eid(); // 123\n$message-\u003ename(); // foo\n$message-\u003epayload(); // ['id' =\u003e 123, 'name' =\u003e 'foo']\n```\n\n### CQRS\n\nYou can use payload in [CQRS](https://github.com/gpslab/cqrs) infrastructure.\n\nCommand to rename contact:\n\n```php\nclass RenameContactCommand extends PayloadCommand\n{\n    public $contact_id = 0;\n\n    public $new_name = '';\n}\n```\n\nQuery for get contact by identity:\n\n```php\nclass ContactByIdentityQuery extends PayloadQuery\n{\n    public $id = 0;\n}\n```\n\n### Domain Events\n\nYou can use payload in [Domain Events](https://github.com/gpslab/domain-event).\n\nEvent, contact was renamed:\n\n```php\nclass RenamedContactEvent extends PayloadDomainEvent\n{\n    public $contact_id = 0;\n\n    public $old_name = '';\n\n    public $new_name = '';\n}\n```\n\n\n### Serialize\n\nYou can serialize messages with Symfony [serializer](https://symfony.com/doc/current/components/serializer.html)\ncomponent. For do it you can use `PayloadNormalizer` or `TypedPayloadNormalizer` and\n[encode](https://symfony.com/doc/current/components/serializer.html#encoders) result to JSON, XML, YAML, CSV, etc.\n\n* `PayloadNormalizer` - can be used only for one class because he does not distinguish messages;\n* `TypedPayloadNormalizer` - adds to the normalized data the type of message received from `MessageTypeResolver` service.\n\nYou can use `ClassNameMessageTypeResolver` as a simplify resolver. It use the last part of class name as a messages type.\n\n* `\\Acme\\Demo\\SomeMessage` converted to `SomeMessage`\n* `\\Acme_Demo_SomeMessage` converted to `SomeMessage`\n\nBe careful with the use of this resolver and do not named message classes equally in different namespace.\n\n## License\n\nThis bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fpayload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpslab%2Fpayload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fpayload/lists"}