{"id":18576097,"url":"https://github.com/thiagodp/traits","last_synced_at":"2025-09-10T22:32:51.940Z","repository":{"id":57040952,"uuid":"65769124","full_name":"thiagodp/traits","owner":"thiagodp","description":"🔮 Be more productive with PHP","archived":false,"fork":false,"pushed_at":"2019-10-15T18:30:11.000Z","size":12,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-29T20:22:38.478Z","etag":null,"topics":["array","builder","generator","getter","php","phputil","setter","trait"],"latest_commit_sha":null,"homepage":"","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/thiagodp.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":"2016-08-15T22:26:51.000Z","updated_at":"2023-03-16T13:50:42.000Z","dependencies_parsed_at":"2022-08-23T23:30:50.144Z","dependency_job_id":null,"html_url":"https://github.com/thiagodp/traits","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/thiagodp/traits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Ftraits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Ftraits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Ftraits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Ftraits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiagodp","download_url":"https://codeload.github.com/thiagodp/traits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Ftraits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274536170,"owners_count":25303780,"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-09-10T02:00:12.551Z","response_time":83,"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":["array","builder","generator","getter","php","phputil","setter","trait"],"created_at":"2024-11-06T23:23:33.857Z","updated_at":"2025-09-10T22:32:51.899Z","avatar_url":"https://github.com/thiagodp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phputil\\traits\nUseful traits for PHP.\n\n[![Build Status](https://travis-ci.org/thiagodp/traits.svg?branch=master)](https://travis-ci.org/thiagodp/traits)\n\nWe use [semantic version](http://semver.org/). See [our releases](https://github.com/thiagodp/traits/releases).\n\n## Installation\n\n```command\ncomposer require phputil/traits\n```\n\n## Traits\n\n* [GetterBuilder](https://github.com/thiagodp/traits/blob/master/lib/GetterBuilder.php)\n* [WithBuilder](https://github.com/thiagodp/traits/blob/master/lib/WithBuilder.php)\n* [GetterSetterWithBuilder](https://github.com/thiagodp/traits/blob/master/lib/GetterSetterWithBuilder.php)\n* [FromArray](https://github.com/thiagodp/traits/blob/master/lib/FromArray.php)\n* [ToArray](https://github.com/thiagodp/traits/blob/master/lib/ToArray.php)\n\n## Examples\n\nExample on `GetterBuilder`:\n\n```php\nuse phputil\\traits\\GetterBuilder;\n\nclass MyClass {\n\n\tuse GetterBuilder; // simulate getters\n\t\n\tprivate $name = '';\n\tprivate $description = '';\n\t\n\tfunction __construct( $name, $description ) {\n\t\t$this-\u003ename = $name;\n\t\t$this-\u003edescription = $description;\n\t}\n}\n \n$obj = new MyClass( 'Bob', 'I am Bob' );\necho $obj-\u003egetName(); // Bob\necho $obj-\u003egetDescription(); // I am Bob\n```\n\nExample on `WithBuilder`:\n\n```php\nuse phputil\\traits\\WithBuilder;\n\nclass MyClass {\n\n\tuse WithBuilder;\n\t\n\tpublic $name = '';\n\tpublic $description = '';\n}\n\n$obj = ( new MyClass() )-\u003ewithName( 'Bob' )-\u003ewithDescription( 'I am Bob' );\necho $obj-\u003ename; // Bob\necho $obj-\u003edescription; // I am Bob\n```\n\nExample on `GetterSetterWithBuilder`:\n\n```php\nuse phputil\\traits\\GetterSetterWithBuilder;\n\nclass MyClass {\n\n\tuse GetterSetterWithBuilder;\n\t\n\tprivate $name = '';\n\tprivate $description = '';\n}\n  \n$obj = ( new MyClass() )-\u003ewithName( 'Bob' )-\u003esetDescription( 'I am Bob' );\necho $obj-\u003egetName(); // Bob\necho $obj-\u003egetDescription(); // I am Bob\n$obj-\u003esetName( 'Bob Dylan' );\necho $obj-\u003egetName(); // Bob Dylan\n```\n\nExample on `FromArray`:\n\n```php\nuse phputil\\traits\\FromArray;\n\nclass MyClass {\n\n\tuse FromArray;\n\t\n\tprivate $id;\n\tprotected $name;\n\tpublic $age;\n}\n  \n$obj = new MyClass();\n$obj-\u003efromArray( array( 'id' =\u003e 10, 'name' =\u003e 'Bob', 'age' =\u003e 18 ) );\nvar_dump( $obj ); // the attributes will have the array values\n```\n\nExample on converting from a dynamic object:\n\n```php\n// From a converting from a dynamic object, just use a type casting\n$p = new \\stdClass;\n$p-\u003eid = 10;\n$p-\u003ename = 'Bob';\n$p-\u003eage = 18;\n\n$obj = new MyClass();\n$obj-\u003efromArray( (array) $p ); // Just make a type casting to array ;)\n```\n\nExample on `ToArray`:\n\n```php\nuse phputil\\traits\\ToArray;\n\nclass MyClass {\n\n\tuse ToArray;\n\t\n\tprivate $id = 50;\n\tprotected $name = 'Bob';\n\tpublic $age = 21;\n}\n  \n$obj = new MyClass();\nvar_dump( $obj-\u003etoArray() ); // array( 'id' =\u003e 50, 'name' =\u003e 'Bob', 'age' =\u003e 21 )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Ftraits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagodp%2Ftraits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Ftraits/lists"}