59 lines
2.2 KiB
PHP
59 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Acme\Dhl;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class DhlServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/dhl.php', 'dhl');
|
|
|
|
// Bind DhlClient as a singleton
|
|
$this->app->singleton(Support\DhlClient::class, function ($app) {
|
|
// Check if we're in test/sandbox mode
|
|
$isTestMode = config('dhl.legacy.test_mode', false) || config('dhl.legacy.sandbox', false);
|
|
$baseUrl = $isTestMode ? config('dhl.sandbox_url') : config('dhl.base_url');
|
|
|
|
return new Support\DhlClient(
|
|
$baseUrl,
|
|
config('dhl.api_key'),
|
|
config('dhl.username'),
|
|
config('dhl.password')
|
|
);
|
|
});
|
|
|
|
// Bind services as singletons
|
|
$this->app->singleton(Services\ShippingService::class, function ($app) {
|
|
return new Services\ShippingService($app->make(Support\DhlClient::class));
|
|
});
|
|
|
|
$this->app->singleton(Services\TrackingService::class, function ($app) {
|
|
return new Services\TrackingService($app->make(Support\DhlClient::class));
|
|
});
|
|
|
|
$this->app->singleton(Services\ReturnsService::class, function ($app) {
|
|
return new Services\ReturnsService($app->make(Support\DhlClient::class));
|
|
});
|
|
|
|
// Bind the main manager class
|
|
$this->app->singleton(DhlManager::class, function ($app) {
|
|
return new DhlManager(
|
|
$app->make(Support\DhlClient::class),
|
|
$app->make(Services\ShippingService::class),
|
|
$app->make(Services\TrackingService::class),
|
|
$app->make(Services\ReturnsService::class)
|
|
);
|
|
});
|
|
}
|
|
public function boot(): void
|
|
{
|
|
$this->publishes([__DIR__ . '/../config/dhl.php' => config_path('dhl.php')], 'dhl-config');
|
|
$this->publishes([__DIR__ . '/../database/migrations/' => database_path('migrations')], 'dhl-migrations');
|
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
|
|
if (config('dhl.webhook.enabled')) {
|
|
$this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
|
|
}
|
|
}
|
|
}
|