first commit
This commit is contained in:
49
laravel/app/Providers/AppServiceProvider.php
Normal file
49
laravel/app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Contracts\WbClientInterface;
|
||||
use App\Contracts\WbSyncFactoryInterface;
|
||||
use App\Contracts\WbSyncManagerInterface;
|
||||
use App\Services\WbService\WbClient;
|
||||
use App\Services\WbService\WbSyncFactory;
|
||||
use App\Services\WbService\WbSyncManager;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->registerSyncServices();
|
||||
$this->app->bind(WbSyncManagerInterface::class, WbSyncManager::class);
|
||||
$this->app->bind(WbClientInterface::class, WbClient::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
private function registerSyncServices(): void
|
||||
{
|
||||
$syncServices = config('wb-sync.services');
|
||||
|
||||
foreach ($syncServices as $serviceClass) {
|
||||
$this->app->singleton($serviceClass);
|
||||
}
|
||||
|
||||
$this->app->singleton(WbSyncFactoryInterface::class, function ($app) use ($syncServices) {
|
||||
$services = array_map(function ($serviceClass) use ($app) {
|
||||
return $app->make($serviceClass);
|
||||
}, $syncServices);
|
||||
|
||||
return new WbSyncFactory($services);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user