Skip to content

Commit d2a08f4

Browse files
committed
use PSR-7 for Firewall middleware
1 parent 4cd4a5c commit d2a08f4

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

api.include.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7933,20 +7933,20 @@ private function isIpAllowed(string $ipAddress, string $allowedIpAddresses): boo
79337933
}
79347934

79357935
private function getIpAddress(ServerRequestInterface $request): string
7936-
{
7937-
$serverParams = $request->getServerParams();
7938-
return $serverParams['REMOTE_ADDR'] ?? '127.0.0.1';
7939-
}
7940-
7941-
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
79427936
{
79437937
$reverseProxy = $this->getProperty('reverseProxy', '');
7944-
$serverParams = $request->getServerParams();
79457938
if ($reverseProxy) {
79467939
$ipAddress = array_pop($request->getHeader('X-Forwarded-For'));
79477940
} else {
7948-
$ipAddress = $this->getIpAddress($request);
7941+
$serverParams = $request->getServerParams();
7942+
$ipAddress = $serverParams['REMOTE_ADDR'] ?? '127.0.0.1';
79497943
}
7944+
return $ipAddress;
7945+
}
7946+
7947+
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
7948+
{
7949+
$ipAddress = $this->getIpAddress($request);
79507950
$allowedIpAddresses = $this->getProperty('allowedIpAddresses', '');
79517951
if (!$this->isIpAllowed($ipAddress, $allowedIpAddresses)) {
79527952
$response = $this->responder->error(ErrorCode::TEMPORARY_OR_PERMANENTLY_BLOCKED, '');

api.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7933,20 +7933,20 @@ private function isIpAllowed(string $ipAddress, string $allowedIpAddresses): boo
79337933
}
79347934

79357935
private function getIpAddress(ServerRequestInterface $request): string
7936-
{
7937-
$serverParams = $request->getServerParams();
7938-
return $serverParams['REMOTE_ADDR'] ?? '127.0.0.1';
7939-
}
7940-
7941-
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
79427936
{
79437937
$reverseProxy = $this->getProperty('reverseProxy', '');
7944-
$serverParams = $request->getServerParams();
79457938
if ($reverseProxy) {
79467939
$ipAddress = array_pop($request->getHeader('X-Forwarded-For'));
79477940
} else {
7948-
$ipAddress = $this->getIpAddress($request);
7941+
$serverParams = $request->getServerParams();
7942+
$ipAddress = $serverParams['REMOTE_ADDR'] ?? '127.0.0.1';
79497943
}
7944+
return $ipAddress;
7945+
}
7946+
7947+
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
7948+
{
7949+
$ipAddress = $this->getIpAddress($request);
79507950
$allowedIpAddresses = $this->getProperty('allowedIpAddresses', '');
79517951
if (!$this->isIpAllowed($ipAddress, $allowedIpAddresses)) {
79527952
$response = $this->responder->error(ErrorCode::TEMPORARY_OR_PERMANENTLY_BLOCKED, '');

src/Tqdev/PhpCrudApi/Middleware/FirewallMiddleware.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ private function isIpAllowed(string $ipAddress, string $allowedIpAddresses): boo
3737
}
3838

3939
private function getIpAddress(ServerRequestInterface $request): string
40-
{
41-
$serverParams = $request->getServerParams();
42-
return $serverParams['REMOTE_ADDR'] ?? '127.0.0.1';
43-
}
44-
45-
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
4640
{
4741
$reverseProxy = $this->getProperty('reverseProxy', '');
48-
$serverParams = $request->getServerParams();
4942
if ($reverseProxy) {
5043
$ipAddress = array_pop($request->getHeader('X-Forwarded-For'));
5144
} else {
52-
$ipAddress = $this->getIpAddress($request);
45+
$serverParams = $request->getServerParams();
46+
$ipAddress = $serverParams['REMOTE_ADDR'] ?? '127.0.0.1';
5347
}
48+
return $ipAddress;
49+
}
50+
51+
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
52+
{
53+
$ipAddress = $this->getIpAddress($request);
5454
$allowedIpAddresses = $this->getProperty('allowedIpAddresses', '');
5555
if (!$this->isIpAllowed($ipAddress, $allowedIpAddresses)) {
5656
$response = $this->responder->error(ErrorCode::TEMPORARY_OR_PERMANENTLY_BLOCKED, '');

0 commit comments

Comments
 (0)