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

ActiveLibrary

acelot/resolver
===============

Dependency auto resolver for PHP 7 and 8

2.4.0(4y ago)122.6k↑66.7%1MITPHPPHP ^7.3 || ^8.0

Since May 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/acelot/resolver)[ Packagist](https://packagist.org/packages/acelot/resolver)[ Docs](https://github.com/acelot/resolver)[ RSS](/packages/acelot-resolver/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (10)Used By (0)

Resolver
========

[](#resolver)

[![Build Status](https://camo.githubusercontent.com/0289640af9f18a8e4aa891fe893b833ab75b390bf50478a84de4f60f99424ebe/68747470733a2f2f7472617669732d63692e6f72672f6163656c6f742f7265736f6c7665722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/acelot/resolver)[![Code Climate](https://camo.githubusercontent.com/b9eb818596bc7655ba1e13c76c54f404a755dd5ea5b466a2dffdd0f4587b48ad/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6163656c6f742f7265736f6c7665722e737667)](https://codeclimate.com/github/acelot/resolver)[![](https://camo.githubusercontent.com/f8a8828518e1a83fe1a2ee9be91c94e14e443da880294f80f3dfd3a58d24407c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d7a65726f2d626c75652e737667)](https://camo.githubusercontent.com/f8a8828518e1a83fe1a2ee9be91c94e14e443da880294f80f3dfd3a58d24407c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d7a65726f2d626c75652e737667)[![](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)

**Resolver** is a dependency auto resolver for PHP 7 and 8. Supports PSR-11 `ContainerInterface`.

### Installation

[](#installation)

```
composer require acelot/resolver

```

### Why?

[](#why)

Imagine that you have a controller:

```
class UsersController
{
    public function __construct(UsersService $service)
    {
        // ...
    }
}
```

As you can see the controller requires `UsersService` in constructor. To resolve this dependency you can just pass the new instance of `UsersService`. Let's do this:

```
$service = new UsersService();
$controller = new UsersController($service);
```

It doesn't work, because `UsersService`, in turn, requires `UsersRepository` to access the data.

```
class UsersService
{
    public function __construct(UsersRepository $repository)
    {
        // ...
    }
}
```

Okay, let's create the repository instance!

```
$repository = new UsersRepository();
$service = new UsersService($repository);
$controller = new UsersController($service);
```

Sadly, it still doesn't work, because we encountering the new dependency! The repository, surprisingly, requires a database connection :)

```
class UsersRepository
{
    public function __construct(Database $db)
    {
        // ...
    }
}
```

You say "Eat this!".

```
$db = new Database('connection string here');
$repository = new UsersRepository($db);
$service = new UsersService($repository);
$controller = new UsersController($service);
```

Success! We have finally created the instance of `UsersController`! Now imagine that you have ten or hundred controllers like this?! With **Resolver** you can greatly simplify creation of classes. In what turns this code using **Resolver**:

```
$resolver = new Resolver([
    Database::class => ObjectDefinition::define(Database::class)->withArgument('connectionString', 'connection string here')
]);

$controller = $resolver->resolve(UsersController::class);
```

And it's all.

### How it works?

[](#how-it-works)

**Resolver** resolves the classes by using [Reflection](http://php.net/manual/ru/book.reflection.php). Through reflection the **Resolver** finds out all dependencies of the class and all dependencies of dependencies and so on. When **Resolver** reaches the deepest dependency it starts creating instances of these one by one until the top class. The resolved classes are stored in local array to avoid re-resolving.

### Available definitions

[](#available-definitions)

- FactoryDefinition (short alias `factory()`)
- ObjectDefinition (short alias `object()`)
- ValueDefinition (short alias `value()`)

### Instance sharing

[](#instance-sharing)

Resolved definitions can be shared between calls via `->shared()` method. This method available in `FactoryDefinition` and `ObjectDefinition`. `ValueDefinition` is shared always by design.

---

**Resolver** (c) by Valeriy Protopopov.

**Resolver** is licensed under a MIT license.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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 ~216 days

Recently: every ~284 days

Total

8

Last Release

1764d ago

Major Versions

0.1.0 → 1.0.02017-10-02

1.0.0 → 2.0.02017-12-12

PHP version history (2 changes)0.1.0PHP ^7.1

2.4.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e8e4631dcd1e5485b4fe6a80f5c6feea95c388ca6b522c3cc69cb4eee8cc284?d=identicon)[acelot](/maintainers/acelot)

---

Top Contributors

[![acelot](https://avatars.githubusercontent.com/u/1065215?v=4)](https://github.com/acelot "acelot (32 commits)")[![sparfenov](https://avatars.githubusercontent.com/u/9413081?v=4)](https://github.com/sparfenov "sparfenov (1 commits)")

---

Tags

dependency-injectioninversion-of-controlphppsr-11dependency-injectionresolverinversion of control

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[mouf/mouf

The Mouf PHP framework: an open-source PHP framework providing an easy way to download, install, use and reuse components, with a graphical user interface.

55146.0k17](/packages/mouf-mouf)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)

PHPackages © 2026

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