{"id":15942020,"url":"https://github.com/mikebarlow/getset","last_synced_at":"2025-03-28T00:32:59.141Z","repository":{"id":57054483,"uuid":"93796866","full_name":"mikebarlow/GetSet","owner":"mikebarlow","description":"Trait for adding magic setters / getters to objects","archived":true,"fork":false,"pushed_at":"2018-01-24T11:01:35.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T16:53:13.631Z","etag":null,"topics":["getter","magic-methods","setter","trait"],"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/mikebarlow.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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-08T22:29:04.000Z","updated_at":"2024-11-23T00:08:34.000Z","dependencies_parsed_at":"2022-08-24T05:21:24.211Z","dependency_job_id":null,"html_url":"https://github.com/mikebarlow/GetSet","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/mikebarlow%2FGetSet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebarlow%2FGetSet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebarlow%2FGetSet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebarlow%2FGetSet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikebarlow","download_url":"https://codeload.github.com/mikebarlow/GetSet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245949235,"owners_count":20698911,"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":["getter","magic-methods","setter","trait"],"created_at":"2024-10-07T07:21:55.621Z","updated_at":"2025-03-28T00:32:58.876Z","avatar_url":"https://github.com/mikebarlow.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GetSet\n\n[![Author](http://img.shields.io/badge/author-@mikebarlow-red.svg?style=flat-square)](https://twitter.com/mikebarlow)\n[![Latest Version](https://img.shields.io/github/release/mikebarlow/getset.svg?style=flat-square)](https://github.com/mikebarlow/GetSet/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/mikebarlow/GetSet/blob/master/LICENSE)\n[![Build Status](https://img.shields.io/travis/mikebarlow/GetSet/master.svg?style=flat-square)](https://travis-ci.org/mikebarlow/GetSet)\n\n## Introduction\n\nGetSet is a PSR-2 compliant trait to be used for adding magic getters / setters to objects.\n\n## Requirements\n\n### Composer\n\nGetSet requires the following:\n\n* \"php\": \"\u003e=5.6.0\"\n\nAnd the following if you wish to run in dev mode and run tests.\n\n* \"phpunit/phpunit\": \"~5.7\"\n* \"squizlabs/php_codesniffer\": \"~2.0\"\n\n## Installation\n\n### Composer\n\nSimplest installation is via composer.\n\n    composer require snscripts/getset 1.*\n\nor adding to your projects `composer.json` file.\n\n    {\n        \"require\": {\n            \"snscripts/getset\": \"1.*\"\n        }\n    }\n\n### Setup\n\nTo initiate GetSet simply `use` the trait within your class\n\n    class MyClass\n    {\n        use \\Snscripts\\GetSet\\GetSet;\n\n        ...\n    }\n\n## Usage\n\nOnce setup, simply set or get any variables on the object you need.\n\n    $MyClass-\u003efoo_bar = 'barfoo';\n\n    echo $MyClass-\u003efoo_bar; // barfoo\n\nThis will set the variable into a `$data` array added to your object via the GetSet trait.\n\n### Variable Transformers\n\nYou can create custom get / set transformers to change a variables data as it gets added to or retrieved from the `$data` variable. These should be in the format `setXAttr` and `getXAttr` where `X` is a CamelCased version of the variable you are setting or getting from the object.\n\nIn the example above, basic getter / setter methods for `foo_bar` could look like:\n\n    public function setFooBarAttr($value)\n    {\n        $this-\u003edata['foo_bar'] = strtoupper($value);\n    }\n\n    public function getFooBarAttr()\n    {\n        return strtolower($this-\u003edata['foo_bar']);\n    }\n\n## Mass data assignment\n\nIf you need to assign a full array of data to your object and wish for the variables to be passed through any custom setters there is the `setAllData` method.\n\n    $MyClass-\u003esetAllData([\n        'foo_bar' =\u003e 'barfoo'\n    ]);\n\n## Data Export\n\nIf you need to export all the data set within your object you can use 1 of 2 methods.\n\n### toArray\n\n    $MyClass-\u003etoArray();\n\nThis will simply return all data set onto the object as an array.\n\n### toJson\n\n    $MyClass-\u003etoJson();\n\nThis will return all the data set onto the object as a Json object. This first uses the toArray method to retrieve an array before returning the data through `json_encode`.\n\n\n## Changelog\n\nYou can view the changelog [HERE](https://github.com/mikebarlow/GetSet/blob/master/CHANGELOG.md)\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/mikebarlow/GetSet/blob/master/CONTRIBUTING.md) for details.\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/mikebarlow/GetSet/blob/master/LICENSE) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikebarlow%2Fgetset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikebarlow%2Fgetset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikebarlow%2Fgetset/lists"}