forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
modules/openapi-generator/src/main/resources/php-nextgen/ClientBuilder.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* ClientBuilder | ||
* | ||
* PHP version 8.1 | ||
* | ||
* @package {{invokerPackage}} | ||
* @author OpenAPI Generator team | ||
* @link https://openapi-generator.tech | ||
*/ | ||
|
||
{{>partial_header}} | ||
/** | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
namespace {{invokerPackage}}; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\ClientInterface; | ||
use {{invokerPackage}}\Configuration; | ||
use {{invokerPackage}}\HeaderSelector; | ||
{{#apiInfo}} | ||
{{#apis}} | ||
use {{apiPackage}}\{{classFilename}}; | ||
{{/apis}} | ||
{{/apiInfo}} | ||
|
||
/** | ||
* ClientBuilder Class Doc Comment | ||
* | ||
* @package {{invokerPackage}} | ||
* @author OpenAPI Generator team | ||
* @link https://openapi-generator.tech | ||
{{#apiInfo}} | ||
{{#apis}} | ||
* @property-read {{classFilename}} ${{classVarName}} | ||
{{/apis}} | ||
{{/apiInfo}} | ||
*/ | ||
class ClientBuilder | ||
{ | ||
/** | ||
* @var ClientInterface | ||
*/ | ||
protected ClientInterface $client; | ||
/** | ||
* @var Configuration | ||
*/ | ||
protected Configuration $config; | ||
/** | ||
* @var HeaderSelector | ||
*/ | ||
protected HeaderSelector $headerSelector; | ||
/** | ||
* @var int Host index | ||
*/ | ||
protected int $hostIndex; | ||
/** | ||
* @param ClientInterface|null $client | ||
* @param Configuration|null $config | ||
* @param HeaderSelector|null $selector | ||
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec | ||
*/ | ||
public function __construct( | ||
ClientInterface $client = null, | ||
Configuration $config = null, | ||
HeaderSelector $selector = null, | ||
int $hostIndex = 0 | ||
) { | ||
$this->client = $client ?: new Client(); | ||
$this->config = $config ?: new Configuration(); | ||
$this->headerSelector = $selector ?: new HeaderSelector(); | ||
$this->hostIndex = $hostIndex; | ||
} | ||
|
||
/** | ||
* Initiates new client builder with OAuth access token. | ||
* @link https://docs.salla.dev/docs/merchant/2fa0d7aca2def-authorization | ||
* | ||
* @param string $accessToken | ||
* @throws \InvalidArgumentException | ||
* @return ClientBuilder | ||
*/ | ||
public static function createWithAccessToken( | ||
string $accessToken | ||
): static { | ||
if (empty($accessToken)) { | ||
throw new \InvalidArgumentException('Access token cannot be empty'); | ||
} | ||
|
||
$config = new Configuration(); | ||
$config->setAccessToken($accessToken); | ||
|
||
return new static(null, $config); | ||
} | ||
|
||
/** | ||
* {{=<% %>=}}{@inheritDoc}<%={{ }}=%> | ||
*/ | ||
public function __get(string $name) | ||
{ | ||
switch ($name) { | ||
{{#apiInfo}} | ||
{{#apis}} | ||
case '{{classVarName}}': | ||
return new {{classFilename}}($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
{{/apis}} | ||
{{/apiInfo}} | ||
default: | ||
throw new \InvalidArgumentException(\sprintf('Unknown property "%s"', $name)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
samples/client/echo_api/php-nextgen/src/ClientBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* ClientBuilder | ||
* | ||
* PHP version 8.1 | ||
* | ||
* @package OpenAPI\Client | ||
* @author OpenAPI Generator team | ||
* @link https://openapi-generator.tech | ||
*/ | ||
|
||
/** | ||
* Echo Server API | ||
* | ||
* Echo Server API | ||
* | ||
* The version of the OpenAPI document: 0.1.0 | ||
* Contact: team@openapitools.org | ||
* @generated Generated by: https://openapi-generator.tech | ||
* OpenAPI Generator version: 7.3.0-SNAPSHOT | ||
*/ | ||
|
||
/** | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
namespace OpenAPI\Client; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\ClientInterface; | ||
use OpenAPI\Client\Configuration; | ||
use OpenAPI\Client\HeaderSelector; | ||
use OpenAPI\Client\Api\AuthApi; | ||
use OpenAPI\Client\Api\BodyApi; | ||
use OpenAPI\Client\Api\FormApi; | ||
use OpenAPI\Client\Api\HeaderApi; | ||
use OpenAPI\Client\Api\PathApi; | ||
use OpenAPI\Client\Api\QueryApi; | ||
|
||
/** | ||
* ClientBuilder Class Doc Comment | ||
* | ||
* @package OpenAPI\Client | ||
* @author OpenAPI Generator team | ||
* @link https://openapi-generator.tech | ||
* @property-read AuthApi $auth | ||
* @property-read BodyApi $body | ||
* @property-read FormApi $form | ||
* @property-read HeaderApi $header | ||
* @property-read PathApi $path | ||
* @property-read QueryApi $query | ||
*/ | ||
class ClientBuilder | ||
{ | ||
/** | ||
* @var ClientInterface | ||
*/ | ||
protected ClientInterface $client; | ||
|
||
/** | ||
* @var Configuration | ||
*/ | ||
protected Configuration $config; | ||
|
||
/** | ||
* @var HeaderSelector | ||
*/ | ||
protected HeaderSelector $headerSelector; | ||
|
||
/** | ||
* @var int Host index | ||
*/ | ||
protected int $hostIndex; | ||
|
||
/** | ||
* @param ClientInterface|null $client | ||
* @param Configuration|null $config | ||
* @param HeaderSelector|null $selector | ||
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec | ||
*/ | ||
public function __construct( | ||
ClientInterface $client = null, | ||
Configuration $config = null, | ||
HeaderSelector $selector = null, | ||
int $hostIndex = 0 | ||
) { | ||
$this->client = $client ?: new Client(); | ||
$this->config = $config ?: new Configuration(); | ||
$this->headerSelector = $selector ?: new HeaderSelector(); | ||
$this->hostIndex = $hostIndex; | ||
} | ||
|
||
/** | ||
* Initiates new client builder with OAuth access token. | ||
* @link https://docs.salla.dev/docs/merchant/2fa0d7aca2def-authorization | ||
* | ||
* @param string $accessToken | ||
* @throws \InvalidArgumentException | ||
* @return ClientBuilder | ||
*/ | ||
public static function createWithAccessToken( | ||
string $accessToken | ||
): static { | ||
if (empty($accessToken)) { | ||
throw new \InvalidArgumentException('Access token cannot be empty'); | ||
} | ||
|
||
$config = new Configuration(); | ||
$config->setAccessToken($accessToken); | ||
|
||
return new static(null, $config); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __get(string $name) | ||
{ | ||
switch ($name) { | ||
case 'auth': | ||
return new AuthApi($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
case 'body': | ||
return new BodyApi($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
case 'form': | ||
return new FormApi($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
case 'header': | ||
return new HeaderApi($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
case 'path': | ||
return new PathApi($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
case 'query': | ||
return new QueryApi($this->client, $this->config, $this->headerSelector, $this->hostIndex); | ||
default: | ||
throw new \InvalidArgumentException(\sprintf('Unknown property "%s"', $name)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.