add __toString and update php sample

This commit is contained in:
William Cheng 2015-06-17 19:00:29 +08:00
parent 456e17430b
commit 436db1f8e7
9 changed files with 53 additions and 1 deletions

View File

@ -65,6 +65,14 @@ class {{classname}} implements ArrayAccess {
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode($this, JSON_PRETTY_PRINT);
} else {
return json_encode($this);
}
}
}
{{/model}}
{{/models}}

View File

@ -61,4 +61,12 @@ class Category implements ArrayAccess {
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode($this, JSON_PRETTY_PRINT);
} else {
return json_encode($this);
}
}
}

View File

@ -80,4 +80,12 @@ class Order implements ArrayAccess {
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode($this, JSON_PRETTY_PRINT);
} else {
return json_encode($this);
}
}
}

View File

@ -80,4 +80,12 @@ class Pet implements ArrayAccess {
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode($this, JSON_PRETTY_PRINT);
} else {
return json_encode($this);
}
}
}

View File

@ -61,4 +61,12 @@ class Tag implements ArrayAccess {
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode($this, JSON_PRETTY_PRINT);
} else {
return json_encode($this);
}
}
}

View File

@ -88,4 +88,12 @@ class User implements ArrayAccess {
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode($this, JSON_PRETTY_PRINT);
} else {
return json_encode($this);
}
}
}

View File

@ -10,6 +10,9 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
// for error reporting (need to run with php5.3 to get no warning)
//ini_set('display_errors', 1);
//error_reporting(~0);
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
// enable debugging
//SwaggerClient\Configuration::$debug = true;

View File

@ -23,7 +23,8 @@ try {
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
// return Pet (model)
$response = $pet_api->getPetById($petId);
var_dump($response);
// to test __toString()
print ($response);
// add pet (post json)
$new_pet_id = 10005;