{"id":19112889,"url":"https://github.com/chipslays/sauce","last_synced_at":"2025-07-20T06:04:19.400Z","repository":{"id":56952082,"uuid":"361295541","full_name":"chipslays/sauce","owner":"chipslays","description":"🍅 A sauce made from useful things.","archived":false,"fork":false,"pushed_at":"2022-03-23T06:45:25.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-28T07:55:36.183Z","etag":null,"topics":["collection","traits"],"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/chipslays.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-25T00:28:50.000Z","updated_at":"2022-03-23T06:45:05.000Z","dependencies_parsed_at":"2022-08-21T03:40:28.528Z","dependency_job_id":null,"html_url":"https://github.com/chipslays/sauce","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/chipslays/sauce","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fsauce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fsauce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fsauce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fsauce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chipslays","download_url":"https://codeload.github.com/chipslays/sauce/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipslays%2Fsauce/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266076031,"owners_count":23872729,"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":["collection","traits"],"created_at":"2024-11-09T04:34:26.471Z","updated_at":"2025-07-20T06:04:19.342Z","avatar_url":"https://github.com/chipslays.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🍅 Sauce\n\n[![Tests](https://github.com/chipslays/sauce/actions/workflows/tests.yml/badge.svg)](https://github.com/chipslays/sauce/actions/workflows/tests.yml)\n![Packagist Version](https://img.shields.io/packagist/v/chipslays/sauce)\n![GitHub](https://img.shields.io/github/license/chipslays/sauce)\n\nA sauce made from useful things.\n\n# Installation\n\n```bash\n$ composer require chipslays/sauce\n```\n\n# Usage\n\n## Singleton\n\nA simple implementation of a Singleton as a trait.\n\n```php\nuse Sauce\\Traits\\Singleton;\n\nclass Hero\n{\n    use Singleton;\n}\n\n$hero1 = Hero::getInstance();\n$hero1-\u003eattack();\n\nHero::forgetInstance();\n$hero2 = Hero::getInstance();\n$hero2-\u003eattack();\n```\n\n```php\nuse Sauce\\Traits\\Singleton;\n\nclass SingletonClass {\n    use Singleton;\n\n    private $value;\n\n    /**\n     * @param mixed $value\n     * @return static\n     */\n    public function set($value)\n    {\n        $this-\u003evalue = $value;\n        return $this;\n    }\n\n    /**\n     * @return mixed\n     */\n    public function get()\n    {\n        return $this-\u003evalue;\n    }\n}\n\necho SingletonClass::getInstance()-\u003eset(1)-\u003eget(); // return 2\necho SingletonClass::getInstance()-\u003eset(2)-\u003eget(); // return 2\n\nSingletonClass::forgetInstance();\necho SingletonClass::getInstance()-\u003eset(3)-\u003eget(); // return 3\n```\n\n## Mappable\n\nWhen applied to a class, makes it possible to add methods to that class at runtime.\n\n\u003e ℹ `Mappable` already include `Call` trait.\n\n```php\nuse Sauce\\Traits\\MappableClass;\n\nclass MappableClass {\n    use Mappable;\n}\n\n$class = new MappableClass;\n$class-\u003emap('sum', fn(...$args) =\u003e array_sum($args));\necho $class-\u003esum(1000, 300, 30, 5, 2) // 1337\n\n$class::mapOnce('timestamp', fn() =\u003e time());\necho $class-\u003etimestamp(); // e.g. 1234567890\necho $class-\u003etimestamp(); // e.g. 1234567890\n```\n\n```php\nuse Sauce\\Traits\\MappableClass;\n\nclass MappableClass {\n    use Mappable;\n}\n\nMappableClass::map('sum', fn(...$args) =\u003e array_sum($args));\necho MappableClass::sum(1000, 300, 30, 5, 2)\n\nMappableClass::mapOnce('timestamp', fn() =\u003e time());\necho MappableClass::timestamp()\n```\n\n## Call\n\nCall function or static/non-static classes.\n\n```php\nuse Sauce\\Traits\\Call;\n\nclass MyClass {\n    use Call;\n}\n\n$class = new MyClass;\n$class-\u003e__call_function(fn () =\u003e true);\n$class-\u003e__call_function('\\App\\Controllers\\MainController@home');\n$class-\u003e__call_function('\\App\\Controllers\\MainController@users', [$id]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fsauce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchipslays%2Fsauce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipslays%2Fsauce/lists"}