Skip to content

[PHP] Separate host accessor into some parts #7036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ApiClient
$postData = json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($postData));
}

$url = $this->config->getHost() . $resourcePath;
$url = $this->config->getBaseUrl() . $resourcePath;

$curl = curl_init();
// set timeout, if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,26 @@ class Configuration
*/
protected $password = '';

/**
* The scheme
*
* @var string
*/
protected $scheme = '{{scheme}}';

/**
* The host
*
* @var string
*/
protected $host = '{{basePath}}';
protected $host = '{{host}}';

/**
* The basePath
*
* @var string
*/
protected $basePath = '{{contextPath}}';

/**
* User agent of the HTTP request, set to "PHP-Swagger" by default
Expand Down Expand Up @@ -230,6 +244,29 @@ class Configuration
return $this->password;
}

/**
* Sets the Scheme
*
* @param string $scheme Scheme
*
* @return $this
*/
public function setScheme($scheme)
{
$this->scheme = $scheme;
return $this;
}

/**
* Gets the Scheme
*
* @return string Scheme
*/
public function getScheme()
{
return $this->scheme;
}

/**
* Sets the host
*
Expand All @@ -253,6 +290,44 @@ class Configuration
return $this->host;
}

/**
* Sets the Base Path
*
* @param string $basePath Base Path
*
* @return $this
*/
public function setBasePath($basePath)
{
$this->basePath = $basePath;
return $this;
}

/**
* Gets the Base Path
*
* @return string Base Path
*/
public function getBasePath()
{
return $this->basePath;
}

/**
* Gets the Base URL
*
* @return string Base URL
*/
public function getBaseUrl()
{
return sprintf(
'%s://%s/%s',
$this->scheme,
trim($this->host, '/'),
trim($this->basePath, '/')
);
}

/**
* Sets the user agent of the api client
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ use {{invokerPackage}}\ObjectSerializer;
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'{{httpMethod}}',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected function testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'PUT',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,26 @@ class Configuration
*/
protected $password = '';

/**
* The scheme
*
* @var string
*/
protected $scheme = 'https';

/**
* The host
*
* @var string
*/
protected $host = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r';
protected $host = 'petstore.swagger.io */ ' " =end -- \r\n \n \r';

/**
* The basePath
*
* @var string
*/
protected $basePath = '/v2 *_/ ' \" =end -- \\r\\n \\n \\r';

/**
* User agent of the HTTP request, set to "PHP-Swagger" by default
Expand Down Expand Up @@ -240,6 +254,29 @@ public function getPassword()
return $this->password;
}

/**
* Sets the Scheme
*
* @param string $scheme Scheme
*
* @return $this
*/
public function setScheme($scheme)
{
$this->scheme = $scheme;
return $this;
}

/**
* Gets the Scheme
*
* @return string Scheme
*/
public function getScheme()
{
return $this->scheme;
}

/**
* Sets the host
*
Expand All @@ -263,6 +300,44 @@ public function getHost()
return $this->host;
}

/**
* Sets the Base Path
*
* @param string $basePath Base Path
*
* @return $this
*/
public function setBasePath($basePath)
{
$this->basePath = $basePath;
return $this;
}

/**
* Gets the Base Path
*
* @return string Base Path
*/
public function getBasePath()
{
return $this->basePath;
}

/**
* Gets the Base URL
*
* @return string Base URL
*/
public function getBaseUrl()
{
return sprintf(
'%s://%s/%s',
$this->scheme,
trim($this->host, '/'),
trim($this->basePath, '/')
);
}

/**
* Sets the user agent of the api client
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected function testSpecialTagsRequest($body)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'PATCH',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ protected function fakeOuterBooleanSerializeRequest($body = null)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -570,7 +570,7 @@ protected function fakeOuterCompositeSerializeRequest($body = null)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -817,7 +817,7 @@ protected function fakeOuterNumberSerializeRequest($body = null)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -1064,7 +1064,7 @@ protected function fakeOuterStringSerializeRequest($body = null)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -1321,7 +1321,7 @@ protected function testClientModelRequest($body)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'PATCH',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -1728,7 +1728,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -2012,7 +2012,7 @@ protected function testEnumParametersRequest($enum_form_string_array = null, $en
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'GET',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -2232,7 +2232,7 @@ protected function testInlineAdditionalPropertiesRequest($param)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'POST',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down Expand Up @@ -2468,7 +2468,7 @@ protected function testJsonFormDataRequest($param, $param2)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'GET',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected function testClassnameRequest($body)
$query = \GuzzleHttp\Psr7\build_query($queryParams);
return new Request(
'PATCH',
$this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
$this->config->getBaseUrl() . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
Expand Down
Loading