Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-09-25 (16 days ago) | Not enough user ratings | Total: 8 | All time: 11,435 This week: 44 |
Version | License | PHP version | Categories | |||
laravel-rapid-bind 1.0 | The PHP License | 8.1 | Libraries, Language, Design Patterns, P... |
Description | Author | |||
This package can create singletons to implement interfaces. Innovation Award
|
<p align="center">
<img style='height: 350px' src='https://github.com/DeGraciaMathieu/laravel-rapid-bind/assets/11473997/17e2a556-e081-4889-8ae4-30f074e41686'>
</p>
In an architecture based on ports and adapters, we create many bindings between interfaces and implementations.
Often, these bindings are simple and require no additional configuration.
This package facilitates the creation of these bindings, helping you avoid cluttering your AppServiceProvider
.
Requires >= PHP 8.1
composer require degraciamathieu/laravel-rapid-bind
Provide information on the folders containing the interfaces :
<?php
namespace App\Providers;
class AppServiceProvider extends ServiceProvider
{
/
* Register any application services.
*/
public function register(): void
{
RapidBind::bind([
'../app/Domain/Ports/Repositories',
]);
}
/
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}
Now, add the Bind annotation on the port with the value of the FQCN of the associated adapter :
<?php
namespace App\Domain\Ports\Repositories;
use DeGraciaMathieu\RapidBind\Bind;
use App\Infrastructure\Repositories\UserRepositoryAdapter;
#[Bind(UserRepositoryAdapter::class)]
interface UserRepository
{
//
}
<?php
namespace App\Infrastructure\Repositories;
use App\Domain\Ports\Repositories\UserRepository;
class UserRepositoryAdapter implements UserRepository
{
//
}
From now on, a singleton has been automatically created between the port and the adapter !
$userRepository = app(UserRepository::class);
dd($userRepository); // App\Infrastructure\Repositories\UserRepositoryAdapter
Files (14) |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (2 files, 1 directory) | ||||
tests (1 directory) | ||||
.phpunit.result.cache | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
phpunit.xml.dist | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
testbench.yaml | Data | Auxiliary data |
Files (14) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Facades (1 file) | ||||
Bind.php | Class | Class source | ||
RapidBind.php | Class | Class source |
Files (14) | / | tests | / | Unit |
File | Role | Description | ||
---|---|---|---|---|
Stubs (3 directories) | ||||
RapidBindTest.php | Class | Class source |
Files (14) | / | tests | / | Unit | / | Stubs |
Files (14) | / | tests | / | Unit | / | Stubs | / | Adapters |
File | Role | Description |
---|---|---|
FooAdapter.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.