Вход Регистрация
Файл: sngine-v2.8/Script/includes/libs/AWS/Aws/CloudSearchDomain/CloudSearchDomainClient.php
Строк: 98
<?php
namespace AwsCloudSearchDomain;

use 
AwsAwsClient;
use 
AwsCommandInterface;
use 
GuzzleHttpPsr7Uri;
use 
PsrHttpMessageRequestInterface;
use 
GuzzleHttpPsr7;

/**
 * This client is used to search and upload documents to an **Amazon CloudSearch** Domain.
 *
 * @method AwsResult search(array $args = [])
 * @method GuzzleHttpPromisePromise searchAsync(array $args = [])
 * @method AwsResult suggest(array $args = [])
 * @method GuzzleHttpPromisePromise suggestAsync(array $args = [])
 * @method AwsResult uploadDocuments(array $args = [])
 * @method GuzzleHttpPromisePromise uploadDocumentsAsync(array $args = [])
 */
class CloudSearchDomainClient extends AwsClient
{
    public function 
__construct(array $args)
    {
        
parent::__construct($args);
        
$list $this->getHandlerList();
        
$list->appendBuild($this->searchByPost(), 'cloudsearchdomain.search_by_POST');
    }

    public static function 
getArguments()
    {
        
$args parent::getArguments();
        
$args['endpoint']['required'] = true;
        
$args['region']['default'] = function (array $args) {
            
// Determine the region from the provided endpoint.
            // (e.g. http://search-blah.{region}.cloudsearch.amazonaws.com)
            
return explode('.', new Uri($args['endpoint']))[1];
        };

        return 
$args;
    }

    
/**
     * Use POST for search command
     *
     * Useful when query string is too long
     */
    
private function searchByPost()
    {
        return static function (callable 
$handler) {
            return function (
                
CommandInterface $c,
                
RequestInterface $r null
            
) use ($handler) {
                if (
$c->getName() !== 'Search') {
                    return 
$handler($c$r);
                }
                return 
$handler($cself::convertGetToPost($r));
            };
        };
    }

    
/**
     * Converts default GET request to a POST request
     *
     * Avoiding length restriction in query
     *
     * @param RequestInterface $r GET request to be converted
     * @return RequestInterface $req converted POST request
     */
    
public static function convertGetToPost(RequestInterface $r)
    {
        if (
$r->getMethod() === 'POST') {
            return 
$r;
        }

        
$query $r->getUri()->getQuery();
        
$req $r->withMethod('POST')
            ->
withBody(Psr7stream_for($query))
            ->
withHeader('Content-Length'strlen($query))
            ->
withHeader('Content-Type''application/x-www-form-urlencoded')
            ->
withUri($r->getUri()->withQuery(''));
        return 
$req;
    }
}
Онлайн: 1
Реклама