Object -> Array conversion function array2object($data) { if(!is_array($data)) return $data; $object = new stdClass(); if (is_array($data) && count($data) > 0) { foreach ($data as $name=>$value) { $name = strtolower(trim($name)); if (!empty($name)) { $object->$name = array2object($value); } } } return $object; } function object2array($data){ if(!is_object($data) && !is_array($data)) return $data; if(is_object($data)) $data = get_object_vars($data); return array_map('object2array', $data); } // Call parsers and functions of openSRS function processOpenSRS ($type="", $data="", $config = '', $rData = array()) { if ($type != "" && $data != ""){ if ($type == "array") $dataArray = $data; // ARRAY if ($type == "json"){ // JSON $json = str_replace("\\\"", "\"", $data); // Replace \" with " for JSON that comes from Javascript $dataArray = json_decode($json, true); } if ($type == "yaml") $dataArray = Spyc::YAMLLoad($data); // YAML // Convert associative array to object $dataObject = array2object($dataArray); } $class = '\DNSManager\opensrs\\' . $dataObject->func; // Call appropriate class if (class_exists($class)){ if(!empty($rData)) $classCall = new $class($type, $dataObject, $config, $rData); else $classCall = new $class($type, $dataObject, $config); } else { $classCall = null; trigger_error("OSRS Error - Unable to find the function passed. Either the function is misspelled or there are incorrect file paths set in openSRS_config.php."); } return $classCall; } function convertArray2Formated ($type="", $data="") { $resultString = ""; if ($type == "json") $resultString = json_encode($data); if ($type == "yaml") $resultString = Spyc::YAMLDump($data); return $resultString; } function convertFormated2array ($type="", $data="") { $resultArray = ""; if ($type == "json") $resultArray = json_decode($data, true); if ($type == "yaml") $resultArray = Spyc::YAMLLoad($data);; return $resultArray; }