<?php declare(strict_types=1);
/**
* valantic CEC Deutschland GmbH
* Copyright (c) 2022.
*
* All rights reserved.
*
* @see https://www.valantic.com/
*
* @author andrei
* Date: 17.10.2022 16:43
*/
namespace Valantic\Bundle\PentagastBundle\Service;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class UserRegistrationGuard extends ShopFeatureGuardBase
{
public const USER_REGISTRATION_ROUTES = [
'frontend.account.register.page', // GET /account/register
'frontend.account.register.save', // POST /account/register
'store-api.account.register', // POST /store-api/account/register
'store-api.account.register.confirm', // POST /store-api/account/register-confirm
//'frontend.checkout.register.page', // GET /checkout/register
'frontend.account.register.mail', // GET /registration/confirm
'store-api.account.register.confirm', // POST /store-api/account/register-confirm
];
/**
* @throws NotFoundHttpException
*/
public function validate(Request $request): void
{
$route = $request->attributes->get('_route');
$salesChannelContext = $this->getSalesChannelContext($request);
if ($route && $salesChannelContext && !$this->shopFeaturesService->registrationEnabled($salesChannelContext)) {
if (\in_array($route, self::USER_REGISTRATION_ROUTES, true) && !$this->shopFeaturesService->loginEnabled($salesChannelContext)) {
throw new NotFoundHttpException();
}
}
}
}