yahvya/php-dependency-manager
Composer 安装命令:
composer require yahvya/php-dependency-manager
包简介
Dependency manager php library
README 文档
README
A lightweight dependency injection library for managing and resolving typed dependencies in PHP projects.
📄 Library Details
- 👤 Author and maintainer: Yahaya Bathily - GitHub
- 📄 License: MIT
- 🧾 License usage: Free to use in both commercial and non-commercial projects under the MIT license.
- 🗓️ Created at: 15/08/2025
📚 Documentation
The library consists of three main classes:
Yahay\PhpDependencyInjector\DependencyManagerYahay\PhpDependencyInjector\DependencyBuilderYahay\PhpDependencyInjector\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
This class is responsible for building dependencies — even those not explicitly registered. It provides two key methods:
build()
Accepts aBuilderDataDto, 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 themanualParametersproperty of the DTO.
Example:
new BuilderDataDto(
builder: fn(FakeTwo $two, string $s) => new FakeOne(fakeTwo: $two),
manualParameters: ["s" => "Your value"]
)
getInstanceOf()
Accepts aReflectionNamedTypeand attempts to instantiate it.
This method is lower-level, and usually,build()is sufficient if you're using builder closures.
🧠 DependencyManager
This is the main class of the library. It handles:
- Registering your dependencies via the
dependenciesMapproperty. - 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
To run the tests, clone the repository and run:
php vendor/bin/phpunit
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
Contributions are welcome! Feel free to open issues or submit pull requests.
📫 Contact
If you have any questions or suggestions, feel free to reach out via GitHub.
yahvya/php-dependency-manager 适用场景与选型建议
yahvya/php-dependency-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yahvya/php-dependency-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yahvya/php-dependency-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-25