PHPackages                             norvica/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. norvica/invoker

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

norvica/invoker
===============

Invoke PHP callables with configurable parameter resolving.

v0.2.0(2y ago)011BSD-3-ClausePHPPHP ^8.1

Since Sep 23Pushed 2y agoCompare

[ Source](https://github.com/norvica/invoker)[ Packagist](https://packagist.org/packages/norvica/invoker)[ RSS](/packages/norvica-invoker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Invoker
=======

[](#invoker)

[![Latest Stable Version](https://camo.githubusercontent.com/20bfd1215d4a7ae5cb9c9a232ceee301faa83fb7003f720d1ab45805d3a102fc/68747470733a2f2f706f7365722e707567782e6f72672f6e6f72766963612f696e766f6b65722f762f737461626c652e706e67)](https://packagist.org/packages/norvica/invoker)[![Checks](https://github.com/norvica/invoker/actions/workflows/checks.yml/badge.svg)](https://github.com/norvica/invoker/actions/workflows/checks.yml)

**Invoker** is a lightweight PHP library that simplifies invoking functions or methods with named parameters. It's designed to flexibly resolve missing parameters, utilizing a custom resolver mechanism to provide needed arguments dynamically.

Features
--------

[](#features)

- Invoke any callable (function/method) with named parameters.
- Ability to use custom resolvers for dynamic parameter resolution.
- Zero dependency, ready to integrate with your project.

Installation
------------

[](#installation)

Install via Composer:

```
composer require norvica/invoker
```

Basic Usage
-----------

[](#basic-usage)

Here is a quick example of invoking a simple callable:

```
// using function
$result = \Norvica\Invoker\call('some_function', ['arg1' => 'value1']);

// using class
$result = \Norvica\Invoker\Invoker::call('some_function', ['arg1' => 'value1']);
```

Sure, let's add some advanced examples and explanations to your `readme.md` based on the `dataProvider`. This will show potential users the flexibility of your Invoker library.

---

Advanced Usage
--------------

[](#advanced-usage)

The Invoker library can handle various types of callables including:

- Plain functions
- Closures
- Object instances with an `__invoke()` method
- Object instances with a public method
- Static methods on a class

Here's how you can invoke these using the library:

### Plain Functions

[](#plain-functions)

```
$result = \Norvica\Invoker\call('some_function', ['arg1' => 'value1']);
```

### Closures

[](#closures)

```
$closure = function (string $arg1) {
  // [...]
};
$result = \Norvica\Invoker\call($closure, ['arg1' => 'value1']);
```

### Object with `__invoke` Method

[](#object-with-__invoke-method)

```
$object = new ClassWithInvokeMethod();
$result = \Norvica\Invoker\call($object, ['arg1' => 'value1']);

// same as
$result = \Norvica\Invoker\call([$object, '__invoke'], ['arg1' => 'value1']);
```

### Object with Public Method

[](#object-with-public-method)

```
$object = new ClassWithPublicMethod();
$result = \Norvica\Invoker\call([$object, 'someMethod'], ['arg1' => 'value1']);
```

### Class with Static Method

[](#class-with-static-method)

```
$result = \Norvica\Invoker\call([ClassWithStaticMethod::class, 'someMethod'], ['arg1' => 'value1']);

// or
$result = \Norvica\Invoker\call(ClassWithStaticMethod::class . '::foo', ['arg1' => 'value1']);
```

Variadic Arguments
------------------

[](#variadic-arguments)

The library also supports variadic arguments. Here's how you can pass an array for a variadic parameter.

```
$closure = function (string $arg1, int ...$number) {
  // [...]
};
$result = \Norvica\Invoker\call($closure, ['arg1' => 'value1', 'number' => [1, 2, 3]]);
```

Using a Resolver
----------------

[](#using-a-resolver)

You can implement your own resolvers by adhering to the `Resolver` interface, which has two methods: `resolve()`and `supports()`.

### Example: Resolving PSR-11 Container Services

[](#example-resolving-psr-11-container-services)

Here's how you can create a simple resolver for a PSR-11 Container:

```
use Norvica\Invoker\Resolver;
use ReflectionParameter;
use Psr\Container\ContainerInterface;

final class ServiceResolver implements Resolver
{
    public function __construct(
        private ContainerInterface $container,
    ) {}

    public function resolve(ReflectionParameter $parameter): mixed
    {
        return $this->container->get((string) $parameter->getType());
    }

    public function supports(ReflectionParameter $parameter): bool
    {
        return $this->container->has((string) $parameter->getType());
    }
}
```

To invoke a method with this resolver:

```
$container = // your PSR-11 container
$resolver = new ServiceResolver($container);
$result = \Norvica\Invoker\call([$someObject, 'someMethod'], ['foo' => 'bar'], $resolver);
```

### Example: Resolving PSR-7 Requests

[](#example-resolving-psr-7-requests)

A resolver can be tailored for PSR-7 ServerRequest and Response objects. Here's a sample resolver for handling a `ServerRequestInterface`.

```
use Norvica\Invoker\Resolver;
use ReflectionParameter;
use Psr\Http\Message\ServerRequestInterface;

final class RequestResolver implements Resolver
{
    public function __construct(
        private YourRequestFactory $factory,
    ) {}

    public function resolve(ReflectionParameter $parameter): ServerRequestInterface
    {
        return $this->factory->createFromGlobals();
    }

    public function supports(ReflectionParameter $parameter): bool
    {
        return is_a((string) $parameter->getType(), ServerRequestInterface::class, true);
    }
}
```

To use it:

```
$requestResolver = new RequestResolver($yourRequestFactory);
$result = \Norvica\Invoker\call($someInvokableController, ['id' => '123'], $requestResolver);
```

Of course. Adding that section would clarify the scope and philosophy of the library. Here's how you can include it in your `readme.md`:

Running Tests
-------------

[](#running-tests)

```
./vendor/bin/phpunit --testdox
```

---

Project Philosophy: Lean and Simple
-----------------------------------

[](#project-philosophy-lean-and-simple)

The primary goal of the **Invoker** library is to remain as lean and straightforward as possible. The focus is on providing a core utility for invoking callables with named parameters and custom resolvers.

### Out of Scope

[](#out-of-scope)

While we appreciate suggestions and pull requests, please note that specific implementations of resolvers or extra functionalities are considered **out of scope** for this library. We aim to keep the codebase clean and easily maintainable, without incorporating features that may lead to bloat or complexity.

If you require more specialized behaviors, you are encouraged to extend the library or implement your own resolvers according to your project needs.

---

Similar Concepts and Alternatives
---------------------------------

[](#similar-concepts-and-alternatives)

If you're interested in this library, you might also want to explore other similar tools and frameworks that offer functionality for argument resolution or method invocation.

### Symfony Action Argument Resolving

[](#symfony-action-argument-resolving)

One notable alternative is [Symfony's Action Argument Resolving](https://symfony.com/doc/current/controller/value_resolver.html). This feature allows you to transform the incoming request or any other data into arguments passed into your controller methods. While it's more tightly integrated with the Symfony ecosystem, it offers a wide array of built-in resolvers and the ability to create custom ones.

### PHP-DI Invoker

[](#php-di-invoker)

Another mature project with very similar idea is [PHP-DI Invoker](https://github.com/PHP-DI/Invoker). Feel free to check the project's [README](https://github.com/PHP-DI/Invoker#usage).

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~9 days

Total

3

Last Release

949d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65d17adaa691f6946a6301320413a5871cd9a3284d49914f185b1bb7c7755eee?d=identicon)[serge-kvashnin](/maintainers/serge-kvashnin)

---

Top Contributors

[![serge-kvashnin](https://avatars.githubusercontent.com/u/75180587?v=4)](https://github.com/serge-kvashnin "serge-kvashnin (11 commits)")

---

Tags

callableinvokerresolver

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)[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)[zenstruck/callback

Callable wrapper to validate and inject arguments.

569.6M4](/packages/zenstruck-callback)[rybakit/arguments-resolver

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

26107.7k7](/packages/rybakit-arguments-resolver)[raphhh/trex-reflection

Reflection helpers for callables and types

14324.0k10](/packages/raphhh-trex-reflection)[phpfluent/callback

Allows you execute callbacks in a more dynamic way

1159.2k1](/packages/phpfluent-callback)

PHPackages © 2026

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