{"id":33990532,"url":"https://github.com/glamorous/value-object","last_synced_at":"2025-12-13T06:17:02.177Z","repository":{"id":62511234,"uuid":"138518726","full_name":"glamorous/value-object","owner":"glamorous","description":"PHP Interface to create value objects to use in your project. Abstract Enum class available that uses the same interface.","archived":false,"fork":false,"pushed_at":"2021-07-12T08:11:53.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-19T02:08:47.700Z","etag":null,"topics":["enum","php","valueobject"],"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/glamorous.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-24T22:07:22.000Z","updated_at":"2021-07-12T08:11:58.000Z","dependencies_parsed_at":"2022-11-02T12:46:40.343Z","dependency_job_id":null,"html_url":"https://github.com/glamorous/value-object","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/glamorous/value-object","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glamorous%2Fvalue-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glamorous%2Fvalue-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glamorous%2Fvalue-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glamorous%2Fvalue-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glamorous","download_url":"https://codeload.github.com/glamorous/value-object/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glamorous%2Fvalue-object/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27701513,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["enum","php","valueobject"],"created_at":"2025-12-13T06:17:01.498Z","updated_at":"2025-12-13T06:17:02.171Z","avatar_url":"https://github.com/glamorous.png","language":"PHP","readme":"# Value Object\n\n[![Latest Stable Version](https://poser.pugx.org/glamorous/value-object/v/stable)](https://packagist.org/packages/glamorous/value-object)\n[![License](https://img.shields.io/github/license/glamorous/value-object.svg)](https://github.com/glamorous/value-object)\n[![PHP Version](https://img.shields.io/packagist/php-v/glamorous/value-object.svg)]()\n[![Build Status](https://img.shields.io/travis/glamorous/value-object.svg)](https://travis-ci.com/glamorous/value-object)\n[![Codecov](https://img.shields.io/codecov/c/github/glamorous/value-object.svg)](https://codecov.io/gh/glamorous/value-object)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/glamorous/value-object/badges/quality-score.png)](https://scrutinizer-ci.com/g/glamorous/value-object/)\n[![Total Downloads](https://img.shields.io/packagist/dt/glamorous/value-object.svg)](https://packagist.org/packages/glamorous/value-object)\n[![GitHub issues](https://img.shields.io/github/issues/glamorous/value-object.svg)](https://github.com/glamorous/value-object/issues)\n\nPHP Interface to create value objects to use in your project. Abstract Enum class available that uses the same interface.\n\n## Why?\n\nValueObjects are the ideal way to use in your project. You can force yourself in your project to have data in the way you want.\n\n## Documentation\n\n### The interface\n\nThe interface has three methods you need to implement.\n\n- **__toString()**: This magic method is needed to represent the ValueObject as a string. Is usefull for logging.\n- **toNative()**: This method must return an array, integer, string... This is needed to test if two value objects are the same or not and for serializing.\n- **equalsTo(ValueObject $object)**: The method requires another ValueObject instance. The `toNative()`-method can be used to check if two value objects are the same. In the Enum it uses the `equals` method from the parent.\n\n### The Enum\n\nThe included Enum extends the Enum from [MyCLabs](https://github.com/myclabs/php-enum).\nAdditionally it implements the interface.\nThis way it's possible to use the functions `toNative()` and `equalsTo()` in your application.\nMore importantly an enumaration is also a value object, something that can't be changed when created.\nWhen all those classes implements the same interface, its easier for the developer to use them through eachother.\n\n## Installation\n\nYou can install the package via composer:\n``` bash\n$ composer require glamorous/value-object\n```\n\n## Usage\n\n**Amount (Interface example)**\n\nMost of the people will say: \"this is an integer, why do we need a value object?\". Then you should read some articles about value objects again.\n\n```\n\nuse Glamorous\\ValueObject;\n\nfinal class Amount implements ValueObject\n{\n    private $amount;\n\n    public __construct(int $amount)\n    {\n        if ($amount \u003c 0) {\n            throw new \\InvalidArgumentException('Amount must be above zero or zero');\n        }\n\n        $this-\u003eamount = $amount;\n    }\n}\n```\n\n**Status (Enum example)**\n\n```\nuse Glamorous\\Enum;\n\nfinal class Status extends Enum\n{\n    const OPEN = 'open';\n    const CLOSED = 'closed';\n}\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details. To see a list of the contributors: [all contributors](../../contributors).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglamorous%2Fvalue-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglamorous%2Fvalue-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglamorous%2Fvalue-object/lists"}