{"id":28399288,"url":"https://github.com/andreypostal/php-pancake-object","last_synced_at":"2025-06-28T19:31:25.945Z","repository":{"id":283732154,"uuid":"952720679","full_name":"andreypostal/php-pancake-object","owner":"andreypostal","description":"Light and simple helper to work with value objects by providing a serializer and hydrator using PHP Attributes.","archived":false,"fork":false,"pushed_at":"2025-03-31T17:06:32.000Z","size":31,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T15:24:07.717Z","etag":null,"topics":["deserialization","deserializer","hydrate","hydrator","parser","php","serialization","serializer","value-object"],"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/andreypostal.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":"2025-03-21T19:00:58.000Z","updated_at":"2025-04-03T12:54:20.000Z","dependencies_parsed_at":"2025-03-21T20:47:52.695Z","dependency_job_id":"0a53aeef-74c7-4d21-b850-d59516e006b5","html_url":"https://github.com/andreypostal/php-pancake-object","commit_stats":null,"previous_names":["andreypostal/php-pancake-object"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/andreypostal/php-pancake-object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypostal%2Fphp-pancake-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypostal%2Fphp-pancake-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypostal%2Fphp-pancake-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypostal%2Fphp-pancake-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreypostal","download_url":"https://codeload.github.com/andreypostal/php-pancake-object/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreypostal%2Fphp-pancake-object/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262484005,"owners_count":23318376,"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":["deserialization","deserializer","hydrate","hydrator","parser","php","serialization","serializer","value-object"],"created_at":"2025-06-01T07:39:49.590Z","updated_at":"2025-06-28T19:31:25.938Z","avatar_url":"https://github.com/andreypostal.png","language":"PHP","readme":"# 🥞 Pancake Object\n\n[![Coverage Status](https://coveralls.io/repos/github/andreypostal/php-pancake-object/badge.svg?branch=main\u0026t=1)](https://coveralls.io/github/andreypostal/php-pancake-object?branch=main)\n\nLight and simple helper to work with value objects by providing a serializer and hydrator using PHP Attributes.\nIt also provides a set of interfaces that allow you to customize the lib behavior to your needs.\n\n## Installation\n\n```\ncomposer require andreypostal/php-pancake-object\n```\n\n## Usage\n\n### Attributes usage\n\nCurrently, we have three main attributes available:\n- ValueObject\n- Item\n- SkipItem\n\nWhen creating your **Value Objects** you just need to add the attribute ``Item``\nto each property that you want to hydrate/serialize.\n\n```php\nuse \\Andrey\\PancakeObject\\Attributes\\Item;\n\n// { \"id\": 123, \"name\": \"my name\" }\nclass MyObject {\n    #[Item]\n    public int $id;\n    #[Item]\n    public string $name;\n}\n```\n\nIn the case where you want to serialize/hydrate every property from an object\n\n```php\nuse \\Andrey\\PancakeObject\\Attributes\\ValueObject;\n\n// { \"id\": 123, \"name\": \"my name\" }\n#[ValueObject]\nclass MyObject {\n    public int $id;\n    public string $name;\n}\n```\n\nYou can also combine both when need to add custom key, make an item required or even just skip some property.\n\n```php\nuse \\Andrey\\PancakeObject\\Attributes\\ValueObject;\nuse \\Andrey\\PancakeObject\\Attributes\\Item;\nuse \\Andrey\\PancakeObject\\Attributes\\SkipItem;\n\n// { \"id\": 123, \"custom_name\": \"my name\" }\n#[ValueObject]\nclass MyObject {\n    public int $id;\n    #[Item(key: 'custom_name')]\n    public string $name;\n    #[SkipItem]\n    public string $ignoredProperty;\n}\n```\n\nIn case the items are required to exist in the data array being used for hydration,\nyou can add the required flag in the attribute to include some basic required validation.\n\n```php\nuse \\Andrey\\PancakeObject\\Attributes\\Item;\n\n// { \"id\": 123 } or { \"id\": 123, \"name\": \"my name\" }\nclass MyObject {\n    #[Item(required: true)]\n    public int $id;\n    #[Item]\n    public string $name;\n}\n```\n\nWhen some of the keys in your data are different from your object, you can include the custom key in the attribute.\n\n```php\nuse \\Andrey\\PancakeObject\\Attributes\\Item;\n\n// { \"customer_name\": \"the customer name\" }\nclass MyObject {\n    #[Item(key: 'customer_name')]\n    public string $name;\n}\n```\n\nAlso, if you have a property that is an array of other object, you can inform the class in the attribute using the ``type`` option.\nThis will work as a hint so the hydrator can instantiate the appropriate object. This works with enums as well.\n\n```php\nuse \\Andrey\\PancakeObject\\Item;\nuse \\MyNamespace\\MyOtherObj;\n\n// { \"list\": [ { \"key\": \"value\" } ] }\nclass MyObject {\n    /** @var MyOtherObj[] */\n    #[Item(type: MyOtherObj::class)]\n    public array $list;\n}\n```\n\nThe type option can be used to validate that all the items in an array have some desired type as well, like \"string\", \"integer\"...\n\n### Hydrator and Serializer\n\nIn order to hydrate some value object following the attribute rules, you just need to use the SimpleHydrator class.\nWe also provide interfaces that allow you to customize the hydrator and key mapping strategy used (like snake case to pascal case).\n\nThe same applies to the SimpleSerializer class, used to serialize an object into an data array.\n\n```php\nuse \\Andrey\\PancakeObject\\SimpleHydrator;\nuse \\Andrey\\PancakeObject\\SimpleSerializer;\nuse \\MyNamespace\\MyObject;\n\n// Hydration phase\n$hydrator = new SimpleHydrator();\n\n$dataArray = $request-\u003ebody-\u003etoArray();\n$myObject = $hydrator-\u003ehydrate($dataArray, MyObject::class);\n\n// Serialization phase\n$serializer = new SimpleSerializer();\n$arr = $serializer-\u003eserialize($myObject);\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreypostal%2Fphp-pancake-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreypostal%2Fphp-pancake-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreypostal%2Fphp-pancake-object/lists"}