{"id":29196585,"url":"https://github.com/flancer32/php_data_object","last_synced_at":"2025-07-02T06:07:42.751Z","repository":{"id":62505326,"uuid":"51744755","full_name":"flancer32/php_data_object","owner":"flancer32","description":"Data object implementation for PHP","archived":false,"fork":false,"pushed_at":"2020-05-15T14:47:20.000Z","size":73,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-27T00:34:09.006Z","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/flancer32.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}},"created_at":"2016-02-15T09:31:30.000Z","updated_at":"2016-12-22T12:02:46.000Z","dependencies_parsed_at":"2022-11-02T12:16:26.742Z","dependency_job_id":null,"html_url":"https://github.com/flancer32/php_data_object","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/flancer32/php_data_object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flancer32%2Fphp_data_object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flancer32%2Fphp_data_object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flancer32%2Fphp_data_object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flancer32%2Fphp_data_object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flancer32","download_url":"https://codeload.github.com/flancer32/php_data_object/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flancer32%2Fphp_data_object/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263083719,"owners_count":23411165,"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":"2025-07-02T06:07:37.151Z","updated_at":"2025-07-02T06:07:42.743Z","avatar_url":"https://github.com/flancer32.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php_data_object\n\n[![Build Status](https://travis-ci.org/flancer32/php_data_object.svg)](https://travis-ci.org/flancer32/php_data_object)\n[![codecov.io](https://codecov.io/github/flancer32/php_data_object/coverage.svg?branch=master)](https://codecov.io/github/flancer32/php_data_object?branch=master)\n\n_\"Smart data structures and dumb code works a lot better than the other way around.\"_ (c) Eric S. Raymond\n\n_\"Bad programmers worry about the code. Good programmers worry about data structures and their relationships.\"_ (c) Linus Torvalds\n\n\n\n## Overview\nThis is yet another PHP implementation of the data container (like [DTO](https://en.wikipedia.org/wiki/Data_transfer_object) / [SDO](http://php.net/manual/en/book.sdo.php)). Some kind of the wrapper around associative array. The main goal of this implementation is to be an accessor for the raw data.\n\n\n\n## Native PHP objects\n\n\n### Structure\nWe can use any property of any PHP object:\n\n    $obj1 = new class {};\n    $obj2 = new class {};\n    $obj1-\u003ename = 'first';\n    $obj2-\u003ecode = 'OBJ2';\n    $obj1-\u003esub = $obj2;\n    $this-\u003eassertEquals('first', $obj1-\u003ename);\n    $this-\u003eassertEquals('OBJ2', $obj1-\u003esub-\u003ecode);\n\n[More...](./docs/010_PhpObjects.md)\n\n\n### Paths\nWe can set/get value of the inner property in PHP style:\n\n    $obj-\u003esub-\u003ecode = $code;\n    $code = $obj-\u003esub-\u003ecode;\n    \nbut we will have \"_Undefined property_\" error if `$obj-\u003esub` property does not exist. \n\n\n### Type checking\nWe need to use accessors to control properties types.\n\nThis is `Customer` class with `string` property:\n\n    /**\n     * @property string $name Customer name.\n     */\n    class Customer\n    {\n        public function getName() : string\n        {\n            return $this-\u003ename;\n        }\n    \n        public function setName(string $data)\n        {\n            $this-\u003ename = $data;\n        }\n    }\n\nThis is `Order` class with `Customer` property: \n\n    /**\n     * @property Customer $customer\n     */\n    class Order\n    {\n        public function getCustomer() : Customer\n        {\n            return $this-\u003ecustomer;\n        }\n    \n        public function setCustomer(Customer $data)\n        {\n            $this-\u003ecustomer = $data;\n        }\n    }\n    \nThis is code without errors (all types are expected): \n    \n    $customer = new Customer();\n    $customer-\u003esetName('John Dow');\n    $order = new Order();\n    $order-\u003esetCustomer($customer);\n    $this-\u003eassertTrue(is_string($order-\u003egetCustomer()-\u003egetName()));\n    \nThis code will throw a `\\TypeError` exception:\n    \n    $customer = new class {};\n    $customer-\u003ename = 'John Dow';\n    $order = new Order();\n    $order-\u003esetCustomer($customer);\n    \n\n[More...](./docs/020_TypeChecking.md)\n\n\n## Data Objects\n\n\n### Structure\n\n\n### Paths\nWith paths we will have property value if chain of properties exists or `null` otherwise:\n\n    $code = $obj-\u003eget('sub/code');\n    $code = $obj-\u003eget('/sub/code');    // equals to 'sub/code'\n    $code = $obj-\u003eget('/subs/0/code'); // 'subs' is array\n    $code = $obj-\u003eget('/sub/code/does/not/exist'); // 'null' is returned, no error is occured\n\nAlso we can set data property by path:\n\n    $obj-\u003eset('order/customer/name', 'John Dow');\n    \n\n### Type hinting\n    \n    \n\n## Installation\nAdd to `composer.json`:\n\n    \"require\": {\n        \"flancer32/php_data_object\": \"0.1.0\"\n    }\n\n\n\n## Development\n\n    $ composer install\n    $ ./vendor/bin/phpunit -c ./test/unit/phpunit.dist.xml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflancer32%2Fphp_data_object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflancer32%2Fphp_data_object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflancer32%2Fphp_data_object/lists"}