{"id":15027729,"url":"https://github.com/compositephp/entity","last_synced_at":"2025-07-03T07:34:28.982Z","repository":{"id":62035057,"uuid":"556999215","full_name":"compositephp/entity","owner":"compositephp","description":"Lightweight and smart PHP 8.1+ Entity class with automatic Data Mapping and serialization","archived":false,"fork":false,"pushed_at":"2025-05-26T11:13:37.000Z","size":95,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-12T06:07:23.120Z","etag":null,"topics":["datamapper","entity","hydration","php","php81","serialization"],"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/compositephp.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":"2022-10-24T22:56:24.000Z","updated_at":"2025-05-26T11:13:41.000Z","dependencies_parsed_at":"2025-04-09T20:32:20.122Z","dependency_job_id":"71641d48-74c2-4e16-8291-e4d457b20a0b","html_url":"https://github.com/compositephp/entity","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":0.5,"last_synced_commit":"ec666a1fe5c2c623a19432b8a0e19593956427a8"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/compositephp/entity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Fentity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Fentity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Fentity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Fentity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compositephp","download_url":"https://codeload.github.com/compositephp/entity/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compositephp%2Fentity/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262361661,"owners_count":23299084,"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":["datamapper","entity","hydration","php","php81","serialization"],"created_at":"2024-09-24T20:06:57.270Z","updated_at":"2025-07-03T07:34:28.939Z","avatar_url":"https://github.com/compositephp.png","language":"PHP","readme":"# Composite Entity\n[![Latest Stable Version](https://poser.pugx.org/compositephp/entity/v/stable)](https://packagist.org/packages/compositephp/entity)\n[![Build Status](https://github.com/compositephp/entity/actions/workflows/main.yml/badge.svg)](https://github.com/compositephp/entity/actions)\n[![Codecov](https://codecov.io/gh/compositephp/entity/branch/master/graph/badge.svg)](https://codecov.io/gh/compositephp/entity/)\n\nComposite Entity is a PHP 8.1+ lightweight class designed for efficient and intelligent data handling. \nIt specializes in the serialization and deserialization of data, making it highly beneficial for database management.\n\n## Features\n* Converts database rows to strictly typed objects and vice versa.\n* Streamlines database interactions.\n\nOverview:\n* [Requirements](#requirements)\n* [Installation](#installation)\n* [Quick example](#quick-example)\n* [Advanced usage](#advanced-usage)\n\n## Requirements\n\n* PHP 8.1 or higher.\n\n## Installation\n\nInstall using Composer::\n\n ```shell\n $ composer require compositephp/entity\n ```\n\n## Supported column types:\n\nComposite Entity supports a wide range of data types:\n\n* Basic types: String, Integer, Float, Bool, Array.\n* Complex types: Object (stdClass), DateTime/DateTimeImmutable, Enum.\n* Advanced types: Entity, Entity Lists or Maps, Collections (e.g., Doctrine Collection), Custom classes implementing Composite\\DB\\Entity\\CastableInterface.\n\n## Quick example\n\n```php\nuse Composite\\Entity\\AbstractEntity;\n\nclass User extends AbstractEntity\n{\n    public function __construct(\n        public readonly int $id,\n        public string $email,\n        public ?string $name = null,\n        public bool $is_test = false,\n        public array $languages = [],\n        public Status $status = Status::ACTIVE,\n        public readonly \\DateTimeImmutable $created_at = new \\DateTimeImmutable(),\n    ) {}\n}\n\nenum Status\n{\n    case ACTIVE;\n    case BLOCKED;\n}\n```\n\nExample of serialization:\n\n```php\n$user = new User(\n    id: 123,\n    email: 'john@example.com',\n    name: 'John',\n    is_test: false,\n    languages: ['en', 'fr'],\n    status: Status::BLOCKED,\n);\n\nvar_export($user-\u003etoArray());\n\n//will output\narray (\n  'id' =\u003e 123,\n  'email' =\u003e 'user@example.com',\n  'name' =\u003e 'John',\n  'is_test' =\u003e false,\n  'languages' =\u003e '[\"en\",\"fr\"]',\n  'status' =\u003e 'BLOCKED',\n  'created_at' =\u003e '2022-01-01 11:22:33.000000',\n)\n```\n\nYou can also deserialize (hydrate) entity from array:\n\n```php\n$user = User::fromArray([\n  'id' =\u003e 123,\n  'email' =\u003e 'user@example.com',\n  'name' =\u003e 'John',\n  'is_test' =\u003e false,\n  'languages' =\u003e '[\"en\",\"fr\"]',\n  'status' =\u003e 'BLOCKED',\n  'created_at' =\u003e '2022-01-01 11:22:33.000000',\n]);\n```\n\nAnd that's it. No need for special getters or setters, no additional \"behaviours\" or extra layers of code.\nComposite Entity handles everything automatically, ensuring seamless data casting.\n\n## Advanced usage\n\n### Custom Hydration\n\nFor tailored performance, implement your own hydrator:\n\n1. Create a class implementing `Composite\\Entity\\HydratorInterface`.\n2. Add `Composite\\Entity\\Attributes\\Hydrator` attribute to your entity class.\n\n### Useful Attributes\n\n* ####  Composite\\Entity\\Attributes\\SkipSerialization\n\n  Exclude properties from hydration.\n\n* #### Composite\\Entity\\Attributes\\ListOf\n\n  Define lists of entities within a property.\n\n  Example:\n  \n  ```php\n  use Composite\\Entity\\AbstractEntity;\n  use Composite\\Entity\\Attributes\\ListOf;\n  \n  class User extends AbstractEntity\n  {\n      public readonly int $id;\n      \n      public function __construct(\n          public string $name,\n          #[ListOf(Setting::class)]\n          public array $settings = [],\n      ) {}\n  }\n  \n  class Setting extends AbstractEntity\n  {\n      public function __construct(\n          public readonly string $name,\n          public bool $isActive,\n      ) {}\n  }\n  ```\n\n## License:\n\nMIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained by Composite PHP.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompositephp%2Fentity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompositephp%2Fentity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompositephp%2Fentity/lists"}