Generate PHP SDKs from Swagger / OpenAPI
Speakeasy's PHP SDK is designed to be easy to use and debug, using object-oriented programing in PHP to create a useful and typed experience. It is also light on external dependencies.
Some of the core features of the SDK include:
- Class-based objects using reflection and property attributes to aid serialization
Utilspackage for common operations, simplifying generated code and making it easier to debug
- Configuration of the SDK is performed using a convenient factory pattern
- Authentication support for OAuth flows and other standard security mechanisms
The SDK uses only a small number of dependencies, including:
guzzlehttp/guzzle- used to provide an HTTP client
jms/serializer- tooling to add with data serialization
The PHP SDK provides a means of overriding the HTTP client used to make the API calls. The client provided by implement the
\GuzzleHttp\ClientInterface. A default implementation using
\GuzzleHttp\Client is provided by default.
Overriding the HTTP client requires just passing the client during construction:
$client = \GuzzleHttp\Client->new('timeout' => 2.0);$sdk = SDK::builder()->setClient($client)->build();
This allows for full customization of low-level features like proxies, custom headers, timeouts, cookies, and others.
Where possible the PHP SDK uses native types:
The generated classes are standard PHP classes with public properties and use attributes and reflection to help guide serialization.
When configured, we will attempt to prefer a certain number of parameters to be partof the function signatures directly, rather than provided as a an object to be passed to the operation methods. This is configured using the
maxMethodParams option in
gen.yaml. Whatever value is in that option will be the maximum number of parameters will place into the method signature.
The default value is
0, so if the
maxMethodParams is not set (or set to
0), no method parameters will be added to operations.
The PHP SDK returns errors via the
error property on the returned responses. The caller should check the status code on the response. If the status code indicates an error, it can then check the
error property for details.