{"id":19771110,"url":"https://github.com/rakshazi/getsettrait","last_synced_at":"2025-04-30T17:32:40.053Z","repository":{"id":62532954,"uuid":"59854032","full_name":"rakshazi/getSetTrait","owner":"rakshazi","description":"Magic getter/setter trait for any PHP class in one string of code.","archived":false,"fork":false,"pushed_at":"2019-09-24T08:58:12.000Z","size":18,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-16T06:30:39.712Z","etag":null,"topics":["composer","getters","php","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rakshazi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-27T18:07:53.000Z","updated_at":"2020-12-18T09:12:17.000Z","dependencies_parsed_at":"2022-11-02T15:15:39.806Z","dependency_job_id":null,"html_url":"https://github.com/rakshazi/getSetTrait","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakshazi%2FgetSetTrait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakshazi%2FgetSetTrait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakshazi%2FgetSetTrait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakshazi%2FgetSetTrait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rakshazi","download_url":"https://codeload.github.com/rakshazi/getSetTrait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251751305,"owners_count":21637900,"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":["composer","getters","php","setter","trait"],"created_at":"2024-11-12T05:01:08.832Z","updated_at":"2025-04-30T17:32:39.780Z","avatar_url":"https://github.com/rakshazi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GetSetTrait\nA dynamic setter-getter library for PHP 5.4+.\n\nYou can use methods like `setFoo('bar')` and `getFoo()`, which you DON'T have to create (in your class).\nGetSetTrait will make these methods work for you automatically as long as you have a `$foo` property in your class.\n\nIt makes use of Traits, so `using` it is super simple, you don't have to extend any class, as you can extend a single class only, we don't force you to use ours.\nYou can restrict to only getter only or you can specify a Type for property using **annotations**.\n\n## Installation\n\nGetSetTrait uses [Composer](http://getcomposer.org/) to make hassles Go.\n\nLearn to use composer and add this to require (in your composer.json):\n\n\u003e \"rakshazi/get-set-trait\": \"@stable\"\n\nLibrary on [Packagist](https://packagist.org/packages/rakshazi/get-set-trait).\n\n## Usage\n\nJust add this in your classes:\n\n\u003e use Rakshazi\\GetSetTrait;\n\n```php\nclass Dummy\n{\n    //Add ability to use dynamic getters and setters\n    use \\Rakshazi\\GetSetTrait;\n}\n\n//Init dummy class\n$dummy = new Dummy;\n//Set new var 'message_for_world' with value\n$dummy-\u003esetMessageForWorld('Hello');\n//Will return \"Hello\\n\"\necho $dummy-\u003egetMessageForWorld().\"\\n\";\n//Will return the same text\necho $dummy-\u003egetData('message_for_world').\"\\n\";\n//Set new message for our world!\n$dummy-\u003esetData('message_for_world', 'Bye-bye!');\n//Will return \"Bye-bye!\\n\"\necho $dummy-\u003egetData('message_for_world').\"\\n\";\n//Will set new var 'new_message'\n$dummy-\u003esetNewMessage('Use me now!');\n//Will return true, value exists\n$dummy-\u003ehasNewMessage();\n//Will return false\n$dummy-\u003ehasSomeOtherValue();\n//Will show all object data\nvar_dump($dummy);\n```\n\n**That's basically it.**\n\n## Advanced usage\n\n### Data property\n\nIf you want save all data in `$object-\u003esomeProperty` array instead of saving each property as object's property (`$object-\u003eproperty_name`),\nyou can use `setDataProperty('data')` function, example:\n\n```php\n\u003c?php\nclass Dummy\n{\n    //Add ability to use dynamic getters and setters\n    use \\Rakshazi\\GetSetTrait;\n\n    public function __construct()\n    {\n        $this-\u003esetDataProperty('data');\n    }\n}\n\n//Init dummy class\n$dummy = new Dummy;\n//Set new var 'message_for_world' with value\n$dummy-\u003esetMessageForWorld('Hello');\n//Will return \"Hello\\n\"\necho $dummy-\u003egetMessageForWorld().\"\\n\";\n//Will return the same text\necho $dummy-\u003egetData('message_for_world').\"\\n\";\n//Set new message for our world!\n$dummy-\u003esetData('message_for_world', 'Bye-bye!');\n//Will return \"Bye-bye!\\n\"\necho $dummy-\u003egetData('message_for_world').\"\\n\";\n//Will set new var 'new_message'\n$dummy-\u003esetNewMessage('Use me now!');\n//Will return all properties in an array\n$dummy-\u003egetAllData();\n//Will show all object data\nvar_dump($dummy);\n```\n\n**Result** (all data saved in `data` property)\n\n```\nobject(Dummy)#1 (2) {\n  [\"_data_property\":\"Dummy\":private]=\u003e\n  string(4) \"data\"\n  [\"data\"]=\u003e\n  array(2) {\n    [\"message_for_world\"]=\u003e\n    string(8) \"Bye-bye!\"\n    [\"new_message\"]=\u003e\n    string(11) \"Use me now!\"\n  }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakshazi%2Fgetsettrait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frakshazi%2Fgetsettrait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakshazi%2Fgetsettrait/lists"}