Merge pull request #2401 from wing328/php_getting_started

[PHP] update readme, add "Getting Started" section
This commit is contained in:
wing328 2016-03-17 17:12:03 +08:00
commit ca093e5aaa
2 changed files with 77 additions and 0 deletions

View File

@ -1,4 +1,17 @@
# {{packagePath}} # {{packagePath}}
{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}
This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
- API verion: {{appVersion}}
- Package version: {{artifactVersion}}
- Build date: {{generatedDate}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}
## Requirements ## Requirements
@ -40,6 +53,39 @@ composer install
./vendor/bin/phpunit lib/Tests ./vendor/bin/phpunit lib/Tests
``` ```
## Getting Started
Please follow the installation procedure and then run the following:
```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
{{{invokerPackage}}}::getDefaultConfiguration->setUsername('YOUR_USERNAME');
{{{invokerPackage}}}::getDefaultConfiguration->setPassword('YOUR_PASSWORD');{{/isBasic}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
{{{invokerPackage}}}::getDefaultConfiguration->setApiKey('{{{keyParamName}}}', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. BEARER) for API key, if needed
// {{{invokerPackage}}}::getDefaultConfiguration->setApiKeyPrefix('{{{keyParamName}}}', 'BEARER');{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
{{{invokerPackage}}}::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}
$api_instance = new {{invokerPackage}}\{{classname}}();
{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
try {
{{#returnType}}$result = {{/returnType}}$api_instance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
print_r($result);{{/returnType}}
} catch (Exception $e) {
echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), "\n";
}
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
?>
```
## Documentation for API Endpoints ## Documentation for API Endpoints
All URIs are relative to *{{basePath}}* All URIs are relative to *{{basePath}}*

View File

@ -1,4 +1,12 @@
# SwaggerClient-php # SwaggerClient-php
This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
- API verion: 1.0.0
- Package version: 1.0.0
- Build date: 2016-03-17T16:51:52.647+08:00
- Build package: class io.swagger.codegen.languages.PhpClientCodegen
## Requirements ## Requirements
@ -40,6 +48,29 @@ composer install
./vendor/bin/phpunit lib/Tests ./vendor/bin/phpunit lib/Tests
``` ```
## Getting Started
Please follow the installation procedure and then run the following:
```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure OAuth2 access token for authorization: petstore_auth
Swagger\Client::getDefaultConfiguration->setAccessToken('YOUR_ACCESS_TOKEN');
$api_instance = new Swagger\Client\PetApi();
$body = new \Swagger\Client\Model\Pet(); // \Swagger\Client\Model\Pet | Pet object that needs to be added to the store
try {
$api_instance->addPet($body);
} catch (Exception $e) {
echo 'Exception when calling PetApi->addPet: ', $e->getMessage(), "\n";
}
?>
```
## Documentation for API Endpoints ## Documentation for API Endpoints
All URIs are relative to *http://petstore.swagger.io/v2* All URIs are relative to *http://petstore.swagger.io/v2*