{"id":15578548,"url":"https://github.com/phauthentic/attribute-serializer","last_synced_at":"2025-03-29T07:43:03.932Z","repository":{"id":224364267,"uuid":"763047393","full_name":"Phauthentic/attribute-serializer","owner":"Phauthentic","description":"A serializer to transform an object into an associative array by extracting data from its properties and constants based on the #[Serialize] attribute.","archived":false,"fork":false,"pushed_at":"2024-02-25T16:49:07.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T07:43:00.728Z","etag":null,"topics":["attributes","php8","serialization","serializer","solid-principles"],"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/Phauthentic.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-25T12:24:18.000Z","updated_at":"2024-06-04T10:22:34.000Z","dependencies_parsed_at":"2024-02-25T15:27:55.817Z","dependency_job_id":"ee96b7a8-501b-4434-80aa-78346209c0fa","html_url":"https://github.com/Phauthentic/attribute-serializer","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"ef986ecf6480092f2979b57fc84b36f97cfba837"},"previous_names":["phauthentic/attribute-serializer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phauthentic%2Fattribute-serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phauthentic%2Fattribute-serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phauthentic%2Fattribute-serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phauthentic%2Fattribute-serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Phauthentic","download_url":"https://codeload.github.com/Phauthentic/attribute-serializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246156029,"owners_count":20732359,"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":["attributes","php8","serialization","serializer","solid-principles"],"created_at":"2024-10-02T19:11:25.770Z","updated_at":"2025-03-29T07:43:03.893Z","avatar_url":"https://github.com/Phauthentic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Attribute Based Serializer\n\n![PHP \u003e= 8.1](https://img.shields.io/static/v1?label=PHP\u0026message=^8.1\u0026color=787CB5\u0026style=for-the-badge\u0026logo=php)\n![phpstan Level 8](https://img.shields.io/static/v1?label=phpstan\u0026message=Level%208\u0026color=%3CCOLOR%3E\u0026style=for-the-badge)\n![License: MIT](https://img.shields.io/static/v1?label=License\u0026message=MIT\u0026color=%3CCOLOR%3E\u0026style=for-the-badge)\n\nSerializer class for extracting data from objects annotated with the `#[Serialize]` attribute.\n\nThis class provides a method, serialize, to transform an object into an associative array by extracting data from its properties and constants based on the `#[Serialize]` attribute.\n\n## Installation\n\n```sh\ncomposer require phauthentic/attribute-serializer\n```\n\n## How to use it?\n\nAdd the `#[Serialize()]` attribute to the property or constant. You can rename the property in the resulting array by providing a name to the attribute `#[Serialize('other-name')]`.\n\n```php\nclass Example {\n    #[Serialize('username')]\n    private $name = 'serializer';\n}\n\nvar_dump((new Serializer())-\u003eserialize(new Example()));\n```\n\n```text\n[\n    'username' =\u003e 'serializer'\n]\n```\n\n### Dot notation for deep arrays\n\nField names can be dynamically renamed, even into deeper array structures, by using the dot notation.\n\n```php\nclass Example2 {\n    #[Serialize('first.second')]\n    private $name = 'serializer';\n}\n\nvar_dump((new Serializer())-\u003eserialize(new Example2());\n```\n\n```text\n[\n    'first' =\u003e [\n        'second' =\u003e 'serializer'\n    ]\n]\n```\n\n### ToArrayTrait\n\n```php\nclass Example3 {\n    use ToArrayTrait;\n\n    #[Serialize('username')]\n    private $name = 'serializer';\n}\n\nvar_dump((new Example3)-\u003etoArray());\n```\n\n```text\n[\n    'username' =\u003e 'serializer'\n]\n```\n\n## License\n\nCopyright Florian Krämer\n\nLicensed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphauthentic%2Fattribute-serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphauthentic%2Fattribute-serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphauthentic%2Fattribute-serializer/lists"}