ldc-boutique-cnc-sable/app/Http/Middleware/CustomerIsEmployed.php
2026-10-27 09:58:12 +01:00

38 lines
1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Exceptions\CustomerNotEmployedException;
use Closure;
use Domain\Services\ShopperService;
use Infrastructure\Adapters\Services\AppCustomerAuthService;
use Symfony\Component\HttpFoundation\Response;
class CustomerIsEmployed
{
public function __construct(
private readonly AppCustomerAuthService $authService,
private readonly ShopperService $shopperService
) {
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request):(\Illuminate\Http\Response) $next
*/
public function handle($request, Closure $next): Response
{
$customer = $this->authService->getCustomerAsMandatory();
$shopper = $this->shopperService->getShopperFor($customer->getId());
if (! $shopper || ! $shopper->isActive()) {
throw new CustomerNotEmployedException();
}
return $next($request);
}
}