76 lines
2.5 KiB
PHP
76 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use Domain\Ports\Repositories\BasketRepository;
|
|
use Domain\Ports\Repositories\ProductRepository;
|
|
use Domain\Ports\Services\OrderBuilderSessionManager;
|
|
use Domain\Ports\Services\SessionService;
|
|
use Domain\Ports\Services\TunnelAttemptTrackerService;
|
|
use Domain\Services\BasketService;
|
|
use Illuminate\Contracts\Session\Session;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Infrastructure\Adapters\Repositories\SessionBasketRepository;
|
|
use Infrastructure\Adapters\Serializers\BasketSerializer;
|
|
use Infrastructure\Adapters\Services\AppSessionService;
|
|
use Infrastructure\Adapters\Services\DatabaseTunnelAttemptTrackerService;
|
|
use Infrastructure\Adapters\Services\SessionOrderBuilderManager;
|
|
use Shared\DDD\DomainEventDispatcher;
|
|
|
|
class ShoppingServiceProvider extends ServiceProvider
|
|
{
|
|
private const string BASKET_SESSION_KEY_PREFIX = 'basket_';
|
|
|
|
private const string ORDER_BUILDER_SESSION_KEY = 'order_tunnel_builder_session';
|
|
|
|
private const string ORDER_TUNNEL_ATTEMPT_SESSION_KEY = 'order_tunnel_attempt_id';
|
|
|
|
/**
|
|
* Bootstrap the application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
App::singleton(
|
|
SessionService::class,
|
|
fn () => new AppSessionService('domain_session_uuid')
|
|
);
|
|
|
|
App::scoped(
|
|
BasketRepository::class,
|
|
fn (Application $app) => new SessionBasketRepository(
|
|
$app->make(Session::class),
|
|
self::BASKET_SESSION_KEY_PREFIX,
|
|
$app->make(BasketSerializer::class)
|
|
)
|
|
);
|
|
|
|
App::scoped(
|
|
OrderBuilderSessionManager::class,
|
|
fn (Application $app) => new SessionOrderBuilderManager(
|
|
$app->make(Session::class),
|
|
self::ORDER_BUILDER_SESSION_KEY
|
|
)
|
|
);
|
|
|
|
App::scoped(
|
|
TunnelAttemptTrackerService::class,
|
|
fn (Application $app) => new DatabaseTunnelAttemptTrackerService(
|
|
$app->make(Session::class),
|
|
self::ORDER_TUNNEL_ATTEMPT_SESSION_KEY
|
|
)
|
|
);
|
|
|
|
App::scoped(BasketService::class, fn (Application $app) => new BasketService(
|
|
$app->make(BasketRepository::class),
|
|
$app->make(ProductRepository::class),
|
|
$app->make(SessionService::class),
|
|
$app->make(DomainEventDispatcher::class)
|
|
));
|
|
}
|
|
}
|