TimeoutAwarePsr18Adapter.php in Acquia Search 3.x
File
src/Client/Adapter/TimeoutAwarePsr18Adapter.php
View source
<?php
namespace Drupal\acquia_search\Client\Adapter;
use Http\Factory\Guzzle\RequestFactory;
use Http\Factory\Guzzle\StreamFactory;
use Psr\Http\Client\ClientInterface;
use Solarium\Core\Client\Adapter\AdapterInterface;
use Solarium\Core\Client\Adapter\Psr18Adapter;
use Solarium\Core\Client\Adapter\TimeoutAwareInterface;
use Solarium\Core\Client\Endpoint;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
class TimeoutAwarePsr18Adapter implements AdapterInterface, TimeoutAwareInterface {
protected $timeout;
protected $psr18Adapter;
public function __construct(ClientInterface $httpClient) {
$this->psr18Adapter = new Psr18Adapter($httpClient, new RequestFactory(), new StreamFactory());
}
public function getTimeout() : int {
return $this->timeout;
}
public function setTimeout(int $timeoutInSeconds) : void {
$this->timeout = $timeoutInSeconds;
}
public function execute(Request $request, Endpoint $endpoint) : Response {
$request
->setOptions([
'timeout' => $this->timeout,
]);
return $this->psr18Adapter
->execute($request, $endpoint);
}
}