Skip to content

Commit 9ddb443

Browse files
committed
Added get IP
1 parent b2cc29c commit 9ddb443

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/OpCacheGUI/Network/Request.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,14 @@ public function getUrl()
120120

121121
return $scheme . '://' . $this->serverVariables['HTTP_HOST'] . $this->serverVariables['REQUEST_URI'];
122122
}
123+
124+
/**
125+
* Gets the user's IP address
126+
*
127+
* @return string The IP of the user
128+
*/
129+
public function getIp()
130+
{
131+
return $this->serverVariables['REMOTE_ADDR'];
132+
}
123133
}

src/OpCacheGUI/Network/RequestData.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ public function post($name);
5858
* @return string The current URL
5959
*/
6060
public function getUrl();
61+
62+
/**
63+
* Gets the user's IP address
64+
*
65+
* @return string The IP of the user
66+
*/
67+
public function getIp();
6168
}

test/Unit/Network/RequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,15 @@ public function testGetUrlSslDisabledIIS()
147147

148148
$this->assertSame('http://foo.com/bar', $request->getUrl());
149149
}
150+
151+
/**
152+
* @covers OpCacheGUI\Network\Request::__construct
153+
* @covers OpCacheGUI\Network\Request::getIp
154+
*/
155+
public function testGetIp()
156+
{
157+
$request = new Request([], [], ['REQUEST_URI' => '/bar', 'REMOTE_ADDR' => '10.0.0.2']);
158+
159+
$this->assertSame('10.0.0.2', $request->getIp());
160+
}
150161
}

0 commit comments

Comments
 (0)