PHPackages                             sroze/argument-resolver - 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. sroze/argument-resolver

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

sroze/argument-resolver
=======================

A lightweight utility to resolve method arguments based on types and names

2.0.4(8y ago)1042.9k↓18.1%1[1 PRs](https://github.com/sroze/ArgumentResolver/pulls)1MITPHP

Since Mar 31Pushed 8y ago2 watchersCompare

[ Source](https://github.com/sroze/ArgumentResolver)[ Packagist](https://packagist.org/packages/sroze/argument-resolver)[ Docs](https://github.com/sroze/ArgumentResolver)[ RSS](/packages/sroze-argument-resolver/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (1)

Argument Resolver
=================

[](#argument-resolver)

[![Build Status](https://camo.githubusercontent.com/002f51990b61eefb1e444ddbd984420b04b356624dae083c3214e2daf8fbf072/68747470733a2f2f7472617669732d63692e6f72672f73726f7a652f417267756d656e745265736f6c7665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sroze/ArgumentResolver)[![SensioLabsInsight](https://camo.githubusercontent.com/bde3923a5dd938cedc7e679951f1691f1ebedc1bf3de9dc1847682c313e4b3f4/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f38386534613366382d626335652d343465322d383465342d3566386335313461643632662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/88e4a3f8-bc5e-44e2-84e4-5f8c514ad62f)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4f66271916aaa20cab80c89b66467953c29fc2191102ce061d9e1d90d5186f12/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73726f7a652f417267756d656e745265736f6c7665722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sroze/ArgumentResolver/?branch=master)

This lightweight library helps to automatically call a callable (function, method or closure) with a list of available arguments. The developer of the callable can then use type hinting and/or specific variable names to chose which arguments (s)he wants.

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

[](#installation)

The suggested installation method is via composer:

```
composer require sroze/argument-resolver

```

Resolving arguments
-------------------

[](#resolving-arguments)

The argument resolver can be created easily using the `ArgumentResolverFactory` class:

```
use ArgumentResolver\ArgumentResolverFactory;

$argumentResolver = ArgumentResolverFactory::create();
```

The `resolveArguments` method returns an ordered array of resolved arguments for the given callable. The method's arguments are:

1. The [callable](http://php.net/manual/en/language.types.callable.php)
2. The available arguments, as an array

Here's an example of how it can be used to have arguments of some closures based on a set of available arguments:

```
$closures = [
    function(MyClass $object) {
        return $object instanceof MyClass;
    },
    function($bar, array $list) {
        return count($list);
    }
];

foreach ($closures as $callable) {
    $arguments = $argumentResolver->resolveArguments($callable, [
        'classObject' => new MyClass(),
        'bar' => 'foo',
        'list' => ['an', 'array']
    ]);

    // ...
}
```

More than argument identification with type hinting, you can also use names:

```
class Foo
{
    public function method($foo, $bar)
    {
    }
}

$argumentResolver->resolveArguments([new Foo(), 'method'], [
    'bar' => 1,
    'foo' => 2,
    'baz' => 3
]);

// Which returns: [2, 1]
```

To prevent possible conflicts, the library follow priorities and constraints described in the [Rules](#rules) chapter.

The callable runner
-------------------

[](#the-callable-runner)

Because when you've resolved the needed arguments of a given callable it's often to call it, the library comes with a `CallableRunner` class that will do everything for you:

```
$runner = new CallableRunner($argumentResolver);
$runner->run($callable, $availableArguments);
```

Instantiate an object
---------------------

[](#instantiate-an-object)

Sometimes, you would like to instantiate an object with a set of arguments. Here's the `Instanciator` usage:

```
$instantiator = new Instantiator($argumentResolver);
$instantiator->instantiate(YourClassName::class, $availableArguments);
```

Rules
-----

[](#rules)

### Priorities

[](#priorities)

These are the resolution priorities for the arguments:

1. *Strict matching:* Same name and same type
2. *Type matching*
3. *Name matching*

Constraints
-----------

[](#constraints)

The following constraints applies:

- If there's multiple arguments of the same type, then strict matching apply for this type
- Required arguments have to be resolved

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~165 days

Recently: every ~237 days

Total

7

Last Release

3121d ago

Major Versions

v1.0.1 → 2.0.02015-05-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/58b8aaf662150e054108b611b620d1cf8c1cb91e00f76d3dfcd2d7a69a10991c?d=identicon)[sroze](/maintainers/sroze)

---

Top Contributors

[![sroze](https://avatars.githubusercontent.com/u/804625?v=4)](https://github.com/sroze "sroze (30 commits)")

---

Tags

type-hintresolverargument

### Embed Badge

![Health badge](/badges/sroze-argument-resolver/health.svg)

```
[![Health](https://phpackages.com/badges/sroze-argument-resolver/health.svg)](https://phpackages.com/packages/sroze-argument-resolver)
```

###  Alternatives

[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

50458.3M110](/packages/marc-mabe-php-enum)[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)[rybakit/arguments-resolver

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

26112.9k7](/packages/rybakit-arguments-resolver)[seferov/typhp

Enforce type declaring

533.4k](/packages/seferov-typhp)[acelot/resolver

Dependency auto resolver for PHP 7 and 8

122.7k](/packages/acelot-resolver)

PHPackages © 2026

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