PHPackages                             divineniiquaye/php-invoker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. divineniiquaye/php-invoker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

divineniiquaye/php-invoker
==========================

A library that provides the abilities to invoking callables with named parameters in a generic and extensible way.

v0.9.12(5y ago)310.0k12BSD-3-ClausePHPPHP ^7.1 || ^8.0CI passing

Since Aug 7Pushed 5y ago1 watchersCompare

[ Source](https://github.com/divineniiquaye/php-invoker)[ Packagist](https://packagist.org/packages/divineniiquaye/php-invoker)[ Docs](https://www.biurad.com)[ Fund](https://biurad.com/sponsor)[ Patreon](https://www.patreon.com/biurad)[ RSS](/packages/divineniiquaye-php-invoker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (2)

The PHP Invoker
===============

[](#the-php-invoker)

[![Latest Version](https://camo.githubusercontent.com/edb85e4cd33262783296f688e45d75f00639cec889e0df1bc618b9d9239f9cce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646976696e656e696971756179652f7068702d696e766f6b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/divineniiquaye/php-invoker)[![Software License](https://camo.githubusercontent.com/d8c1f1b4c1b899449e9539d4de1ca66abde4c190f41ce41e7abc3330da5cad2e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4253442d2d332d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Workflow Status](https://camo.githubusercontent.com/800d635066c6cdde140ecc4b2398a5dec61ed8fd065a1db4b9459a7f19c9bfda/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f646976696e656e696971756179652f7068702d696e766f6b65722f54657374733f7374796c653d666c61742d737175617265)](https://github.com/divineniiquaye/php-invoker/actions?query=workflow%3ATests)[![Code Maintainability](https://camo.githubusercontent.com/2654d9f692ddc2a1cd68168e068c1f53f54656608fc43f6147404182ed8744da/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f646976696e656e696971756179652f7068702d696e766f6b65723f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/divineniiquaye/php-invoker)[![Coverage Status](https://camo.githubusercontent.com/baff27ccded076377c772fd5ea14c4242150a2a9544ddfe96ba01029742839e4/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f646976696e656e696971756179652f7068702d696e766f6b65723f7374796c653d666c61742d737175617265)](https://codecov.io/gh/divineniiquaye/php-invoker)[![Quality Score](https://camo.githubusercontent.com/7dd0d8461515724dff1d64a0e113838f767c267bb3cdce11dd8053c2329a32ad/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f646976696e656e696971756179652f7068702d696e766f6b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/divineniiquaye/php-invoker)[![Sponsor development of this project](https://camo.githubusercontent.com/2e662697b46a37233abdd7e45373397aab0bd5206336533151cdf42455d81048/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f72253230746869732532307061636b6167652d2545322539442541342d6666363962342e7376673f7374796c653d666c61742d737175617265)](https://biurad.com/sponsor)

**divineniiquaye/php-invoker** is a php library that allows invoking callables with named parameters in a generic and extensible way for [PHP](https://php.net) 7.1+, based on reference implementation [PHP-DI Invoker](https://github.com/PHP-DI/Invoker) created by [Matthieu Napoli](https://github.com/mnapoli). This library provides clear extension points to let frameworks/projects implement any kind of dependency injection support they want, but not limited to dependency injection. Again, any [PSR-11](http://www.php-fig.org/psr/psr-11/) compliant container can be provided.

📦 Installation &amp; Basic Usage
--------------------------------

[](#-installation--basic-usage)

This project requires [PHP](https://php.net) 7.1 or higher. The recommended way to install, is via [Composer](https://getcomposer.org). Simply run:

```
$ composer require divineniiquaye/php-invoker
```

Let's say you working on a project and want to invoke some named parameters in callables with whatever the order of parameters, but should be matched by their names or instance. Then we'll need an over-engineered `call_user_func()`.

In short, this library is meant to be a base building block for calling a function with named parameters and/or dependency injection.

Using `DivineNii\Invoker\Invoker` class method `call`:

```
$invoker = new DivineNii\Invoker\Invoker;

$invoker->call(function () {
    echo 'Hello world!';
});

// Simple parameter array
$invoker->call(function ($name) {
    echo 'Hello ' . $name;
}, ['John']);

// Named parameters
$invoker->call(function ($name) {
    echo 'Hello ' . $name;
}, [
    'name' => 'John'
]);

// Typehint parameters
$invoker->call(function (string $name) {
    echo 'Hello ' . $name;
}, [
    'name' => 'John'
]);

// Use the default value
$invoker->call(function ($name = 'world') {
    echo 'Hello ' . $name;
});

// Invoke any PHP callable
$invoker->call(['MyClass', 'myStaticMethod']);

// Using Class::method syntax
$invoker->call('MyClass::myStaticMethod');

// Using ":" pattern syntax
$invoker->call('MyClass:myMethod');

// Using "@" pattern syntax
$invoker->call('MyClass@myMethod');
```

Using `DivineNii\Invoker\ArgumentResolver` class in `DivineNii\Invoker\Invoker` class:

Extending the behavior of the `DivineNii\Invoker\Invoker` is easy and is done by adding a callable to [`ArgumentResolver`](https://github.com/divineniiquaye/php-invoker/blob/master/src/ArgumentResolver.php) class:

```
use ReflectionParameter;
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;

class MyParameterValueResolver implements ArgumentValueResolverInterface
{
    /**
     * {@inheritdoc}
     */
    public function resolve(ReflectionParameter $parameter, array $providedParameters)
    {
        //....
    }
}
```

- `$providedParameters` contains the parameters provided by the user when calling `$invoker->call($callable, $parameters)`

An `DivineNii\Invoker\Invoker` can chain multiple parameter resolvers to mix behaviors, e.g. you can mix "named parameters" support with "dependency injection" support.

Here is an implementation example for dumb dependency injection that creates a new instance of the classes type-hinted:

```
use {ReflectionClass, ReflectionException};
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;

class MyParameterValueResolver implements ArgumentValueResolverInterface
{
    /**
     * {@inheritdoc}
     */
    public function resolve(ReflectionParameter $parameter, array $providedParameters)
    {
        $parameterClass = $parameter->getClass();

        if ($parameterClass instanceof ReflectionClass) {
            try {
                return $class->newInstance();
            } catch (ReflectionExcetion $e) {
                // ...
            }
        }
    }
}
```

To use it:

```
$invoker = new DivineNii\Invoker\Invoker([new MyParameterValueResolver()]);

$invoker->call(function (ArticleManager $articleManager) {
    $articleManager->publishArticle('Hello world', 'This is the article content.');
});
```

A new instance of `ArticleManager` will be created by our parameter resolver. The fun starts to happen when we want to add support for many things:

- named parameters
- dependency injection for type-hinted parameters
- ...

It allows to support even the weirdest use cases like:

```
$parameters = [];

// First parameter will receive "Welcome"
$parameters[] = 'Welcome';

// Parameter named "content" will receive "Hello world!"
$parameters['content'] = 'Hello world!';

// $published is not defined so it will use its default value
$invoker->call(function ($title, $content, $published = true) {
    // ...
}, $parameters);
```

Rather than have you re-implement support for dependency injection with different containers every time, this package ships with 2 optional resolvers:

- This resolver will inject container entries by searching for the class name using the type-hint:

    ```
    $invoker->call(function (Psr\Logger\LoggerInterface $logger) {
        // ...
    });
    ```

    In this example it will `->get('Psr\Logger\LoggerInterface')` from the container and inject it, but if instance of interface exist in `$providedParameters`, it also get injected.
- This resolver will inject container entries by searching for the name of the parameter:

    ```
    $invoker->call(function ($twig) {
        // ...
    });
    ```

    In this example it will `->get('twig')` from the container and inject it or from `$providedParameters`.

The `DivineNii\Invoker\Invoker` can be wired to your DI container to resolve the callables, but can resolve all callables including invokable class or object.

For example with an invokable class:

```
class MyHandler
{
    public function __invoke()
    {
        // ...
    }
}

// By default this work
$invoker->call('MyHandler');

// If we set up the container to use
$invoker = new Invoker\Invoker([], $container);
// Now 'MyHandler' parameters is resolved using the container if any!
$invoker->call('MyHandler');
```

The same works for a class method:

```
class WelcomeController
{
    public function home()
    {
        // ...
    }
}

// By default this doesn't work: home() is not a static method
$invoker->call(['WelcomeController', 'home']);

// If we set up the container to use
$invoker = new Invoker\Invoker([], $container);
// Now 'WelcomeController' is resolved using the container!
$invoker->call(['WelcomeController', 'home']);
// Alternatively we can use the Class::method syntax
$invoker->call('WelcomeController::home');
```

📓 Documentation
---------------

[](#-documentation)

For in-depth documentation before using this library. Full documentation on advanced usage, configuration, and customization can be found at [docs.biurad.com](https://docs.biurad.com/php-invoker).

⏫ Upgrading
-----------

[](#-upgrading)

Information on how to upgrade to newer versions of this library can be found in the [UPGRADE](UPGRADE-1.x.md).

🏷️ Changelog
------------

[](#️-changelog)

[SemVer](http://semver.org/) is followed closely. Minor and patch releases should not introduce breaking changes to the codebase; See [CHANGELOG](CHANGELOG-0.x.md) for more information on what has changed recently.

Any classes or methods marked `@internal` are not intended for use outside of this library and are subject to breaking changes at any time, so please avoid using them.

🛠️ Maintenance &amp; Support
----------------------------

[](#️-maintenance--support)

When a new **major** version is released (`1.0`, `2.0`, etc), the previous one (`0.19.x`) will receive bug fixes for *at least* 3 months and security updates for 6 months after that new release comes out.

(This policy may change in the future and exceptions may be made on a case-by-case basis.)

**Professional support, including notification of new releases and security updates, is available at [Biurad Commits](https://commits.biurad.com/php-invoker.git).**

👷‍♀️ Contributing
-----------------

[](#‍️-contributing)

To report a security vulnerability, please use the [Biurad Security](https://security.biurad.com). We will coordinate the fix and eventually commit the solution in this project.

Contributions to this library are **welcome**, especially ones that:

- Improve usability or flexibility without compromising our ability to adhere to [PSR-12](http://www.php-fig.org/psr/psr-12/) coding stardand.
- Optimize performance
- Fix issues with adhering to [PSR-11](http://www.php-fig.org/psr/psr-11/) support and backward compatability.

Please see [CONTRIBUTING](./.github/CONTRIBUTING.md) for additional details.

🧪 Testing
---------

[](#-testing)

```
$ composer test
```

This will tests divineniiquaye/php-invoker will run against PHP 7.2 version or higher.

👥 Credits &amp; Acknowledgements
--------------------------------

[](#-credits--acknowledgements)

- [Divine Niiquaye Ibok](https://github.com/divineniiquaye)
- [All Contributors](https://github.com/divineniiquaye/php-invoker/contributors)

🙌 Sponsors
----------

[](#-sponsors)

Are you interested in sponsoring development of this project? Reach out and support us on [Patreon](https://www.patreon.com/biurad) or see  for a list of ways to contribute.

📄 License
---------

[](#-license)

**divineniiquaye/php-invoker** is licensed under the BSD-3 license. See the [`LICENSE`](LICENSE) file for more details.

🏛️ Governance
-------------

[](#️-governance)

This project is primarily maintained by [Divine Niiquaye Ibok](https://github.com/divineniiquaye). Members of the [Biurad Lap](https://team.biurad.com) Leadership Team may occasionally assist with some of these duties.

🗺️ Who Uses It?
---------------

[](#️-who-uses-it)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us an [email](support@biurad.com) or [message](https://projects.biurad.com/message) mentioning this library. We publish all received request's at .

Check out the other cool things people are doing with `divineniiquaye/php-invoker`:

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Total

12

Last Release

1891d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a71bed376af70d8c5eeb12c80cfb4bf428f70e48301fb2bba1d4a87009e20eeb?d=identicon)[divineniiquaye](/maintainers/divineniiquaye)

---

Top Contributors

[![divineniiquaye](https://avatars.githubusercontent.com/u/53147395?v=4)](https://github.com/divineniiquaye "divineniiquaye (87 commits)")[![cyclonecopp](https://avatars.githubusercontent.com/u/46801032?v=4)](https://github.com/cyclonecopp "cyclonecopp (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

biuradcallablesdependency-injectiondi-invokerphpinvokerresolverPHP7biurad

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/divineniiquaye-php-invoker/health.svg)

```
[![Health](https://phpackages.com/badges/divineniiquaye-php-invoker/health.svg)](https://phpackages.com/packages/divineniiquaye-php-invoker)
```

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[dflydev/placeholder-resolver

Given a data source representing key =&gt; value pairs, resolve placeholders like ${foo.bar} to the value associated with the 'foo.bar' key in the data source.

14414.6M3](/packages/dflydev-placeholder-resolver)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[sunrise/vin

VIN decoder for PHP 7.1+ based on ISO-3779

83127.0k](/packages/sunrise-vin)[rybakit/arguments-resolver

ArgumentsResolver allows you to determine the arguments to pass to a function or method.

26107.7k7](/packages/rybakit-arguments-resolver)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
