52 lines
1.7 KiB
PHP
52 lines
1.7 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\Services\BasketService;
|
|
use Illuminate\Contracts\Session\Session;
|
|
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\SessionOrderBuilderManager;
|
|
|
|
class ShoppingServiceProvider extends ServiceProvider
|
|
{
|
|
private const string BASKET_SESSION_KEY_PREFIX = 'basket_';
|
|
|
|
private const string ORDER_BUILDER_SESSION_KEY = 'order_tunnel_builder_session';
|
|
|
|
/**
|
|
* Bootstrap the application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
App::singleton(SessionService::class, fn () => new AppSessionService('domain_session_uuid'));
|
|
|
|
App::singleton(BasketRepository::class, fn () => new SessionBasketRepository(
|
|
resolve(Session::class),
|
|
self::BASKET_SESSION_KEY_PREFIX,
|
|
resolve(BasketSerializer::class)
|
|
));
|
|
|
|
App::singleton(BasketService::class, fn () => new BasketService(
|
|
resolve(BasketRepository::class),
|
|
resolve(ProductRepository::class),
|
|
resolve(SessionService::class)
|
|
));
|
|
|
|
App::singleton(OrderBuilderSessionManager::class, fn () => new SessionOrderBuilderManager(
|
|
resolve(Session::class),
|
|
self::ORDER_BUILDER_SESSION_KEY
|
|
));
|
|
}
|
|
}
|