1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace Aws\CloudSearchDomain;
- use Aws\AwsClient;
- use Aws\CommandInterface;
- use Aws\HandlerList;
- use GuzzleHttp\Psr7\Uri;
- use Psr\Http\Message\RequestInterface;
- use GuzzleHttp\Psr7;
- 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) {
-
-
- return explode('.', new Uri($args['endpoint']))[1];
- };
- unset($args['endpoint']['default']);
- return $args;
- }
-
- 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($c, self::convertGetToPost($r));
- };
- };
- }
-
- public static function convertGetToPost(RequestInterface $r)
- {
- if ($r->getMethod() === 'POST') {
- return $r;
- }
- $query = $r->getUri()->getQuery();
- $req = $r->withMethod('POST')
- ->withBody(Psr7\Utils::streamFor($query))
- ->withHeader('Content-Length', strlen($query))
- ->withHeader('Content-Type', 'application/x-www-form-urlencoded')
- ->withUri($r->getUri()->withQuery(''));
- return $req;
- }
- }
|