fas/autowire
Composer 安装命令:
composer require fas/autowire
包简介
Fast and simple autowiring
关键字:
README 文档
README
Installation
composer require fas/autowire
Introduction
This library introduces autowiring capabilities using any PSR-11 container. A very simple container is also provided with this library.
Usage
Create object
require __DIR__ . '/../vendor/autoload.php'; use Fas/Autowire/Autowire; $autowire = new Autowire(); // Autowire all constructor arguments $myObject = $autowire->new(MyClass::class); // Override some constructor arguments $myObject = $autowire->new(MyClass::class, ['some_argument' => 'test-value']); // Call a method with no arguments (autowire all arguments) $autowire->call(function (DateTime $datetime, MyClass $myObject) { // do stuff }); // Override argument $autowire->call(function (DateTime $datetime, MyClass $myObject) { // do stuff }, ['datetime' => new DateTime('2021-07-01 12:34:56')]); // Any callable will do // Plain function $upperCased = $autowire->call('strtoupper', ['str' => 'something-in-lower-case']); // Static method $datetime = $autowire->call([DateTime::class, 'createFromFormat'], [ 'format' => 'Y-m-d H:i:s', 'time' => '2021-01-02 12:34:56', // php7 'datetime' => '2021-01-02 12:34:56', // php8 'object' => new DateTimeZone('Europe/Copenhagen'), ]); // Instance method $autowire->call([new DateTime, 'setTime'], ['hour' => 0, 'minute' => 1, 'second' => 2, 'microseconds' => 123]); // Invokable class $autowire->call($myInvokableClass, ['my_param' => 'test']);
Using Autowiring for any psr-11 container:
$container = new MyPsrContainer(); $autowire = new Autowire($container);
Using the fas/autowire container
$container = new Container(); $container->set(LoggerInterface::class, NullLogger::class); $autowire = new Autowire($container); $autowire->call(function (LoggerInterface $logger) { $logger->info("Logging using whatever logger is defined for LoggerInterface in the container"); });
fas/autowire 适用场景与选型建议
fas/autowire 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 177 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「di」 「autowire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fas/autowire 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fas/autowire 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fas/autowire 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Autowire and configure using PHP 8 Attributes in Laravel.
A fast and intuitive dependency injection container.
A fast, autowired PSR-11 dependency injection container for PHP with cached resolution closures.
PSR-11 Container for Dependency Injection (auto-wiring, attributes, factories, closures, array access)
autowire dependency injection from PSR-11 containers
Dependency injection container for the Monolith framework.
统计信息
- 总下载量: 177
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-30