smorken/support
最新稳定版本:v10.6.0
Composer 安装命令:
composer require smorken/support
包简介
Support classes for Laravel
README 文档
README
License
This software is open-sourced software licensed under the MIT license
The Laravel framework is open-sourced software licensed under the MIT license
Installation
The service provider should automatically register.
If not, you can manually add Smorken\Support\ServiceProvider::class to the
providers section of config/app.php.
Binder
The binder is a method to automatically wire dependencies from a config array. I use it primarily for wiring storage to models.
The config array contains a concrete key and a contract key.
The concrete key can contain all of the possible concrete implementations
that your project contains for a contract. The contract key
contains the actual implementation to be used.
Simple dependency example
$config = [
'concrete' => [
ImplOne::class => [
'foo' => 'foo impl one', //parameters for ImplOne
],
],
'contract' => [
ContractOne::class => ImplOne::class,
],
];
$binder->bindAll($config);
Create dependencies by reflection
$config = [
'concrete' => [
ImplOne::class => [
'foo' => 'foo impl one',
],
ImplTwo::class => [
'foo' => 'foo impl two', //param one
'bar' => [ //param two (reflection)
'impl' => ImplBar::class,
'params' => [
'bar' => 'bar from impl bar in impl two',
],
],
],
],
'contract' => [
ContractOne::class => ImplTwo::class,
],
];
$binder->bindAll($config);
Create dependencies from container
$config = [
'concrete' => [
ImplBar::class => [
'bar' => 'bar from prebound impl bar in impl two',
],
ImplTwo::class => [
'foo' => 'foo impl two prebound', //param one
'bar' => [ //param two (container)
'bound' => ContractBar::class,
],
],
],
'contract' => [
ContractBar::class => ImplBar::class,
ContractOne::class => ImplTwo::class,
],
];
$binder->bindAll($config);
统计信息
- 总下载量: 5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 13
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-09