22
33namespace  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- 
125final  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  ($ classExistsChecksas  $ 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        $ regionarray_get ($ awsConfig'region ' , 'us-west-2 ' );
6573
6674        $ psr7Handler\Aws \default_http_handler ();
67-         $ signernew  SignatureV4 ('es ' , $ region
75+         $ signernew  \ Aws \ Signature \ SignatureV4 ('es ' , $ region
6876
6977        $ handlerfunction  (array  $ requestuse  (
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-             $ credentialsnew  Credentials ($ key$ secret
86+             $ credentialsnew  \ Aws \ Credentials \ Credentials ($ key$ secret
7987
8088            // Create a PSR-7 request from the array passed to the handler 
81-             $ psr7Requestnew  Request ($ request'http_method ' ],
82-                 (new  Uri ($ request'uri ' ]))->withScheme ($ request'scheme ' ])->withHost ($ request'headers ' ]['host ' ][0 ]),  $ request [ ' headers ' ] ,
83-                 $ request'body ' ]);
89+             $ psr7Requestnew  \ 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$ signersignRequest ($ 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$ signedRequestwait ();
9199
92100            // Convert the PSR-7 response to a RingPHP response 
93-             return  new  CompletedFutureArray ([
101+             return  new  \ GuzzleHttp \ Ring \ Future \ CompletedFutureArray ([
94102                'status '          => $ responsegetStatusCode (),
95103                'headers '         => $ responsegetHeaders (),
96104                'body '            => $ responsegetBody ()->detach (),
0 commit comments