Skip to content

Commit ff37359

Browse files
Anton EversAnton Evers
authored andcommitted
Create a facade for Symfony's IpUtils' checkIp method
1 parent e8e4a93 commit ff37359

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/internal/Magento/Framework/App/MaintenanceMode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\Filesystem;
10-
use Symfony\Component\HttpFoundation\IpUtils;
10+
use Magento\Framework\HTTP\IpChecker;
1111

1212
/**
1313
* Application Maintenance Mode
@@ -62,7 +62,7 @@ public function isOn($remoteAddr = '')
6262
if (!$this->flagDir->isExist(self::FLAG_FILENAME)) {
6363
return false;
6464
}
65-
return !IpUtils::checkIp($remoteAddr, $this->getAddressInfo());
65+
return !IpChecker::isInRange($remoteAddr, $this->getAddressInfo());
6666
}
6767

6868
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\HTTP;
7+
8+
use Symfony\Component\HttpFoundation\IpUtils;
9+
10+
class IpChecker
11+
{
12+
/**
13+
* Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.
14+
*
15+
* @param string $requestIp IP to check
16+
* @param string|array $ips List of IPs or subnets (can be a string if only a single one)
17+
*
18+
* @return bool Whether the IP is contained in the list of given IPs or subnets
19+
*/
20+
public static function isInRange($requestIp, $ips)
21+
{
22+
return IpUtils::checkIp($requestIp, $ips);
23+
}
24+
}

0 commit comments

Comments
 (0)