smorken / support
Support classes for Laravel
Requires
- php: ^8.3
- illuminate/support: ^12.0|^13.0
Requires (Dev)
- illuminate/routing: ^12.0|^13.0
- laravel/framework: ^12.0|^13.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^2.1.13
- phpunit/phpunit: ^11.0|^12.0
- smorken/docker: *
This package is auto-updated.
Last update: 2026-06-07 16:59:18 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);