{"id":19112549,"url":"https://github.com/xbyter/php-object-mapping","last_synced_at":"2025-02-22T11:33:06.357Z","repository":{"id":179112794,"uuid":"662965402","full_name":"xbyter/php-object-mapping","owner":"xbyter","description":"PHP对象映射，可以将array/object映射为类对象。可做参数的传递、Request参数映射、Entity、Bean等。并可根据定义的映射对象生成API文档。","archived":false,"fork":false,"pushed_at":"2023-07-07T10:27:20.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-03T04:49:22.604Z","etag":null,"topics":["bean","entity","json-mapper","json-mapping","mapping","object-fill","object-mapper","object-mapping","request-mapping"],"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/xbyter.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":"2023-07-06T09:09:13.000Z","updated_at":"2023-10-10T05:50:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"72f1132a-d9b9-441b-a8b6-d4e1f7d5d3d4","html_url":"https://github.com/xbyter/php-object-mapping","commit_stats":null,"previous_names":["xbyter/php-object-mapping"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fphp-object-mapping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fphp-object-mapping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fphp-object-mapping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fphp-object-mapping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xbyter","download_url":"https://codeload.github.com/xbyter/php-object-mapping/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240170073,"owners_count":19759141,"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":["bean","entity","json-mapper","json-mapping","mapping","object-fill","object-mapper","object-mapping","request-mapping"],"created_at":"2024-11-09T04:33:27.458Z","updated_at":"2025-02-22T11:33:06.316Z","avatar_url":"https://github.com/xbyter.png","language":"PHP","readme":"# php-object-mapping\n\n# 说明\nPHP对象映射，可以将array/object映射为类对象。可做参数的传递、Request参数映射、Entity、Bean等。并可根据定义的映射对象生成API文档。\n\n# 示例\n```php\nclass TestMapping extends BaseMapping\n{\n    /** @var int 总数 */\n    public int $total;\n\n    public ?TestItem $item = null;\n\n    /** @var \\Xbyter\\PhpObjectMappingTests\\Data\\TestItem[] 列表对象 */\n    public array $list = [];\n\n    /** @var string 受保护的值，不会被设置 */\n    protected string $protected_key = 'protected value';\n}\n\nclass TestItem extends BaseMapping\n{\n    /** @var string|null 标题 */\n    public ?string $title = null;\n\n    /**\n     * @var string|null 会返回装饰过的值\n     * @return TitleDecorator\n     */\n    public ?string $decorate_title = null;\n}\n\n//装饰类\nclass TitleDecorator implements DecoratorInterface\n{\n\n    public function decorate($value)\n    {\n        return sprintf(\"this is a decorated value: %s\", $value);\n    }\n}\n\n//映射对象，多维数组可用 TestMapping::fromList([[...], [...]]);\n$testMapping = TestMapping::fromItem([\n    'total' =\u003e 10,\n    'item'  =\u003e [\n        'title' =\u003e 'a'\n    ],\n    'list'  =\u003e [\n        [\n            'title' =\u003e 'b',\n            'decorate_title' =\u003e 'c',\n        ]\n    ],\n    'protected_key' =\u003e '受保护的字段不会被赋值',\n]);\n\n//转为数组\n$array = $testMapping-\u003etoArray();\n\nvar_dump($testMapping-\u003etotal); //10\nvar_dump($testMapping-\u003eitem-\u003etitle); //a\nvar_dump($testMapping-\u003elist[0]-\u003etitle); //b\nvar_dump($testMapping-\u003elist[0]-\u003edecorate_title); //this is a decorated value: c\nvar_dump($testMapping-\u003eprotected_key); //Error : Cannot access protected property $protected_key\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxbyter%2Fphp-object-mapping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxbyter%2Fphp-object-mapping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxbyter%2Fphp-object-mapping/lists"}