smorken / support
Support classes for Laravel
Requires
- php: ^8.1
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- illuminate/routing: ^9.0|^10.0|^11.0|^12.0
- laravel/framework: ^9.0|^10.0|^11.0|^12.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^1.11.10|^2.1.13
- phpunit/phpunit: ^10.0|^11.0
- smorken/docker: *
- dev-master / 10.x-dev
- v10.4.1
- v10.4.0
- v10.3.0
- v10.2.1
- v10.2.0
- v10.1.1
- v10.1.0
- v10.0.3
- v10.0.2
- v10.0.1
- v10.0.0
- 9.x-dev
- v9.0.10
- v9.0.9
- v9.0.8
- v9.0.7
- v9.0.6
- v9.0.5
- v9.0.4
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0
- 8.x-dev
- v8.1.1
- v8.1
- v8.0
- 6.x-dev
- v6.3
- v6.2
- v6.1
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
This package is auto-updated.
Last update: 2025-05-02 13:35:53 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);