diff --git a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache index 1247be83f3f..03b73f5775a 100644 --- a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache @@ -48,6 +48,18 @@ class APIClient { $this->headerValue = $headerValue; } + /** + * Set the user agent of the API client + * + * @param string $user_agent The user agent of the API client + */ + public function setUserAgent($user_agent) { + if (!is_string($user_agent)) { + throw new Exception('User-agent must be a string.'); + } + $this->user_agent= $user_agent; + } + /** * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] */ @@ -58,7 +70,6 @@ class APIClient { $this->curl_timout = $seconds; } - /** * @param string $resourcePath path to method endpoint * @param string $method method to call @@ -121,6 +132,13 @@ class APIClient { } curl_setopt($curl, CURLOPT_URL, $url); + // Set user agent + if ($this->user_agent) { + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + } else { // use PHP-Swagger as the default user agent + curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger'); + } + // Make the request $response = curl_exec($curl); $response_info = curl_getinfo($curl); diff --git a/samples/client/petstore/php/Swagger.php b/samples/client/petstore/php/Swagger.php index 1247be83f3f..03b73f5775a 100644 --- a/samples/client/petstore/php/Swagger.php +++ b/samples/client/petstore/php/Swagger.php @@ -48,6 +48,18 @@ class APIClient { $this->headerValue = $headerValue; } + /** + * Set the user agent of the API client + * + * @param string $user_agent The user agent of the API client + */ + public function setUserAgent($user_agent) { + if (!is_string($user_agent)) { + throw new Exception('User-agent must be a string.'); + } + $this->user_agent= $user_agent; + } + /** * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] */ @@ -58,7 +70,6 @@ class APIClient { $this->curl_timout = $seconds; } - /** * @param string $resourcePath path to method endpoint * @param string $method method to call @@ -121,6 +132,13 @@ class APIClient { } curl_setopt($curl, CURLOPT_URL, $url); + // Set user agent + if ($this->user_agent) { + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + } else { // use PHP-Swagger as the default user agent + curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger'); + } + // Make the request $response = curl_exec($curl); $response_info = curl_getinfo($curl);