/** * Constructor of the class * * @param Configuration $config config for this ApiClient */ public function __construct(\Squiggle\Configuration $config = null) { if ($config === null) { $config = Configuration::getDefaultConfiguration(); } $this->config = $config; $this->serializer = new ObjectSerializer(); }
/** * Constructor of the class * * @param Configuration $config config for this ApiClient */ public function __construct(\QuantiModo\Client\Configuration $config = null) { if ($config === null) { $config = Configuration::getDefaultConfiguration(); } $this->config = $config; $this->serializer = new ObjectSerializer(); }
/** * Deserialize a JSON string into an object * * @param mixed $data object or primitive to be deserialized * @param string $class class name is passed as a string * @param string $httpHeader HTTP headers * * @return object an instance of $class */ public function deserialize($data, $class, $httpHeader = null) { if (null === $data) { $deserialized = null; } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int] $inner = substr($class, 4, -1); $deserialized = array(); if (strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { $deserialized[$key] = $this->deserialize($value, $subClass); } } } elseif (strcasecmp(substr($class, -2), '[]') == 0) { $subClass = substr($class, 0, -2); $values = array(); foreach ($data as $key => $value) { $values[] = $this->deserialize($value, $subClass); } $deserialized = $values; } elseif ($class === '\\DateTime') { $deserialized = new \DateTime($data); } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { settype($data, $class); $deserialized = $data; } elseif ($class === '\\SplFileObject') { // determine file name if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\\s]+)[\'"]?$/i', $httpHeader, $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . $match[1]; } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); error_log("[INFO] Written {$byte_written} byte to {$filename}. Please move the file to a proper folder or delete the temp file after processing.\n", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); foreach ($instance::$swaggerTypes as $property => $type) { $propertySetter = $instance::$setters[$property]; if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { continue; } $propertyValue = $data->{$instance::$attributeMap[$property]}; if (isset($propertyValue)) { $instance->{$propertySetter}($this->deserialize($propertyValue, $type)); } } $deserialized = $instance; } return $deserialized; }
/** * Deserialize a JSON string into an object * * @param mixed $data object or primitive to be deserialized * @param string $class class name is passed as a string * @param string $httpHeaders HTTP headers * @param string $discriminator discriminator if polymorphism is used * * @return object an instance of $class */ public static function deserialize($data, $class, $httpHeaders = null, $discriminator = null) { if (null === $data) { return null; } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int] $inner = substr($class, 4, -1); $deserialized = array(); if (strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { $deserialized[$key] = self::deserialize($value, $subClass, null, $discriminator); } } return $deserialized; } elseif (strcasecmp(substr($class, -2), '[]') == 0) { $subClass = substr($class, 0, -2); $values = array(); foreach ($data as $key => $value) { $values[] = self::deserialize($value, $subClass, null, $discriminator); } return $values; } elseif ($class === 'object') { settype($data, 'array'); return $data; } elseif ($class === '\\DateTime') { // Some API's return an invalid, empty string as a // date-time property. DateTime::__construct() will return // the current time for empty input which is probably not // what is meant. The invalid empty string is probably to // be interpreted as a missing field/value. Let's handle // this graceful. if (!empty($data)) { return new \DateTime($data); } else { return null; } } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { settype($data, $class); return $data; } elseif ($class === '\\SplFileObject') { // determine file name if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]); } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); if (Configuration::getDefaultConfiguration()->getDebug()) { error_log("[DEBUG] Written {$byte_written} byte to {$filename}. Please move the file to a proper folder or delete the temp file after processing." . PHP_EOL, 3, Configuration::getDefaultConfiguration()->getDebugFile()); } return $deserialized; } else { // If a discriminator is defined and points to a valid subclass, use it. if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { $subclass = '\\Swagger\\Client\\Model\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { $class = $subclass; } } $instance = new $class(); foreach ($instance::swaggerTypes() as $property => $type) { $propertySetter = $instance::setters()[$property]; if (!isset($propertySetter) || !isset($data->{$instance::attributeMap()[$property]})) { continue; } $propertyValue = $data->{$instance::attributeMap()[$property]}; if (isset($propertyValue)) { $instance->{$propertySetter}(self::deserialize($propertyValue, $type, null, $discriminator)); } } return $instance; } }