-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hCaptcha API Client package. | ||
* | ||
* (c) Wider Plan <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WiderPlan\Hcaptcha; | ||
|
||
use GuzzleHttp\Client as Guzzle; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Promise\Create; | ||
use Http\Discovery\Psr18Client; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
return function (string $secretKey, \Closure $responseFactory): Client { | ||
$handler = function (RequestInterface $request) use ($responseFactory) { | ||
$response = $responseFactory( | ||
$request->getMethod(), | ||
(string) $request->getUri(), | ||
(string) $request->getBody(), | ||
); | ||
|
||
return Create::promiseFor($response); | ||
}; | ||
|
||
return Client::create( | ||
$secretKey, | ||
new Psr18Client(new Guzzle(['handler' => HandlerStack::create($handler)])), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hCaptcha API Client package. | ||
* | ||
* (c) Wider Plan <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WiderPlan\Hcaptcha; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Component\HttpClient\MockHttpClient; | ||
use Symfony\Component\HttpClient\Psr18Client; | ||
use Symfony\Component\HttpClient\Response\MockResponse; | ||
|
||
return function (string $secretKey, \Closure $responseFactory): Client { | ||
$httpClient = new MockHttpClient(function (string $method, string $uri, array $options) use ($responseFactory) { | ||
$response = $responseFactory($method, $uri, $options['body']); | ||
\assert($response instanceof ResponseInterface); | ||
|
||
$headers = []; | ||
|
||
foreach ($response->getHeaders() as $name => $values) { | ||
foreach ($values as $value) { | ||
$headers[] = sprintf('%s: %s', $name, $value); | ||
} | ||
} | ||
|
||
return new MockResponse((string) $response->getBody(), [ | ||
'http_code' => $response->getStatusCode(), | ||
'response_headers' => $headers, | ||
]); | ||
}); | ||
|
||
return Client::create($secretKey, new Psr18Client($httpClient)); | ||
}; |