{"id":20732148,"url":"https://github.com/ailixter/gears-overloading","last_synced_at":"2025-06-13T07:35:28.980Z","repository":{"id":56942709,"uuid":"112513518","full_name":"ailixter/gears-overloading","owner":"ailixter","description":null,"archived":false,"fork":false,"pushed_at":"2019-08-17T13:58:12.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T00:30:46.242Z","etag":null,"topics":["component","dynamic-props","facade","overloading","proxy"],"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/ailixter.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-11-29T18:40:26.000Z","updated_at":"2019-08-16T12:26:18.000Z","dependencies_parsed_at":"2022-08-21T07:50:35.498Z","dependency_job_id":null,"html_url":"https://github.com/ailixter/gears-overloading","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-overloading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-overloading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-overloading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-overloading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ailixter","download_url":"https://codeload.github.com/ailixter/gears-overloading/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243013767,"owners_count":20221786,"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":["component","dynamic-props","facade","overloading","proxy"],"created_at":"2024-11-17T05:17:56.547Z","updated_at":"2025-03-11T10:25:53.988Z","avatar_url":"https://github.com/ailixter.png","language":"PHP","readme":"# gears-overloading\n\n## install\ncomposer require ailixter/gears-overloading\n\n## howtos\n\n### How to provide getter/setter overriding for properties\n\n```php\nuse Ailixter\\Gears\\Props;\n\nclass TestProps\n{\n    use Props;\n    \n    private $myPri = 'my private';\n    \n    public function getMyPri() {\n        return '*' . $this-\u003emyPri;\n    }\n}\n\n$test = new TestProps;\necho $test-\u003emyPri;\n$test-\u003emyPri = 'new'; // PropertyException\n```\nor, for real (defined) props:\n\n```php\nclass TestRealProps\n{\n    use Props;\n    \n    private $myPri = 'my private';\n\n    protected function propertyGet($prop)\n    {\n        return $this-\u003e{$prop};\n    }\n\n    protected function propertySet($prop, $value)\n    {\n        $this-\u003e{$prop} = $value;\n    }\n}\n\n$test = new TestRealProps;\necho $test-\u003emyPri;\n$test-\u003emyPri = 'new';\necho $test-\u003eundefined;     // Notice\n$test-\u003eundefined = 'some'; // perfectly ok\n```\n\n### How to support explicitely defined properties only\n\n```php\nuse Ailixter\\Gears\\StrictProps;\n\nclass TestStrictProps\n{\n    use StrictProps;\n\n    private $myPri = 'my private';\n}\n\n$test = new TestStrictProps;\necho $test-\u003emyPri;\n$test-\u003emyPri = 'new';\necho $test-\u003eundefined;     // PropertyException\n$test-\u003eundefined = 'some'; // PropertyException\n```\n\n### How to create getters and fluent setters for all defined props\n\n```php\nuse Ailixter\\Gears\\AutoGetSetProps;\n\nclass TestAutoGetSetProps\n{\n    use AutoGetSetProps;\n\n    private $myPri;\n}\n\n$test = TestAutoGetSetProps;\necho $test-\u003esetMyPri('new')-\u003egetMyPri();\n```\n\nit's also possible to specify defaults in getters:\n\n```php\nclass TestAutoGetPropsWithDefaults\n{\n    use Props, AutoGetSetProps;\n\n    private   $myPri;\n    protected $myPro;\n\n    public function getMyPro($default = 'static default')\n    {\n        return $this-\u003eexistingProperty('myPro', $default);\n    }\n}\n\n$test = TestAutoGetSetProps;\necho $test-\u003emyPro;                       // static default\necho $test-\u003egetMyPri('dynamic default'); // dynamic default\n```\n\n### How to implement property binding\n\nThis enables you to _delegate_ procedural property getting/setting.\n\n```php\nuse Ailixter\\Gears\\BoundProps;\n\nclass TestBoundProps\n{\n    use BoundProps;\n\n    /** @var BoundPropsInterface */\n    private $myBoundPri;\n}\n\n$test = new TestBoundProps;\n$test-\u003emyBoundPri = new TestPropsBinding;\n$test-\u003emyBoundPri = 'new';\necho $test-\u003emyBoundPri;\n```\n\n### How to proxy your objects\n\n```php\nuse Ailixter\\Gears\\AbstractProxy;\n\nclass TestProxy extends AbstractProxy {}\n\nclass TestObject {\n    public $myPub = 'my public';\n    public function myFn () {\n        return __function__;\n    }\n}\n\n$test = new TestProxy(new TestObject);\necho $test-\u003emyPub;\n$test-\u003emyPub = 'new';\necho $this-\u003emyFn();\n```\n\nor\n\n```php\nclass CustomProxy\n{\n    use Proxy;\n\n    private $proxiedObject;\n\n    public function __construct($proxiedObject)\n    {\n        $this-\u003eproxiedObject = $proxiedObject;\n    }\n}\n```\nor\n\n```php\nclass LazyProxy\n{\n    use Proxy;\n\n    private $obj;\n\n    protected function getProxiedObject()\n    {\n        if (!$this-\u003eobj instanceof ProxiedObject) {\n            $this-\u003eobj = new ProxiedObject;\n        }\n        return $this-\u003eobj;\n    }\n}\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Failixter%2Fgears-overloading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Failixter%2Fgears-overloading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Failixter%2Fgears-overloading/lists"}