{"id":17226766,"url":"https://github.com/dantleech/invoke","last_synced_at":"2025-04-14T01:12:49.736Z","repository":{"id":47114172,"uuid":"226496218","full_name":"dantleech/invoke","owner":"dantleech","description":"Utility to invoke class methods using named parameters","archived":false,"fork":false,"pushed_at":"2021-12-02T21:57:12.000Z","size":83,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T15:13:13.386Z","etag":null,"topics":[],"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/dantleech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-12-07T10:55:45.000Z","updated_at":"2024-02-20T22:20:27.000Z","dependencies_parsed_at":"2022-09-06T05:21:55.022Z","dependency_job_id":null,"html_url":"https://github.com/dantleech/invoke","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Finvoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Finvoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Finvoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Finvoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dantleech","download_url":"https://codeload.github.com/dantleech/invoke/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248402618,"owners_count":21097331,"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":[],"created_at":"2024-10-15T04:17:11.968Z","updated_at":"2025-04-14T01:12:49.705Z","avatar_url":"https://github.com/dantleech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Invoke\n======\n\n[![Build Status](https://travis-ci.org/dantleech/invoke.svg?branch=master)](https://travis-ci.org/dantleech/invoke)\n\nUtility class to create new classes or invoke methods using named arguments.\n\nPHP does not currently support [named\nparameters](https://wiki.php.net/rfc/named_params), this utility provides a\nconvenient way to emulate them.\n\nInstallation\n------------\n\nRequire with composer:\n\n```bash\n$ composer require dantleech/invoke\n```\n\nWhy\n---\n\nSometimes arguments may be sourced from arrays e.g. for \"deserialization\" or\ninstantiating configuration nodes).\n\nValidating the existence of array keys, checking their types etc. is error\nprone and time consuming.\n\nBy using `Invoke::new(MyObject::class, $array)` you can map the array keys\ndirectly to the `__construct` parameters.\n\nThis library will, throw descriptive exceptions:\n\n- If there are extra keys.\n- If there are missing required keys (i.e. non-nullable values).\n- If the types are wrong.\n\nPerformance\n-----------\n\n`Inoke::new(Class::class, [])` is around 50x slower than `new Class()`, or\n260,000 operations per second vs. ~13,000,000.\n\n```\n+--------------------------+---------+\n| subject                  | mode    |\n+--------------------------+---------+\n| benchInvokeNewClass      | 3.720μs |\n| benchInstantiateNewClass | 0.076μs |\n+--------------------------+---------+\n```\n\nUsage\n-----\n\nInstantiate a new class:\n\n```php\n\u003c?php\n\nuse DTL\\Invoke\\Invoke;\n\nclass Foobar\n{\n    public function __construct(string $arg1, string $arg2 = 'val1')\n    {\n    }\n}\n\n$foo = Invoke::new(Foobar::class, [\n    'arg1' =\u003e 'value1'\n]);\n```\n\nInvoke a method:\n\n```php\n\u003c?php\n\nuse DTL\\Invoke\\Invoke;\n\nclass Foobar\n{\n    // ...\n\n    public function one(string $two)\n    {\n    }\n}\n\n$foo = Invoke::new(Foobar::class, [\n    'arg1' =\u003e 'value1'\n]);\n\n$bar= Invoke::method($foo, 'one', [\n    'two' =\u003e 'bar'\n]);\n```\n\nAlternatives\n------------\n\n[nikolaposa/cascader](https://github.com/nikolaposa/cascader)\nUtility for creating objects in PHP from constructor parameters definitions.\n\nContributing\n------------\n\nPull requests are welcome. For major changes, please open an issue first to\ndiscuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\nLicense\n-------\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Finvoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdantleech%2Finvoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Finvoke/lists"}