Skip to content

Commit 96e65e7

Browse files
committed
Fix composer.json, check if Amazon SDK installed
1 parent 7a7ecf8 commit 96e65e7

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
"illuminate/database": "~4.2|^5",
2222
"illuminate/config": "~4.2|^5",
2323
"nesbot/carbon": "~1.0",
24-
"elasticsearch/elasticsearch": ">1.0 <2.2",
25-
"aws/aws-sdk-php": "^3.18"
24+
"elasticsearch/elasticsearch": ">1.0 <2.2"
2625
},
2726
"require-dev": {
2827
"phpunit/phpunit": "~4.2|~5.0",
2928
"mockery/mockery": "^0.9.4"
3029
},
30+
"suggest": {
31+
"aws/aws-sdk-php": "^3.19"
32+
},
3133
"autoload": {
3234
"psr-4": {
3335
"Elasticquent\\": "src/"

src/ElasticSearchClientFactory.php

+22-14
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
namespace Elasticquent;
44

5-
use Aws\Credentials\Credentials;
6-
use Aws\Signature\SignatureV4;
7-
use GuzzleHttp\Psr7\Request;
8-
use GuzzleHttp\Psr7\Uri;
9-
use GuzzleHttp\Ring\Future\CompletedFutureArray;
10-
use Psr\Http\Message\ResponseInterface;
11-
125
final class ElasticSearchClientFactory
136
{
147
use ElasticquentConfigTrait;
@@ -54,6 +47,21 @@ public function getClient()
5447
*/
5548
private function getAwsESHandler()
5649
{
50+
$classExistsChecks = [
51+
'\Aws\Credentials\Credentials',
52+
'\Aws\Signature\SignatureV4',
53+
'\GuzzleHttp\Psr7\Request',
54+
'\GuzzleHttp\Psr7\Uri',
55+
'\GuzzleHttp\Ring\Future\CompletedFutureArray',
56+
'\Psr\Http\Message\ResponseInterface',
57+
];
58+
59+
foreach ($classExistsChecks as $classExistsCheck) {
60+
if (!class_exists($classExistsCheck)) {
61+
return false;
62+
}
63+
}
64+
5765
$awsConfig = $this->getElasticConfig('aws');
5866
if (empty($awsConfig)) {
5967
return false;
@@ -64,7 +72,7 @@ private function getAwsESHandler()
6472
$region = array_get($awsConfig, 'region', 'us-west-2');
6573

6674
$psr7Handler = \Aws\default_http_handler();
67-
$signer = new SignatureV4('es', $region);
75+
$signer = new \Aws\Signature\SignatureV4('es', $region);
6876

6977
$handler = function (array $request) use (
7078
$psr7Handler,
@@ -75,22 +83,22 @@ private function getAwsESHandler()
7583
// Amazon ES listens on standard ports (443 for HTTPS, 80 for HTTP).
7684
$request['headers']['host'][0] = parse_url($request['headers']['host'][0], PHP_URL_HOST);
7785

78-
$credentials = new Credentials($key, $secret);
86+
$credentials = new \Aws\Credentials\Credentials($key, $secret);
7987

8088
// Create a PSR-7 request from the array passed to the handler
81-
$psr7Request = new Request($request['http_method'],
82-
(new Uri($request['uri']))->withScheme($request['scheme'])->withHost($request['headers']['host'][0]), $request['headers'],
83-
$request['body']);
89+
$psr7Request = new \GuzzleHttp\Psr7\Request($request['http_method'],
90+
(new \GuzzleHttp\Psr7\Uri($request['uri']))->withScheme($request['scheme'])->withHost($request['headers']['host'][0]),
91+
$request['headers'], $request['body']);
8492

8593
// Sign the PSR-7 request with credentials from the environment
8694
$signedRequest = $signer->signRequest($psr7Request, $credentials);
8795

8896
// Send the signed request to Amazon ES
89-
/** @var ResponseInterface $response */
97+
/** @var \Psr\Http\Message\ResponseInterface $response */
9098
$response = $psr7Handler($signedRequest)->wait();
9199

92100
// Convert the PSR-7 response to a RingPHP response
93-
return new CompletedFutureArray([
101+
return new \GuzzleHttp\Ring\Future\CompletedFutureArray([
94102
'status' => $response->getStatusCode(),
95103
'headers' => $response->getHeaders(),
96104
'body' => $response->getBody()->detach(),

0 commit comments

Comments
 (0)