{"id":20744215,"url":"https://github.com/021-projects/api-entity","last_synced_at":"2025-04-14T12:06:39.961Z","repository":{"id":220976206,"uuid":"753110314","full_name":"021-projects/api-entity","owner":"021-projects","description":"Quickly and conveniently interpret JSON data into PHP classes","archived":false,"fork":false,"pushed_at":"2025-03-07T21:27:40.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T12:06:34.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/021-projects.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-05T13:46:32.000Z","updated_at":"2025-03-07T21:27:44.000Z","dependencies_parsed_at":"2024-11-17T07:14:46.136Z","dependency_job_id":"c9d9634d-d254-46c4-b32d-f2eeff9476bd","html_url":"https://github.com/021-projects/api-entity","commit_stats":null,"previous_names":["021-projects/api-entity"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/021-projects%2Fapi-entity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/021-projects%2Fapi-entity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/021-projects%2Fapi-entity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/021-projects%2Fapi-entity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/021-projects","download_url":"https://codeload.github.com/021-projects/api-entity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877985,"owners_count":21176243,"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":[],"created_at":"2024-11-17T07:14:43.107Z","updated_at":"2025-04-14T12:06:39.919Z","avatar_url":"https://github.com/021-projects.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# It's even easier to develop SDKs for your APIs\n\u003ca href=\"https://packagist.org/packages/021/api-entity\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/021/api-entity\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n[![run-tests](https://github.com/021-projects/api-entity/actions/workflows/run-tests.yml/badge.svg)](https://github.com/021-projects/api-entity/actions/workflows/run-tests.yml)\n\u003ca href=\"https://packagist.org/packages/021/api-entity\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/021/api-entity\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/021/api-entity\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/021/api-entity\" alt=\"License\"\u003e\u003c/a\u003e\n\nThis package allows you to quickly and conveniently interpret JSON data into PHP classes.\n\n## Support\nIf you like this package, you can support me by donating some cryptocurrency:\n#### Bitcoin\n1G4U12A7VVVaUrmj4KmNt4C5SaDmCXuW49\n#### Litecoin\nLXjysogo9AHiNE7AnUm4zjprDzCCWVESai\n#### Ethereum\n0xd23B42D0A84aB51a264953f1a9c9A393c5Ffe4A1\n#### Tron\nTWEcfzu2UAPsbotZJh8DrEpvdZGho79jTg\n\n## Installation\nYou can install the package via composer:\n\n```bash\ncomposer require 021/api-entity\n```\n\n## Usage\n\n### After 2.1\n2.1 version introduces an automatically casts parsing from phpdoc. \nYou can use `@property` and `@property-read` annotations to define property types.\n\n```php\nuse O21\\ApiEntity\\BaseEntity;\nuse O21\\ApiEntity\\Casts\\Getter;\nuse SDK\\Entities\\UserProfile; // Your custom class\nuse SDK\\Entities\\UserPet; // Your custom class\n\nuse function O21\\ApiEntity\\Response\\json_props;\n\n/**\n * Class User\n * @package SDK\\Entities\n *\n * @property int $id\n * @property string $firstName\n * @property string $lastName\n * @property \\Carbon\\Carbon $registerAt\n * @property UserProfile $profile\n * @property \\Illuminate\\Support\\Collection\u003cUserPet\u003e $pets\n * @property-read string $fullName\n */\nclass User extends BaseEntity\n{\n    public function fullName(): Getter\n    {\n        return Getter::make(fn() =\u003e $this-\u003efirstName.' '.$this-\u003elastName);\n    }\n}\n\n/** @var \\Psr\\Http\\Message\\ResponseInterface $response */\n$response = $api-\u003eget('/user/1');\n\n// Get decoded JSON array from response\n// which is a PSR-7 response or JSON string\n$props = json_props($response);\n// Create User object from JSON props\n$user = new User($props);\n\n// Or just pass response to BaseEntity constructor\n$user = new User($response);\n\necho $user-\u003efullName; // John Doe\necho $user-\u003efull_name; // John Doe\necho $user-\u003eregisterAt-\u003eformat('Y-m-d H:i:s'); // 2022-01-01 00:00:00\necho $user-\u003eprofile-\u003ephone; // +1234567890\necho $user-\u003epets-\u003efirst()-\u003ename; // Archy\n```\n\n### Before 2.1\n```php\nuse O21\\ApiEntity\\BaseEntity;\nuse O21\\ApiEntity\\Casts\\Getter;\nuse SDK\\Entities\\UserProfile; // Your custom class\nuse SDK\\Entities\\UserPet; // Your custom class\n\nuse function O21\\ApiEntity\\Response\\json_props;\n\n/**\n * Class User\n * @package SDK\\Entities\n *\n * @property int $id\n * @property string $firstName\n * @property string $lastName\n * @property \\Carbon\\Carbon $registerAt\n * @property UserProfile $profile\n * @property \\Illuminate\\Support\\Collection\u003cUserPet\u003e $pets\n * @property-read string $fullName\n */\nclass User extends BaseEntity\n{\n    protected array $casts = [\n        'registerAt' =\u003e 'datetime',\n        'profile' =\u003e UserProfile::class,\n        'pets' =\u003e 'collection:'.UserPet::class,\n    ];\n\n    public function fullName(): Getter\n    {\n        return Getter::make(fn() =\u003e $this-\u003efirstName.' '.$this-\u003elastName);\n    }\n}\n\n/** @var \\Psr\\Http\\Message\\ResponseInterface $response */\n$response = $api-\u003eget('/user/1');\n\n// Get decoded JSON array from response\n// which is a PSR-7 response or JSON string\n$props = json_props($response);\n// Create User object from JSON props\n$user = new User($props);\n\n// Or just pass response to BaseEntity constructor\n$user = new User($response);\n\necho $user-\u003efullName; // John Doe\necho $user-\u003efull_name; // John Doe\necho $user-\u003eregisterAt-\u003eformat('Y-m-d H:i:s'); // 2022-01-01 00:00:00\necho $user-\u003eprofile-\u003ephone; // +1234567890\necho $user-\u003epets-\u003efirst()-\u003ename; // Archy\n```\n\nCheck tests/Entities for more examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F021-projects%2Fapi-entity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F021-projects%2Fapi-entity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F021-projects%2Fapi-entity/lists"}