PHPackages                             yahvya/php-dependency-manager - 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. yahvya/php-dependency-manager

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

yahvya/php-dependency-manager
=============================

Dependency manager php library

00PHP

Since Aug 25Pushed 10mo agoCompare

[ Source](https://github.com/yahvya/personal-php-dependency-manager)[ Packagist](https://packagist.org/packages/yahvya/php-dependency-manager)[ RSS](/packages/yahvya-php-dependency-manager/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP Dependency Manager
======================

[](#php-dependency-manager)

> A lightweight dependency injection library for managing and resolving typed dependencies in PHP projects.

---

📄 Library Details
-----------------

[](#-library-details)

- 👤 **Author and maintainer**: Yahaya Bathily - [GitHub](https://github.com/yahvya)
- 📄 **License**: MIT
- 🧾 **License usage**: Free to use in both commercial and non-commercial projects under the MIT license.
- 🗓️ **Created at**: 15/08/2025

---

📚 Documentation
---------------

[](#-documentation)

The library consists of three main classes:

- `Yahay\PhpDependencyInjector\DependencyManager`
- `Yahay\PhpDependencyInjector\DependencyBuilder`
- `Yahay\PhpDependencyInjector\DependencyMap`

---

### 🧩 DependencyMap

[](#-dependencymap)

This class lets you register all your dependencies — including those that are challenging to instantiate manually.
It provides the following methods:

- `register()` — registers a dependency that should be rebuilt on each call.
- `registerSingleton()` — registers a dependency that should be built only once and reused.

These methods take a builder closure wrapped in a `BuilderDataDto` instance. The closure can receive any class from your application (registered or not).

Example:

```
$manager->dependenciesMap->register(
    class: FakeOne::class,
    builderData: new BuilderDataDto(
        builder: fn(FakeTwo $two, AnyClassThere $c) => new FakeOne(fakeTwo: $two)
    )
);

```

---

### 🛠️ DependencyBuilder

[](#️-dependencybuilder)

This class is responsible for building dependencies — even those not explicitly registered. It provides two key methods:

- `build()`
    Accepts a `BuilderDataDto`, resolves the dependencies required by the builder closure, and returns the result.
    Since PHP built-in types (e.g., `string`, `int`) cannot be auto-instantiated, you can pass manual values via the `manualParameters` property of the DTO.

Example:

```
new BuilderDataDto(
    builder: fn(FakeTwo $two, string $s) => new FakeOne(fakeTwo: $two),
    manualParameters: ["s" => "Your value"]
)

```

- `getInstanceOf()`
    Accepts a `ReflectionNamedType` and attempts to instantiate it.
    This method is lower-level, and usually, `build()` is sufficient if you're using builder closures.

---

### 🧠 DependencyManager

[](#-dependencymanager)

This is the main class of the library. It handles:

- Registering your dependencies via the `dependenciesMap` property.
- Retrieving a dependency using `getDependency(ClassName::class)`.
- Calling a method with automatic dependency injection via `call($object, $methodName)`.

You can instantiate it manually or extend it for your own manager.
However, the recommended usage is to call `DependencyManager::get()` to access a shared singleton instance across your application.

---

✅ Library Test Coverage
-----------------------

[](#-library-test-coverage)

To run the tests, clone the repository and run:

```
php vendor/bin/phpunit

```

### Code Coverage Report

[](#code-coverage-report)

```
Code Coverage Report:
2025-08-15 09:40:48

Summary:
Classes: 75.00% (3/4)
Methods: 61.54% (8/13)
Lines:   91.25% (73/80)

Yahay\PhpDependencyInjector\BuilderDataDto
Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  1/  1)
Yahay\PhpDependencyInjector\DependencyBuilder
Methods:  16.67% ( 1/ 6)   Lines:  86.79% ( 46/ 53)
Yahay\PhpDependencyInjector\DependencyManager
Methods: 100.00% ( 4/ 4)   Lines: 100.00% ( 22/ 22)
Yahay\PhpDependencyInjector\DependencyMap
Methods: 100.00% ( 2/ 2)   Lines: 100.00% (  4/  4)

```

---

🙌 Contributing
--------------

[](#-contributing)

Contributions are welcome! Feel free to open issues or submit pull requests.

---

📫 Contact
---------

[](#-contact)

If you have any questions or suggestions, feel free to reach out via [GitHub](https://github.com/yahvya).

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/68204965?v=4)[Yahaya](/maintainers/yahvya)[@yahvya](https://github.com/yahvya)

---

Top Contributors

[![yahvya](https://avatars.githubusercontent.com/u/68204965?v=4)](https://github.com/yahvya "yahvya (15 commits)")

### Embed Badge

![Health badge](/badges/yahvya-php-dependency-manager/health.svg)

```
[![Health](https://phpackages.com/badges/yahvya-php-dependency-manager/health.svg)](https://phpackages.com/packages/yahvya-php-dependency-manager)
```

###  Alternatives

[runtime/swoole

Swoole runtime

56188.8k3](/packages/runtime-swoole)[verbb/default-dashboard

Set default dashboard widgets for users.

13148.8k1](/packages/verbb-default-dashboard)

PHPackages © 2026

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