Skip to content

Commit 2619e14

Browse files
author
İsmail BASKIN
committed
Add hostname property to Response
1 parent f3390c3 commit 2619e14

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/ReCaptcha/Response.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class Response
4343
*/
4444
private $errorCodes = array();
4545

46+
/**
47+
* the hostname of the site where the reCAPTCHA was solved
48+
* @var string
49+
*/
50+
private $hostName = '';
51+
4652
/**
4753
* Build the response from the expected JSON returned by the service.
4854
*
@@ -58,7 +64,7 @@ public static function fromJson($json)
5864
}
5965

6066
if (isset($responseData['success']) && $responseData['success'] == true) {
61-
return new Response(true);
67+
return new Response(true, [], isset($responseData['hostname']) ? $responseData['hostname'] : '');
6268
}
6369

6470
if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
@@ -73,11 +79,13 @@ public static function fromJson($json)
7379
*
7480
* @param boolean $success
7581
* @param array $errorCodes
82+
* @param string $hostname
7683
*/
77-
public function __construct($success, array $errorCodes = array())
84+
public function __construct($success, array $errorCodes = array(), $hostname = '')
7885
{
7986
$this->success = $success;
8087
$this->errorCodes = $errorCodes;
88+
$this->hostName = $hostname;
8189
}
8290

8391
/**
@@ -99,4 +107,12 @@ public function getErrorCodes()
99107
{
100108
return $this->errorCodes;
101109
}
110+
111+
/**
112+
* @return string
113+
*/
114+
public function getHostName()
115+
{
116+
return $this->hostName;
117+
}
102118
}

tests/ReCaptcha/ResponseTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public function testIsSuccess()
5757

5858
$response = new Response(false);
5959
$this->assertFalse($response->isSuccess());
60+
61+
$response = new Response(true, [], 'example.com');
62+
$this->assertEquals('example.com', $response->getHostName());
6063
}
6164

6265
public function testGetErrorCodes()

0 commit comments

Comments
 (0)