Skip to content
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

[PHP] 6.0.x make php implementation depend on meta packages for http client #9772

Closed
Closed
Show file tree
Hide file tree
Changes from 4 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 @@ -18,7 +18,10 @@

namespace {{invokerPackage}};

use \Exception;
use Exception;
use Http\Client\Exception\RequestException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* ApiException Class Doc Comment
Expand All @@ -28,13 +31,13 @@ use \Exception;
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
*/
class ApiException extends Exception
class ApiException extends RequestException
{

/**
* The HTTP body of the server response either as Json or string.
*
* @var \stdClass|string|null
* @var string|null
*/
protected $responseBody;

Expand All @@ -52,19 +55,18 @@ class ApiException extends Exception
*/
protected $responseObject;

/**
* Constructor
*
* @param string $message Error message
* @param int $code HTTP status code
* @param string[]|null $responseHeaders HTTP response header
* @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string
*/
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
{
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
public function __construct(
$message,
RequestInterface $request,
ResponseInterface $response = null,
Exception $previous = null
) {
parent::__construct($message, $request, $previous);
if ($response) {
$this->responseHeaders = $response->getHeaders();
$this->responseBody = (string) $response->getBody();
$this->code = $response->getStatusCode();
}
}

/**
Expand Down Expand Up @@ -108,4 +110,4 @@ class ApiException extends Exception
{
return $this->responseObject;
}
}
}
olexiyk marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 14 additions & 2 deletions modules/openapi-generator/src/main/resources/php/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ To install the bindings via [Composer](https://getcomposer.org/), add the follow

Then run `composer install`

Your project is free to choose the http client of your choice
Please require packages that will provide http client functionality:
https://packagist.org/providers/psr/http-client-implementation
https://packagist.org/providers/php-http/async-client-implementation
https://packagist.org/providers/psr/http-factory-implementation

As an example:

```
composer require guzzlehttp/guzzle php-http/guzzle7-adapter http-interop/http-factory-guzzle
```

### Manual Installation

Download the files and include `autoload.php`:
Expand All @@ -54,8 +66,8 @@ require_once(__DIR__ . '/vendor/autoload.php');
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}
{{> php_doc_auth_partial}}
$apiInstance = new {{invokerPackage}}\Api\{{classname}}(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
// If you want use custom http client, pass your client which implements `Psr\Http\Client\ClientInterface`.
// This is optional, `Psr18ClientDiscovery` will be used to find http client. For instance `GuzzleHttp\Client` implements that interface
new GuzzleHttp\Client(){{#hasAuthMethods}},
$config{{/hasAuthMethods}}
);
Expand Down
Loading