marcojetson/invoker

Invoke callables using associative arrays

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

This package is not auto-updated.

Last update: 2024-11-09 18:59:17 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());