Skip to content
Snippets Groups Projects
Commit efb082f4 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Added timeout to options.

parent a34f5f6d
No related branches found
No related tags found
1 merge request!3Added timeout to options.
Pipeline #5106 passed
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
......@@ -34,4 +34,9 @@ interface ApiClientOptions extends HttpClientOptions, SerializerOptions
*/
public function getApiClientClass();
/**
* @return int
*/
public function getTimeout();
}
\ No newline at end of file
......@@ -24,7 +24,8 @@ class ClientFactory
$serializerFactory->createSerializer($options),
$options->getLogger(),
$options->getApiUrl(),
$options->getDefaultRequestHeaders()
$options->getDefaultRequestHeaders(),
$options->getTimeout()
);
if ($options->isCachedClient()) {
......
......@@ -16,8 +16,6 @@ class ClientImplementation implements Client, LoggerAwareInterface
{
const CLIENT_VERSION = '1.6.5';
const DEFAULT_TIMEOUT = 10;
const LIBRARY_LOGIN_CONTEXT = 'wp-api-client';
/** @var HttpClient */
......@@ -35,6 +33,9 @@ class ClientImplementation implements Client, LoggerAwareInterface
/** @var array */
private $defaultRequestHeaders;
/** @var int */
private $timeout;
/**
* Client constructor.
* @param HttpClient $client
......@@ -42,19 +43,22 @@ class ClientImplementation implements Client, LoggerAwareInterface
* @param LoggerInterface $logger
* @param string $apiUri
* @param array $defaultRequestHeaders
* @param int $timeout
*/
public function __construct(
HttpClient $client,
Serializer $serializer,
LoggerInterface $logger,
$apiUri,
array $defaultRequestHeaders
array $defaultRequestHeaders,
$timeout = 10
) {
$this->client = $client;
$this->serializer = $serializer;
$this->logger = $logger;
$this->apiUrl = $apiUri;
$this->defaultRequestHeaders = $defaultRequestHeaders;
$this->timeout = $timeout;
}
/**
......@@ -73,7 +77,8 @@ class ClientImplementation implements Client, LoggerAwareInterface
$fullUrl = $this->prepareFullUrl($request),
$method = $request->getMethod(),
$body = $this->prepareRequestBody($request),
$headers = $this->prepareRequestHeaders($request), self::DEFAULT_TIMEOUT
$headers = $this->prepareRequestHeaders($request),
$this->timeout
);
$this->logger->debug(
......
......@@ -43,6 +43,10 @@ class TestClientFactory extends \PHPUnit\Framework\TestCase
->withAnyArgs()
->andReturn($isCachedClient);
$options->shouldReceive('getTimeout')
->withAnyArgs()
->andReturn(30);
return $options;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment