定制 fas/autowire 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fas/autowire

Composer 安装命令:

composer require fas/autowire

包简介

Fast and simple autowiring

README 文档

README

Build Status Test Coverage

Latest Stable Version Latest Unstable Version License Total Downloads

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");
});

统计信息

  • 总下载量: 177
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固