[PHP] Fix #6770: Debug flag is not passed (#6808)

* Add testcase which reproduces issue #6770

* Pass debug option if needed

* Update samples

* bin/php-petstore.sh
* bin/security/php-petstore.sh

* Api throws exception when failed to open debug file

* Pass debug option if needed (Async)

* Extract instance method

* Update samples

* bin/php-petstore.sh
* bin/security/php-petstore.sh
This commit is contained in:
Akihito Nakano 2017-11-02 18:14:00 +09:00 committed by wing328
parent 81d6b18cf7
commit e8635632a4
9 changed files with 277 additions and 99 deletions

View File

@ -23,6 +23,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use {{invokerPackage}}\ApiException;
use {{invokerPackage}}\Configuration;
use {{invokerPackage}}\HeaderSelector;
@ -122,9 +123,9 @@ use {{invokerPackage}}\ObjectSerializer;
$request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -236,7 +237,7 @@ use {{invokerPackage}}\ObjectSerializer;
$request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
{{#returnType}}
@ -487,5 +488,23 @@ use {{invokerPackage}}\ObjectSerializer;
}
{{/operation}}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}
{{/operations}}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -113,9 +114,9 @@ class FakeApi
$request = $this->testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -184,7 +185,7 @@ class FakeApi
$request = $this->testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n_r);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -294,4 +295,22 @@ class FakeApi
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -114,9 +115,9 @@ class AnotherFakeApi
$request = $this->testSpecialTagsRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -207,7 +208,7 @@ class AnotherFakeApi
$request = $this->testSpecialTagsRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -336,4 +337,22 @@ class AnotherFakeApi
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -110,9 +111,9 @@ class FakeApi
$request = $this->fakeOuterBooleanSerializeRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -203,7 +204,7 @@ class FakeApi
$request = $this->fakeOuterBooleanSerializeRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -356,9 +357,9 @@ class FakeApi
$request = $this->fakeOuterCompositeSerializeRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -449,7 +450,7 @@ class FakeApi
$request = $this->fakeOuterCompositeSerializeRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -602,9 +603,9 @@ class FakeApi
$request = $this->fakeOuterNumberSerializeRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -695,7 +696,7 @@ class FakeApi
$request = $this->fakeOuterNumberSerializeRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -848,9 +849,9 @@ class FakeApi
$request = $this->fakeOuterStringSerializeRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -941,7 +942,7 @@ class FakeApi
$request = $this->fakeOuterStringSerializeRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1098,9 +1099,9 @@ class FakeApi
$request = $this->testClientModelRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1191,7 +1192,7 @@ class FakeApi
$request = $this->testClientModelRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1379,9 +1380,9 @@ class FakeApi
$request = $this->testEndpointParametersRequest($number, $double, $pattern_without_delimiter, $byte, $integer, $int32, $int64, $float, $string, $binary, $date, $date_time, $password, $callback);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1476,7 +1477,7 @@ class FakeApi
$request = $this->testEndpointParametersRequest($number, $double, $pattern_without_delimiter, $byte, $integer, $int32, $int64, $float, $string, $binary, $date, $date_time, $password, $callback);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -1773,9 +1774,9 @@ class FakeApi
$request = $this->testEnumParametersRequest($enum_form_string_array, $enum_form_string, $enum_header_string_array, $enum_header_string, $enum_query_string_array, $enum_query_string, $enum_query_integer, $enum_query_double);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1858,7 +1859,7 @@ class FakeApi
$request = $this->testEnumParametersRequest($enum_form_string_array, $enum_form_string, $enum_header_string_array, $enum_header_string, $enum_query_string_array, $enum_query_string, $enum_query_integer, $enum_query_double);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -2042,9 +2043,9 @@ class FakeApi
$request = $this->testInlineAdditionalPropertiesRequest($param);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -2113,7 +2114,7 @@ class FakeApi
$request = $this->testInlineAdditionalPropertiesRequest($param);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -2263,9 +2264,9 @@ class FakeApi
$request = $this->testJsonFormDataRequest($param, $param2);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -2336,7 +2337,7 @@ class FakeApi
$request = $this->testJsonFormDataRequest($param, $param2);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -2463,4 +2464,22 @@ class FakeApi
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -114,9 +115,9 @@ class FakeClassnameTags123Api
$request = $this->testClassnameRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -207,7 +208,7 @@ class FakeClassnameTags123Api
$request = $this->testClassnameRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -341,4 +342,22 @@ class FakeClassnameTags123Api
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -113,9 +114,9 @@ class PetApi
$request = $this->addPetRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -184,7 +185,7 @@ class PetApi
$request = $this->addPetRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -338,9 +339,9 @@ class PetApi
$request = $this->deletePetRequest($pet_id, $api_key);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -411,7 +412,7 @@ class PetApi
$request = $this->deletePetRequest($pet_id, $api_key);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -574,9 +575,9 @@ class PetApi
$request = $this->findPetsByStatusRequest($status);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -667,7 +668,7 @@ class PetApi
$request = $this->findPetsByStatusRequest($status);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -838,9 +839,9 @@ class PetApi
$request = $this->findPetsByTagsRequest($tags);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -931,7 +932,7 @@ class PetApi
$request = $this->findPetsByTagsRequest($tags);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1102,9 +1103,9 @@ class PetApi
$request = $this->getPetByIdRequest($pet_id);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1195,7 +1196,7 @@ class PetApi
$request = $this->getPetByIdRequest($pet_id);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1367,9 +1368,9 @@ class PetApi
$request = $this->updatePetRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1438,7 +1439,7 @@ class PetApi
$request = $this->updatePetRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -1594,9 +1595,9 @@ class PetApi
$request = $this->updatePetWithFormRequest($pet_id, $name, $status);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1669,7 +1670,7 @@ class PetApi
$request = $this->updatePetWithFormRequest($pet_id, $name, $status);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -1841,9 +1842,9 @@ class PetApi
$request = $this->uploadFileRequest($pet_id, $additional_metadata, $file);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1938,7 +1939,7 @@ class PetApi
$request = $this->uploadFileRequest($pet_id, $additional_metadata, $file);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -2087,4 +2088,22 @@ class PetApi
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -113,9 +114,9 @@ class StoreApi
$request = $this->deleteOrderRequest($order_id);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -184,7 +185,7 @@ class StoreApi
$request = $this->deleteOrderRequest($order_id);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -336,9 +337,9 @@ class StoreApi
$request = $this->getInventoryRequest();
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -427,7 +428,7 @@ class StoreApi
$request = $this->getInventoryRequest();
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -585,9 +586,9 @@ class StoreApi
$request = $this->getOrderByIdRequest($order_id);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -678,7 +679,7 @@ class StoreApi
$request = $this->getOrderByIdRequest($order_id);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -853,9 +854,9 @@ class StoreApi
$request = $this->placeOrderRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -946,7 +947,7 @@ class StoreApi
$request = $this->placeOrderRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1075,4 +1076,22 @@ class StoreApi
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -32,6 +32,7 @@ use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use Swagger\Client\ApiException;
use Swagger\Client\Configuration;
use Swagger\Client\HeaderSelector;
@ -113,9 +114,9 @@ class UserApi
$request = $this->createUserRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -184,7 +185,7 @@ class UserApi
$request = $this->createUserRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -332,9 +333,9 @@ class UserApi
$request = $this->createUsersWithArrayInputRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -403,7 +404,7 @@ class UserApi
$request = $this->createUsersWithArrayInputRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -551,9 +552,9 @@ class UserApi
$request = $this->createUsersWithListInputRequest($body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -622,7 +623,7 @@ class UserApi
$request = $this->createUsersWithListInputRequest($body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -770,9 +771,9 @@ class UserApi
$request = $this->deleteUserRequest($username);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -841,7 +842,7 @@ class UserApi
$request = $this->deleteUserRequest($username);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -995,9 +996,9 @@ class UserApi
$request = $this->getUserByNameRequest($username);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1088,7 +1089,7 @@ class UserApi
$request = $this->getUserByNameRequest($username);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1258,9 +1259,9 @@ class UserApi
$request = $this->loginUserRequest($username, $password);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1353,7 +1354,7 @@ class UserApi
$request = $this->loginUserRequest($username, $password);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
$responseBody = $response->getBody();
@ -1525,9 +1526,9 @@ class UserApi
$request = $this->logoutUserRequest();
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1594,7 +1595,7 @@ class UserApi
$request = $this->logoutUserRequest();
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -1734,9 +1735,9 @@ class UserApi
$request = $this->updateUserRequest($username, $body);
try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request);
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
@ -1807,7 +1808,7 @@ class UserApi
$request = $this->updateUserRequest($username, $body);
return $this->client
->sendAsync($request)
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
return [null, $response->getStatusCode(), $response->getHeaders()];
@ -1937,4 +1938,22 @@ class UserApi
);
}
/**
* Create http client option
*
* @throws \RuntimeException on file opening failure
* @return array of http client options
*/
protected function createHttpClientOption()
{
$options = [];
if ($this->config->getDebug()) {
$options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
if (!$options[RequestOptions::DEBUG]) {
throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
}
}
return $options;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Swagger\Client;
class DebugTest extends \PHPUnit_Framework_TestCase
{
public function testEnableDebugOutput()
{
$this->expectOutputRegex('#GET /v2/pet/1 HTTP/1.1#');
$config = new Configuration();
$config->setDebug(true);
$api = new Api\PetApi(null, $config);
$api->getPetById(1);
}
public function testEnableDebugOutputAsync()
{
$this->expectOutputRegex('#GET /v2/pet/1 HTTP/1.1#');
$config = new Configuration();
$config->setDebug(true);
$api = new Api\PetApi(null, $config);
$promise = $api->getPetByIdAsync(1);
$promise->wait();
}
}