{"id":22092097,"url":"https://github.com/krakphp/invoke","last_synced_at":"2025-03-23T23:44:52.551Z","repository":{"id":57009027,"uuid":"85446165","full_name":"krakphp/invoke","owner":"krakphp","description":"Invocation Abstraction Library","archived":false,"fork":false,"pushed_at":"2017-09-07T20:25:30.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T13:07:54.011Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-03-19T02:39:31.000Z","updated_at":"2017-03-19T02:40:51.000Z","dependencies_parsed_at":"2022-08-21T14:50:47.113Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/invoke","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Finvoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Finvoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Finvoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Finvoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/invoke/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186923,"owners_count":20574554,"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-12-01T03:08:19.574Z","updated_at":"2025-03-23T23:44:52.526Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Invoke\n\nSimple abstractions for invoking functions with parameters.\n\n## Installation\n\nInstall with composer at `krak/invoke`\n\n## Usage\n\nEach invoker implements the simple interface:\n\n```php\n\u003c?php\n\ninterface Invoke {\n    public function invoke($func, ...$args);\n}\n```\n\nHere's a simple example of the default invoker which uses `call_user_func`.\n\n```php\n\u003c?php\n\nuse Krak\\Invoke;\n\nfunction hello($arg) {\n    echo \"Hello {$arg}\\n\";\n}\n\n$invoke = new Invoke\\CallableInvoke();\n$invoke-\u003einvoke('hello', 'World');\n```\n\n### Container Invoke\n\n```php\n\u003c?php\n\n// some psr container\n$container['service'] = function() {};\n$invoke = Invoke\\ContainerInvoke::create($container);\n$invoke-\u003einvoke('service'); // will invoke the function returned from the container\n$invoke-\u003einvoke('str_repeat', 'a', 10); // if not in container, will try to normally invoke\n```\n\n#### Container with Separator\n\nIn addition to just invoking services, you can invoke service object methods if you pass in a separator into the container factory method.\n\n```php\n\u003c?php\n\n$container['service'] = function() { return new ArrayObject([1]); };\n$invoke = Invoke\\ContainerInvoke::createWithSeparator($container, '@');\n$invoke-\u003einvoke('service@count'); // retrieves the service and invokes the count method which outputs 1 in this case\n```\n\n### Method Invoke\n\n```php\n\u003c?php\n\n// this will invoke any object with the append method\n$invoke = Invoke\\MethodInvoke::create('append');\n\n$data = new ArrayObject();\n$invoke-\u003einvoke($data, 1);\n$invoke-\u003einvoke($data, 2);\nassert(count($data) == 2);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Finvoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Finvoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Finvoke/lists"}