{"id":21599653,"url":"https://github.com/eppak/value","last_synced_at":"2025-03-18T11:46:17.961Z","repository":{"id":56978485,"uuid":"115731426","full_name":"eppak/value","owner":"eppak","description":"Value Object Helper","archived":false,"fork":false,"pushed_at":"2020-01-16T13:05:25.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T18:08:05.846Z","etag":null,"topics":["object","php","value-object"],"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/eppak.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":"2017-12-29T15:05:17.000Z","updated_at":"2020-01-16T13:05:27.000Z","dependencies_parsed_at":"2022-08-21T11:50:48.772Z","dependency_job_id":null,"html_url":"https://github.com/eppak/value","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eppak%2Fvalue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eppak%2Fvalue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eppak%2Fvalue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eppak%2Fvalue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eppak","download_url":"https://codeload.github.com/eppak/value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244217601,"owners_count":20417659,"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":["object","php","value-object"],"created_at":"2024-11-24T18:16:04.928Z","updated_at":"2025-03-18T11:46:17.932Z","avatar_url":"https://github.com/eppak.png","language":"PHP","readme":"Intro\n====\nThis is a smart dto object, is useful to transport and manipulate data. Usually a value object\nhave getter and setter for a bunch of properties that represent data. \n\nInstallation\n====\n```sh\n# composer install eppak/value\n```\n\nConstructor\n====\nCan be created in various modes, it accept usually an array of fields with values;\nthe second optional parameter represent if property can be written or is readonly. \n\n  - As new.\n  - From an array.\n  - From JSON\n  \nIf the object need to be readonly you can istantiate a **roValue** object istead ov **Value**.\n\nExample of Initialization\n====\n```php\n\u003c?php\n    use eppak\\value;\n    \n    //...\n    \n    $data = [ 'testRead' =\u003e 'read',\n              'testWrite' =\u003e 'write',\n              'testReadWrite' =\u003e 'readwrite',\n              'undisciplined' =\u003e 'readwrite' ];\n    \n    $value = new Value( $data );\n    $value = new Value( $data, [ 'testRead' =\u003e static::R,\n                                 'testWrite' =\u003e static::W,\n                                 'testReadWrite' =\u003e static::RW ] );    \n\n    $value = Value::fromArray( $data );\n    $value = Value::fromJson( '{\"test\": \"read\"}' );\n```\n\nExample of reading/writing\n====\n```php\n\u003c?php\n    $testRead =  $value-\u003egetTestRead();\n    $testReadWrite =  $value-\u003egetTestReadWrite();\n    \n    $value-\u003esetTestReadWrite('some value');\n    $value-\u003esetTestRead('some value'); // Thrown an error, is read only    \n```\n\nTesting property existence\n====\nProperties existence can be probed as simple level or multi level, useful when value object is istanced from JSON.\n```php\n\u003c?php\n    $json = Json::fromJson('{ \"test\": { \"test1\" : { \"test2\": { \"test3\" : 1} } }}');\n    $testRead_present = $json-\u003ehas('test');\n    $testChin_present = $json-\u003ehasChain('test', 'test1\u003etest2\u003etest3');\n```\n\nCheat sheet\n====\n| Method        | Type           | Description  |\n| ------------- |-------------| -----|\n| fromArray    | static | *Create an object from array* |\n| fromJson    | static | *Create an object from a json string* |\n| has    | virtual | *Check if a property is present* |\n| hasChain    | virtual | *Check if a chain of properties is present* |\n| getChainValue    | virtual | *Get the value of a chain of properties* |\n| duplicate    | virtual | *Create a new object identical to the current* |\n| getX    | virtual | *Get the X property* |\n| setX    | virtual | *Set the X property* |\n\nLicense\n====\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feppak%2Fvalue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feppak%2Fvalue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feppak%2Fvalue/lists"}