50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?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);
|
|
});
|
|
}
|
|
}
|