marcojetson/invoker

Invoke callables using associative arrays

Maintainers

Package info

github.com/marcojetson/invoker

pkg:composer/marcojetson/invoker

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2015-05-30 08:31 UTC

This package is not auto-updated.

Last update: 2026-03-01 02:43:33 UTC


README

Invoke PHP callables using associative arrays

Build status Test coverage

Usage

Use invoke providing a callable and the arguments as an associative array

function person($name, $age)
{
}

$invoker = new Invoker();
$invoker->invoke('person', ['age' => 29, 'name' => 'Marco']);

Supports optional arguments

function person($name, $age = 29)
{
}

$invoker = new Invoker();
$invoker->invoke('person', ['name' => 'Marco']);

Callables

In addition to PHP callables you can use the following forms as first argument:

  • A class name implementing the __invoke magic method
  • A string containing class::method

You can implement Resolver interface and inject it into Invoker's constructor for adding your own forms

$invoker = new Invoker(new MyResolver());