{"id":17831486,"url":"https://github.com/nark3d/phalueobjects","last_synced_at":"2025-03-19T08:30:48.283Z","repository":{"id":62493500,"uuid":"42370689","full_name":"nark3d/PhalueObjects","owner":"nark3d","description":"PHP Value Objects","archived":false,"fork":false,"pushed_at":"2017-04-19T07:02:57.000Z","size":1115,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T19:06:00.656Z","etag":null,"topics":["domain-driven-design","php","php-value-objects","usable","value-object","valueobject"],"latest_commit_sha":null,"homepage":"http://bestservedcold.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nark3d.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":"2015-09-12T19:47:12.000Z","updated_at":"2024-12-19T15:28:26.000Z","dependencies_parsed_at":"2022-11-02T09:45:39.302Z","dependency_job_id":null,"html_url":"https://github.com/nark3d/PhalueObjects","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nark3d%2FPhalueObjects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nark3d%2FPhalueObjects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nark3d%2FPhalueObjects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nark3d%2FPhalueObjects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nark3d","download_url":"https://codeload.github.com/nark3d/PhalueObjects/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243996790,"owners_count":20380978,"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":["domain-driven-design","php","php-value-objects","usable","value-object","valueobject"],"created_at":"2024-10-27T19:46:42.586Z","updated_at":"2025-03-19T08:30:47.615Z","avatar_url":"https://github.com/nark3d.png","language":"PHP","readme":"# PhalueObjects\n\n[![Build Status](https://travis-ci.org/nark3d/PhalueObjects.svg)](https://travis-ci.org/nark3d/PhalueObjects)\n[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/nark3d/phalueobjects/badges/quality-score.png?s=979567c2d791ffbeab12777c60c8edb86776ddcc)](https://scrutinizer-ci.com/g/nark3d/phalueobjects/)\n[![Code Coverage](https://scrutinizer-ci.com/g/nark3d/phalueobjects/badges/coverage.png?s=59dd4a142412a9dcd989870610f1c9f89c19cf48)](https://scrutinizer-ci.com/g/nark3d/phalueobjects/)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/5820fcfd-8593-4b76-99a6-397b94cd659c/mini.png)](https://insight.sensiolabs.com/projects/5820fcfd-8593-4b76-99a6-397b94cd659c)\n\nA generic set of PHP Value Objects for use in any project.\n\n[Wikipedia](https://en.wikipedia.org/wiki/Domain-driven_design)\n\u003e When people exchange business cards, they generally do not distinguish between each unique card; they only are concerned about the information printed on the card. In this context, business cards are value objects.\n\n## Table of contents\n* [Installation](#installation)\n* [Philosophy](#philosophy)\n* Documents\n    * [Format](src/Format/README.md)\n\n## Installation\n```shell\ncomposer require best-served-cold/phalue-objects\n```\n\n## Philosophy\nTo make this code consistent, we've stuck to a certain set of restrictions:\n\n### Rules\n* [**Must** be immutable](#must-be-immutable)\n* [**Must** contain one value](#must-contain-one-value)\n* [**Can** instantiate new object from value](#can-instantiate-new-object-from-value)\n* [**Can** be created from multiple arguments](#can-be-created-from-multiple-arguments)\n* [**Can** be equal regardless of object](#can-be-equal-regardless-of-object)\n* [**Must** have a zero lifespan](#must-have-a-zero-lifespan)\n\n\n*Disclaimer: This is my interpretation of \"The rules\".*\n\n#### Must be immutable\nThe value object's value must be set at the time of construction.\nAt no point should the value be mutated within the object.\n\n#### Must contain one value\nThe value object can only be constructed from one value, this can be \nany of the following types:\n* boolean \n* integer\n* float/double\n* string\n* array\n* object\n* resource\n* null \n\n#### Can instantiate new object from value\nRather than mutating, a new object can be instantiated from an existing one.\n\nExample:\n\n```php\n//...\npublic function double() \n{\n    return new static($this-\u003egetValue() * 2);\n}\n...//\n```\n\n#### Can be created from multiple arguments\nInstead of an object having multiple object properties, it should be created from\nmultiple arguments.\n\nExample:\n\n```php\n//...\npublic static function fromVars($one = 1, $two = 2, $three = 3)\n{\n    return new static([$one, $two, $three]); \n}\n...//\n```\n\n#### Can be equal regardless of object\nThe type of a value object is irrelevant to equality:\n\nExample:\n\n```php\n//...\n$bob = $stringValueObject-\u003eequals($csvValueObject);\n...//\n```\n\n```$bob``` is true where the type and value are equal.\n\n#### Must have a zero lifespan\nValue objects must not persist data between run times.  For example: \nno database or session information should be collected from within the\nobject.\n\n## Conventions\nFollow [PSR-FIG](http://www.php-fig.org/) rules.\n\n### Constructor\nExample:\n\n```php\nnew SomeClass('value');\n```\n\n* **Must** only have one argument of any type\n\n### Creation methods (From)\nExample:\n\n```php\nSomeClass::fromSomeObject($someObject);\n```\n\n* **Always** start with \"from\"\n* **Must** be static\n* **Can** contain multiple arguments\n* **Must** return new static instance\n\n### Conversion methods (To)\nExample:\n\n```php\n$someObject-\u003etoArray();\n```\n\n* **Always** start with \"to\"\n* **Must not** be static\n* **Must** have zero arguments\n* **Must** return new static instance\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnark3d%2Fphalueobjects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnark3d%2Fphalueobjects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnark3d%2Fphalueobjects/lists"}