{"id":20254772,"url":"https://github.com/chippyash/attributes","last_synced_at":"2026-05-12T09:37:23.899Z","repository":{"id":56952063,"uuid":"94060098","full_name":"chippyash/attributes","owner":"chippyash","description":"General purpose monadic attribute maps for objects","archived":false,"fork":false,"pushed_at":"2019-02-22T10:55:47.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T03:33:56.575Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chippyash.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-06-12T05:56:32.000Z","updated_at":"2019-02-22T10:52:04.000Z","dependencies_parsed_at":"2022-08-21T09:20:17.510Z","dependency_job_id":null,"html_url":"https://github.com/chippyash/attributes","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/chippyash%2Fattributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fattributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fattributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chippyash%2Fattributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chippyash","download_url":"https://codeload.github.com/chippyash/attributes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241705908,"owners_count":20006398,"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":"2024-11-14T10:34:48.971Z","updated_at":"2026-05-12T09:37:23.851Z","avatar_url":"https://github.com/chippyash.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chippyash/attributes\n\n## Quality Assurance\n\n![PHP 5.6](https://img.shields.io/badge/PHP-5.6-blue.svg)\n![PHP 7](https://img.shields.io/badge/PHP-7-blue.svg)\n[![Build Status](https://travis-ci.org/chippyash/attributes.svg?branch=master)](https://travis-ci.org/chippyash/attributes.svg?branch=master)\n[![Test Coverage](https://codeclimate.com/github/chippyash/attributes/badges/coverage.svg)](https://codeclimate.com/github/chippyash/attributes/badges)\n[![Code Climate](https://codeclimate.com/github/chippyash/attributes/badges/gpa.svg)](https://codeclimate.com/github/chippyash/attributes/badges)\n\nThe above badges represent the current development branch.  As a rule, I don't push\n to GitHub unless tests, coverage and usability are acceptable.  This may not be\n true for short periods of time; on holiday, need code for some other downstream\n project etc.  If you need stable code, use a tagged version. Read 'Further Documentation'\n and 'Installation'.\n\n## What?\n\nProvides a very strongly typed, but simple, general purpose Attribute Container based \non [Monadic](https://github.com/chippyash/monad) principles.\n\n## Why?\n\nHow many times have you written a class with a load of protected parameters (Attributes)\nand then had to write all the getters and setters?  This library provides a general\npurpose container for those attributes.  In addition the Attribute container and the\nAttributes are Monadic and immutable, meaning that you can guarantee their state.\n\n## How\n\nUse the Attribution trait.\n\n\u003cpre\u003e\nuse Chippyash\\Attributes\\Attribution;\n\nclass MyClass\n{\n\tuse Attribution;\n}\n\u003c/pre\u003e\n\nYour class now has 2 methods:\n\n`public function getA(StringType $name): Attribute`\n\n`public function hasA(StringType $name): bool`\n\nTo retrieve and test for an Attribute:\n\nYou can further use the AttributionSettable trait to add a setter.  NB. you \nneed to use both together, as Attributal provides the protected $attributes\nvar to the class;\n\n\u003cpre\u003e\nuse Chippyash\\Attributes\\Attribution;\nuse Chippyash\\Attributes\\AttributionSettable;\n\nclass MyClass\n{\n\tuse Attribution;\n\tuse AttributionSettable;\n}\n\u003c/pre\u003e\n\nwhich adds \n\n`public function setA(StringType $name, Attribute $attribute): Attribution`\n\n\u003cpre\u003e\n\tuse Chippyash\\Attributes\\Attribute;\n\tuse Chippyash\\Type\\String\\StringType;\n\t\n\t$myClass = new MyClass();\n\t$attr = new Attribute('bar');\n\t$attrName = new StringType('foo);\n\t$test = $myClass-\u003esetA($attrName, $attr)-\u003egetA($attrName);\n\t\n\techo ($myClass-\u003ehasA($attrName) ? 'true' : 'false');\n\techo ($myClass-\u003ehasA(new StringType('bar)) ? 'true' : 'false');\n\t\n\u003c/pre\u003e\n\nAttributes, being Monadic, have a value which can be retrieved thus:\n\n\u003cpre\u003e\n\t$attrValue = $myClass-\u003egetA($attrName)-\u003evalue();\n\t//or\n\t$attr = $myClass-\u003egetA($attrName);\n\t$attrValue = $attr();  //using the invokable interface\n\u003c/pre\u003e\n\nIf you need to, you can define your class to have an `Attributal` interface when\nusing the trait to communicate to other objects, that attributes can be tested and\nretrieved.  You can use the `AttributalSettable` interface to communicate that the\nclass allows setting of Attributes, (this of course breaks the immutable interface,\nso you might want to consider keeping a state history on the AttributeMap);\n\n\u003cpre\u003e\nuse Chippyash\\Attributes\\Attribution;\nuse Chippyash\\Attributes\\AttributionSettable;\nuse Chippyash\\Attributes\\Attributal;\nuse Chippyash\\Attributes\\AttributalSettable;\n\nclass MyClass implements Attributal, AttributalSettable\n{\n\tuse Attribution;\n\tuse AttributionSettable;\n}\n\n\u003c/pre\u003e\n\n## Further documentation\n\nMore about [Monads](https://github.com/chippyash/monad) and [here](http://zf4.biz/blog/functional-programming-monads)\n\n[Test Contract](https://github.com/chippyash/attributes/blob/master/docs/Test-Contract.md) in the docs directory.\n\nCheck out [ZF4 Packages](http://zf4.biz/packages?utm_source=github\u0026utm_medium=web\u0026utm_campaign=blinks\u0026utm_content=validation) for more packages\n\n## Changing the library\n\n1.  fork it\n2.  write the test\n3.  amend it\n4.  do a pull request\n\nFound a bug you can't figure out?\n\n1.  fork it\n2.  write the test\n3.  do a pull request\n\nNB. Make sure you rebase to HEAD before your pull request\n\nOr - raise an issue ticket.\n\n## Where?\n\nThe library is hosted at [Github](https://github.com/chippyash/attributes). It is\navailable at [Packagist.org](https://packagist.org/packages/chippyash/attributes)\n\n### Installation\n\nInstall [Composer](https://getcomposer.org/)\n\n#### For production\n\n\u003cpre\u003e\n    \"chippyash/attributes\": \"\u003e=1,\u003c2\"\n\u003c/pre\u003e\n\nOr to use the latest, possibly unstable version:\n\n\u003cpre\u003e\n    \"chippyash/attributes\": \"dev-master\"\n\u003c/pre\u003e\n\n\n#### For development\n\nClone this repo, and then run Composer in local repo root to pull in dependencies\n\n\u003cpre\u003e\n    git clone git@github.com:chippyash/attributes.git Attributes\n    cd Attributes\n    composer install\n\u003c/pre\u003e\n\nTo run the tests:\n\n\u003cpre\u003e\n    cd Attributes\n    vendor/bin/phpunit -c test/phpunit.xml test/\n\u003c/pre\u003e\n\n## License\n\nThis software library is released under the [BSD 3 Clause license](https://opensource.org/licenses/BSD-3-Clause)\n\nThis software library is Copyright (c) 2017, Ashley Kitson, UK\n\n## History\n\nV1.0.0 Initial Release\n\nV1.0.1 Update dependencies\n\nV1.1.0 Change of license from GPL V3 to BSD 3 Clause\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fattributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchippyash%2Fattributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchippyash%2Fattributes/lists"}