{"id":41505963,"url":"https://github.com/nixihz/php-object","last_synced_at":"2026-01-23T19:33:46.373Z","repository":{"id":57027583,"uuid":"422436269","full_name":"nixihz/php-object","owner":"nixihz","description":"Allows generate class files parse from json and map json to php object, including multi-level and complex objects.","archived":false,"fork":false,"pushed_at":"2021-10-29T04:12:22.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-03T04:47:26.112Z","etag":null,"topics":["generate-code","json-2-object","object","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nixihz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-29T03:59:07.000Z","updated_at":"2024-05-08T16:31:34.000Z","dependencies_parsed_at":"2022-08-23T16:30:15.658Z","dependency_job_id":null,"html_url":"https://github.com/nixihz/php-object","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nixihz/php-object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixihz%2Fphp-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixihz%2Fphp-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixihz%2Fphp-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixihz%2Fphp-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixihz","download_url":"https://codeload.github.com/nixihz/php-object/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixihz%2Fphp-object/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28698894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["generate-code","json-2-object","object","php"],"created_at":"2026-01-23T19:33:46.053Z","updated_at":"2026-01-23T19:33:46.367Z","avatar_url":"https://github.com/nixihz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nixihz/php-object\n\nAllows generate class files parse from json and map json to php object, including multi-level and complex objects;\n\n## Installation\n\nYou can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):\n\n```\ncomposer require nixihz/php-object\n```\n\nIf you only need this library during development, for instance to run your project's test suite, then you should add it\nas a development-time dependency:\n\n```\ncomposer require --dev nixihz/php-object\n```\n\n## Feature\n\n- [x] Generate PHP Class files from json\n- [x] Map json to object\n\n## Generate PHP class file from json\n\nOnce you have executed `composer require nixihz/php-object`\nyou could use `vendor/bin/php-object-gen` to generate class file from json\n\nUsage：\n\n1. demo\n```shell\n$./vendor/bin/php-object-gen --path=/tmp --json='{\"foo_bar\":{\"foo\":1.3,\"bar\":[641,641]}}'\n\noutput\nClass FooBar saved at: /tmp/FooBar.php\nClass BaseClass saved at: /tmp/BaseClass.php\n\n\n```\n\n2. add params `--help` for more \n\n```shell\n$./vendor/php-object-gen --helper\n\n```\n\n## Map json to object \n`fromJson` map json to object\n\n```php\n\nclass FooBarClass extends PhpObject\n{\n    /** @var string */\n    public $foo;\n\n    /** @var integer */\n    public $bar;\n}\n\nclass DemoClass extends PhpObject\n{\n    /** @var FooBarClass */\n    public $foobar;\n\n    /** @var FooBarClass[] */\n    public $foobars;\n\n}\n\n$json = '{\"foobar\":{\"foo\":\"hello world\",\"bar\":64100},\"foobars\":[{\"foo\":\"hello\",\"bar\":641},{\"foo\":\"world\",\"bar\":664411}]}';\n$demo = (new DemoClass())-\u003efromJson($json);\n\nvar_export($demo);\n\n```\n\noutputs:\n```\nDemoClass::__set_state(array(\n   'foobar' =\u003e \n      FooBarClass::__set_state(array(\n         'foo' =\u003e 'hello world',\n         'bar' =\u003e 64100,\n      )),\n   'foobars' =\u003e \n      array (\n        0 =\u003e \n        FooBarClass::__set_state(array(\n           'foo' =\u003e 'hello',\n           'bar' =\u003e 641,\n        )),\n        1 =\u003e \n        FooBarClass::__set_state(array(\n           'foo' =\u003e 'world',\n           'bar' =\u003e 664411,\n        )),\n      ),\n))\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixihz%2Fphp-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixihz%2Fphp-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixihz%2Fphp-object/lists"}