Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gets fields generated at runtime

  • Loading branch information...
commit 6ab00a8b17ed9b1aab7a41360380f44a42166833 1 parent 1c93aba
Mashape authored
1  mashape/exceptions/exceptionMessages.php
View
@@ -81,6 +81,7 @@
// http://api.mashape.com Error codes
+define("EXCEPTION_FIELD_NOTFOUND", "Can't find the property \"%s\"");
define("EXCEPTION_INSTANCE_NULL", "Please verify the class you're initializing with 'MashapeHandler::handleApi(..)' exists");
define("EXCEPTION_EMPTY_REQUEST", "A request attempt was made to Mashape, but the response was empty. The firewall may be blocking outbound HTTP requests");
define("EXCEPTION_JSONDECODE_REQUEST", "Can't deserialize the response JSON from Mashape. The json_decode function is missing on server");
7 mashape/mashape.php
View
@@ -36,15 +36,18 @@ protected function __construct($dirPath) {
$this->dirPath = $dirPath;
}
- protected static function addError($code, $message) {
+ protected static function addError($code, $message, $statusCode = null) {
if (empty(self::$errors)) {
self::$errors = array();
}
$e = new MashapeAPIError($code, $message);
array_push(self::$errors, $e);
+ if (!empty($statusCode)) {
+ self::setHTTPStatusCode($statusCode);
+ }
}
- public static function setHttpStatusCode($statusCode) {
+ public static function setHTTPStatusCode($statusCode) {
if (!empty($statusCode)) {
header("HTTP/1.0 " . $statusCode);
}
12 mashape/methods/call/helpers/serializeArray.php
View
@@ -35,24 +35,12 @@ function serializeArray($result, $instance, $isSimpleResult, $serverKey) {
if (ArrayUtils::isAssociative($result)) {
$json .= "{";
foreach ($result as $key => $value) {
- echo "Associative key \"" . $key . "\"\n";
$json .= '"' . $key . '":';
if (is_object($value)) {
$json .= serializeObject($value, $instance, false, $serverKey);
} else {
if (is_array($value)) {
-// if (ArrayUtils::isAssociative($result)) {
-//
-// } else {
-// $json .= "[";
-// }
$json .= serializeArray($value, $instance, $isSimpleResult, $serverKey);
-// if (ArrayUtils::isAssociative($result)) {
-//
-// } else {
-// $json .= "]";
-// }
-// $json .= serializeArray($value, $instance, $isSimpleResult, $serverKey);
} else {
$json .= serializeObject($value, $instance, !is_object($value), $serverKey);
}
19 mashape/methods/call/helpers/serializeObject.php
View
@@ -37,7 +37,7 @@ function serializeObject($result, $instance, $isSimpleResult, $serverKey) {
} else {
// It's a custom object, let's serialize recursively every field
$className = get_class($result);
-
+
$reflectedClass = new ReflectionClass($className);
$xmlObject = RESTConfigurationLoader::getObject($className, $serverKey);
@@ -59,12 +59,19 @@ function serializeObject($result, $instance, $isSimpleResult, $serverKey) {
$fieldMethod = $field->getMethod();
$fieldValue = null;
if (empty($fieldMethod)) {
- $reflectedProperty = $reflectedClass->getProperty($fieldName);
- if ($reflectedProperty->isPublic()) {
- $fieldValue = $reflectedClass->getProperty($fieldName)->getValue($result);
+ if ($reflectedClass->hasProperty($fieldName)) {
+ $reflectedProperty = $reflectedClass->getProperty($fieldName);
+ if ($reflectedProperty->isPublic()) {
+ $fieldValue = $reflectedProperty->getValue($result);
+ } else {
+ // Try using the __get magic method
+ $fieldValue = $reflectedClass->getMethod("__get")->invokeArgs($result, array($fieldName));
+ }
+ } else if (ArrayUtils::existKey($fieldName, get_object_vars($result))) {
+ $fieldValue = $result->$fieldName;
+
} else {
- // Try using the __get magic method
- $fieldValue = $reflectedClass->getMethod("__get")->invokeArgs($result, array($fieldName));
+ throw new MashapeException(sprintf(EXCEPTION_FIELD_NOTFOUND, $fieldName), EXCEPTION_GENERIC_LIBRARY_ERROR_CODE);
}
} else {
$fieldValue = $reflectedClass->getMethod($fieldMethod)->invoke($result);
Please sign in to comment.
Something went wrong with that request. Please try again.