greabock/maker

Laravel 5.4 maker

1.1.1 2017-01-29 18:28 UTC

This package is auto-updated.

Last update: 2024-09-09 13:58:40 UTC


README

Build Status

意图(已弃用)

自 v5.4.16 版本起已弃用。请使用 makeWith() 方法代替。
Laravel 5.4 严重削弱了 DI 容器。

容器的 make 方法不再接受第二个参数数组。这个特性通常是一个代码异味。通常,你可以以更直观的方式以另一种方式构造对象。

这个库旨在恢复其往日的辉煌。

# 安装 composer require greabock/maker
更新 composer 后,将 Greabock\Maker\MakerServiceProvider::class 添加到 config/app.php 中的 providers 数组

# 使用

app(Maker::class)->make(Some::class, ['foo' => 'some', 'bar' => 'other'])
// or
make(Some::class, ['foo' => 'some', 'bar' => 'other']);

您还可以绑定闭包

use Illuminate\Contracts\Container\Container;
use Greabock\Maker\Maker;

app(Maker::class)->bind(Some::class, function(Container $container, $parameters){
   $some = $container->make(Some::class);
   $some->doSomeThing($parameters);
   return $some;
});

# 警告!

此函数与旧的 App::make() 类似,但不完全兼容。当使用 Maker 构造对象时,上下文绑定不起作用。