public function testNestedObjectToArray() { $object = new stdClass(); $object->key1 = new stdClass(); $object->key1->key2 = 'value2'; $array = Utilities::objectToArray($object); $this->assertArrayHasKey('key1', $array); $this->assertArrayHasKey('key2', $array['key1']); $this->assertEquals('value2', $array['key1']['key2']); }
public function getData() { if ($this->data !== null) { return $this->data; } $data = $this->getRawHttpRequestBody(); if (isset($_SERVER['CONTENT_TYPE']) && !empty($_SERVER['CONTENT_TYPE'])) { $components = preg_split('/\\;\\s*/', $_SERVER['CONTENT_TYPE']); if (in_array('application/x-www-form-urlencoded', $components)) { $a = explode('&', $data); $output = array(); foreach ($a as $entry) { if (strpos($entry, '=') > 0) { $tmp = explode('=', $entry); $output[urldecode($tmp[0])] = urldecode($tmp[1]); } } return $output; } elseif (in_array('application/json', $components)) { $data = Utilities::objectToArray(json_decode($data)); } else { throw new RestException(HttpStatusCodes::INTERNAL_SERVER_ERROR, 'Content-Type "' . $_SERVER['CONTENT_TYPE'] . '" not supported'); } } else { $data = Utilities::objectToArray(json_decode($data)); } $this->data = $data; return $data; }