MaintenanceModeRequestEvent example

use Symfony\Component\HttpFoundation\Request;

/** * @internal * * @covers \Shopware\Core\Framework\Routing\Event\MaintenanceModeRequestEvent */
class MaintenanceModeRequestEventTest extends TestCase
{
    public function testIsClientAllowed(): void
    {
        $event = new MaintenanceModeRequestEvent(
            new Request(),
            [],
            true
        );

        static::assertTrue($event->isClientAllowed());

        $event->disallowClient();

        static::assertFalse($event->isClientAllowed());

        
/** * @param string[] $allowedIps */
    public function isClientAllowed(Request $request, array $allowedIps): bool
    {
        $isAllowed = IpUtils::checkIp(
            (string) $request->getClientIp(),
            $allowedIps
        );

        $event = new MaintenanceModeRequestEvent($request$allowedIps$isAllowed);

        $this->eventDispatcher->dispatch($event);

        return $event->isClientAllowed();
    }
}
Home | Imprint | This part of the site doesn't use cookies.