smorken / support
Support classes for Laravel
Requires
- php: ^8.1
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- illuminate/routing: ^9.0|^10.0|^11.0
- laravel/framework: ^9.0|^10.0|^11.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^1.11.10
- phpunit/phpunit: ^10.0|^11.0
- smorken/docker: *
This package is auto-updated.
Last update: 2024-12-08 20:31:03 UTC
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);