{"id":20678881,"url":"https://github.com/phpgt/dataobject","last_synced_at":"2025-04-13T18:35:11.071Z","repository":{"id":57040441,"uuid":"330221980","full_name":"phpgt/DataObject","owner":"phpgt","description":"Structured, type-safe, immutable data transfer.","archived":false,"fork":false,"pushed_at":"2025-02-14T16:47:07.000Z","size":112,"stargazers_count":0,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T06:00:02.877Z","etag":null,"topics":["data-transfer-object","dto","dto-pattern","immutable","immutable-datastructures","type-safety"],"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/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"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},"funding":{"github":["phpgt"]}},"created_at":"2021-01-16T17:50:26.000Z","updated_at":"2025-02-14T16:43:19.000Z","dependencies_parsed_at":"2024-11-16T21:25:36.026Z","dependency_job_id":"a517a10d-a7bd-464b-8697-c3108d2745a8","html_url":"https://github.com/phpgt/DataObject","commit_stats":{"total_commits":40,"total_committers":1,"mean_commits":40.0,"dds":0.0,"last_synced_commit":"dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDataObject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDataObject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDataObject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDataObject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/DataObject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248761276,"owners_count":21157524,"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":["data-transfer-object","dto","dto-pattern","immutable","immutable-datastructures","type-safety"],"created_at":"2024-11-16T21:22:53.834Z","updated_at":"2025-04-13T18:35:11.044Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","readme":"Structured, type-safe, immutable data transfer.\n===============================================\n\nA Data Transfer Objects (DTO) in a programming language is a design pattern that facilitates transfer of data between different layers of an application. This library introduces the `DataObject` class which can be built from an existing associative array or standard object, using the `DataObjectBuilder` class.\n\n***\n\n\u003ca href=\"https://giub.com/PhpGt/DataObject/actions\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dataobject-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codacy.com/gh/PhpGt/DataObject\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dataobject-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/PhpGt/DataObject\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dataobject-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/DataObject\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dataobject-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"http://www.php.gt/dataobject\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dataobject-docs.svg\" alt=\"PHP.Gt/DataObject documentation\" /\u003e\n\u003c/a\u003e\n\nA `DataObject` has the following features: \n\n+ It is **immutable**, meaning that code can't modify the data it represents\n+ It provides **type-safe** getters to the contained data\n+ It can be **nested** within other `DataObject`s\n+ It can be converted to and from associative arrays and standard objects\n\nUsage example\n-------------\n\nLoad an object into a `DataObject`, then pass to a third party library for processing.\n\nDue to the immutability of the `DataObject` class, there is no risk of the third party library making changes to the contents of the data.\n\n```php\nuse Gt\\DataObject\\DataObjectBuilder;\n\n// Create a new Builder and build the DataObject from an associative array.\n// For example, data loaded from another remote data source.\n$sourceData = [\n\t\"id\" =\u003e 105,\n\t\"name\" =\u003e \"Edgar Scolmore\",\n\t\"address\" =\u003e [\n\t\t\"street\" =\u003e \"32 Trestles Lane\",\n\t\t\"town\" =\u003e \"Lensworth\",\n\t\t\"county\" =\u003e \"Scamperingshire\",\n\t\t\"postcode\" =\u003e \"SC41 8PN\"\n\t],\n];\n$builder = new DataObjectBuilder();\n$data = $builder-\u003efromAssociativeArray($sourceData);\n\n// Pass the data to a third party to process it.\nThirdParty::processData($data);\n\n// Now we can use the data ourselves for whatever purpose:\nDatabase::store(\n\tid: $data-\u003egetInt(\"id\"),\n\trefname: $data-\u003egetString(\"name\"),\n);\n```\n\nWorking with JSON data\n----------------------\n\nA JSON data structure is almost identical in scope to the DataObject introduced in this repository, with one key difference: JSON data can represent a primitive data type, not always key-value-pairs. Because of this, [PHP.Gt/Json is maintained separately to provide structured, type-safe, immutable JSON objects][json] as an extension to this DataObject repository.\n\n[json]: https://php.gt/json\n","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fdataobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Fdataobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fdataobject/lists"}