pine3ree/pine3ree-auto-resolve-factory
Composer 安装命令:
composer require pine3ree/pine3ree-auto-resolve-factory
包简介
A ioc factory that resolves dependencies using reflection
README 文档
README
This package provides an autowiring reflection-based factory, which operates
using the pine3ree-params-resolver
library
Example:
// file: src/My/App/Model/PostMapper.php use My\App\Database\ConnectionInterface; use My\App\Database\HydratorInterface; //... class PostMapper { ConnectionInterface $db; HydratorInterface $hydrator; public function __construct(ConnectionInterface $db, HydratorInterface $hydrator) { $this->db = $db; $this->hydrator = $hydrator; } //... } //------------------------------------------------------------------------------ // file: test.php use My\App\Model\PostMapper; use Psr\Container\ContainerInterface; use pine3ree\Container\Factory\AutoResolveFactory; $container = include("config/container.php"); $factory = new AutoResolveFactory(); // We need just one instance of it // All dependencies of PostMapper are resolved by the factory if they are found // in the container, i.e. if: // - $container->get(ConnectionInterface::class) returns a ConnectionInterface object // - $container->get(HydratorInterface::class) returns a HydratorInterface object $postMapper = $factory($container, PostMapper::class);
If the container configuration for the service PostMapper::class instructs
the container to use the auto-resolve-factory, you can just fetch the service instance
from the container:
$postMapper = $container->get(PostMapper::class);
The requested service constructor's arguments are resolved in the following way:
-
If the argument is a type-hinted dependency with a fully-qualified-class/interface name the factory tries to load a dependency registered in the container with that class-string as identifier. If no such dependency is found, the factory will try the default provided value, if any, then the
nullvalue if the argument is nullable, and eventually it will try to instantiate the class directly. An exception is thrown on failure. -
If the argument is not type-hinted or is type-hinted with a builtin type the factory will try to load a service or a parameter value registered in the container with the parameter name as identifier. If not found, the factory will try the default provided value, if any, then the
nullvalue if the argument is nullable, otherwise an exception is thrown.
Example configuration for Mezzio
// file: config/dependencies.php //... use My\App\Database\ConnectionInterface; use My\App\Database\PdoConnection; use My\App\Database\PdoConnectionFactory; use My\App\Database\HydratorInterface; use My\App\Model\PostMapper; use pine3ree\Container\Factory\AutoResolveFactory; //... return [ //... 'invokables' => [ //... HydratorInterface::class => HydratorInterface::class, //... ], 'aliases' => [ //... ConnectionInterface::class => PdoConnection::class, //... ], 'factories' => [ //... PdoConnection::class => PdoConnectionFactory::class, PostMapper::class => AutoResolveFactory::class, // * PostListHandler::class => AutoResolveFactory::class, // * //... ], //... ]; // file: my/App/Handler/PostListHandler.php ------------------------------------ use My\App\Model\PostMapper; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; class PostListHandler implements RequestHandlerInterface { public function __construct(PostMapper $postMapper): ResponseInterface { $this->postMapper = $postMapper; } public function handle(ServerRequestInterface $request): ResponseInterface { // use $this->postMapper and $request to build and return a response } }
pine3ree/pine3ree-auto-resolve-factory 适用场景与选型建议
pine3ree/pine3ree-auto-resolve-factory 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「reflection」 「factory」 「pine3ree」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pine3ree/pine3ree-auto-resolve-factory 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pine3ree/pine3ree-auto-resolve-factory 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pine3ree/pine3ree-auto-resolve-factory 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library emulating the PHP internal reflection using just the tokenized source code.
Testing object factory for PHP
Testing object factory for PHP
Parse use statements for a reflection object
Laravel 5 Model Factory Generator.
A fast and intuitive dependency injection container.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-05-28