/** * Converts an array, object, or string to an array. * * @param mixed $thing Array, object, or string (JSON, serialized, or XML). * @return array */ function to_array($thing) { if (is_array($thing)) { return array_build($thing); } if (is_object($thing)) { return array_build(object_to_array($thing)); } if (is_string($thing)) { if (is_json($thing)) { return json_decode($thing, true); } if (is_serialized($thing)) { return to_array(unserialize($thing)); } if (is_xml($thing)) { return xml_decode($thing, true); } } return (array) $thing; }
function test_servicio_eco() { $mensaje = xml_encode("Holá Mundo"); $payload = <<<XML <ns1:eco xmlns:ns1="http://siu.edu.ar/toba_referencia/serv_pruebas"> \t<texto>{$mensaje}</texto> </ns1:eco> XML; $opciones = array('to' => 'http://localhost/' . toba_recurso::url_proyecto($this->get_proyecto()) . '/servicios.php/serv_sin_seguridad'); $servicio = toba::servicio_web('cli_sin_seguridad', $opciones); $mensaje = $servicio->request(new toba_servicio_web_mensaje($payload)); $xml = new SimpleXMLElement($mensaje->get_payload()); $this->AssertEqual(xml_decode((string) $xml->texto), "Respuesta: Holá Mundo"); }
function evt__form_echo__enviar($datos) { $this->s__echo = $datos; $valor = xml_encode($datos['valor']); $clave = xml_encode($datos['clave']); $payload = <<<XML <ns1:test xmlns:ns1="http://siu.edu.ar/toba_referencia/serv_pruebas"> \t<texto>{$clave} {$valor}</texto> </ns1:test> XML; $opciones = array('to' => 'http://localhost/' . toba_recurso::url_proyecto() . '/servicios.php/serv_sin_seguridad'); $servicio = toba::servicio_web('cli_sin_seguridad', $opciones); $respuesta = $servicio->request(new toba_servicio_web_mensaje($payload)); toba::notificacion()->info(xml_decode($respuesta->get_payload())); }
function print_computers_real($systemid) { global $l, $list_fields, $list_col_cant_del, $default_fields, $tab_options, $protectedPost; if (isset($protectedPost["actshowgroup"]) and $protectedPost["modify"] != "") { foreach ($protectedPost as $key => $val) { //check65422 if (substr($key, 0, 5) == "check") { update_computer_group(substr($key, 5), $systemid, $protectedPost["actshowgroup"]); } } $tab_options['CACHE'] = 'RESET'; } //group 2.0 version $sql_group = "SELECT xmldef FROM groups WHERE hardware_id='%s'"; $arg = $systemid; $resGroup = mysql2_query_secure($sql_group, $_SESSION['OCS']["readServer"], $arg); $valGroup = mysql_fetch_array($resGroup); //group old version if (!$valGroup["xmldef"]) { $sql_group = "SELECT request FROM groups WHERE hardware_id='%s'"; $arg = $systemid; $resGroup = mysql2_query_secure($sql_group, $_SESSION['OCS']["readServer"], $arg); $valGroup = mysql_fetch_array($resGroup); $request = $valGroup["request"]; $tab_id = array(); $result_value = mysql_query($request, $_SESSION['OCS']["readServer"]) or die(mysql_error($_SESSION['OCS']["readServer"])); $fied_id_name = mysql_field_name($result_value, 0); while ($value = mysql_fetch_array($result_value)) { $tab_id[] = $value[$fied_id_name]; } } else { $tab_list_sql = regeneration_sql($valGroup["xmldef"]); $i = 1; $tab_id = array(); while ($tab_list_sql[$i]) { if ($tab_id != array()) { if (strtolower(substr($tab_list_sql[$i], 0, 19)) == "select distinct id ") { $tab_list_sql[$i] .= " and id in (" . implode(",", $tab_id) . ")"; } else { $tab_list_sql[$i] .= " and hardware_id in (" . implode(",", $tab_id) . ")"; } unset($tab_id); } $result_value = mysql_query(xml_decode($tab_list_sql[$i]), $_SESSION['OCS']["readServer"]) or die(mysql_error($_SESSION['OCS']["readServer"])); while ($value = mysql_fetch_array($result_value)) { $tab_id[] = $value["HARDWARE_ID"]; } $i++; } } if ($tab_id == array()) { msg_warning($l->g(766)); return false; } $form_name = "calcul_computer_groupcache"; $table_name = $form_name; echo "<font color=red><b>" . $l->g(927) . "</b></font>"; echo open_form($form_name); $queryDetails = "SELECT "; foreach ($list_fields as $lbl => $value) { $queryDetails .= $value . ","; } $queryDetails = substr($queryDetails, 0, -1) . " FROM hardware h LEFT JOIN accountinfo a ON a.hardware_id=h.id\n\t\t\t\t\t\twhere h.id in (" . implode(",", $tab_id) . ") and deviceid <> '_SYSTEMGROUP_' \n\t\t\t\t\t\t\t\t\t\tAND deviceid <> '_DOWNLOADGROUP_'"; if (isset($mesmachines) and $mesmachines != '') { $queryDetails .= $mesmachines; } $tab_options['FILTRE'] = array('h.NAME' => 'Nom'); tab_req($table_name, $list_fields, $default_fields, $list_col_cant_del, $queryDetails, $form_name, 90, $tab_options); form_action_group($systemid); echo close_form(); }
/** * Read a filename into the specified key in this handler * @param string $grouping * @return array */ public function read($grouping, $format = null) { $fallbackParser = function ($pathinfo, $contents) { switch ($pathinfo['extension']) { case 'xml': return xml_decode($contents, 4096); case 'json': return json_decode($contents, true); case 'php': // $array = include 'data:text/plain,' . urlencode($contents); $array = (include $pathinfo['dirname'] . '/' . $pathinfo['basename']); return $array; case 'ini': return parse_ini_string($contents, true); } }; $result = []; $path = $this->resolver->resolve('default', $grouping, $format); if ($path !== false) { $handle = fopen($path, 'r'); $contents = fread($handle, filesize($path)); $pathInfo = pathinfo($path); $parser = array_key_exists($pathInfo['extension'], $this->readParsers) ? $this->readParsers[$pathInfo['extension']] : $fallbackParser; $result = $parser($pathInfo, $contents); fclose($handle); } $path = $this->resolver->resolve($this->mode, $grouping, $format); if ($path !== false) { $handle = fopen($path, 'r'); $contents = fread($handle, filesize($path)); $pathInfo = pathinfo($path); $parser = array_key_exists($pathInfo['extension'], $this->readParsers) ? $this->readParsers[$pathInfo['extension']] : $fallbackParser; $array = $parser($pathInfo, $contents); $result = array_replace($result, $array); $this->setArray([$grouping . '_pathinfo' => $pathInfo]); fclose($handle); } if (empty($result)) { throw new \RuntimeException(sprintf("No configuration available for grouping '%s'", $grouping)); } return $this->setArray([$grouping => $result]); }
public function Communicate($pDomain, $pMethod, $pEndPoint, $pIdentity = null, $pFormat = 'json') { // Pull from callback function $EntryPoint = $this->_EntryPoint($pDomain); // Get the preferred domain protocol $Protocol = $this->_Protocol($pDomain); // Remove the leading slash from the end point. if ($pEndPoint[0] == '/') { $pEndPoint = preg_replace('/\\//', '', $pEndPoint, 1); } // Remove trailing slash on entrypoint. if ($EntryPoint[strlen($EntryPoint) - 1] == '/') { $EntryPoint[strlen($EntryPoint) - 1] = ''; } // No leading slash on the entry point means a separate domain. if ($EntryPoint[0] == '/') { $Entry = $Protocol . $pDomain . $EntryPoint . '/'; } else { $Entry = $Protocol . $EntryPoint . '/'; } $url = $Entry . $pEndPoint; switch ($pFormat) { case 'xml': $url .= '.xml'; break; case 'json': $url .= '.json'; break; default: break; } $result = $this->_Communicate($url); switch ($pFormat) { case 'xml': $result = xml_decode($result); break; case 'json': default: $result = json_decode($result); break; } return $result; }
/** * Retorna la misma cadena enviada al servidor * @param string $texto texto a repetir * @return string $texto texto repetido */ function op__eco(toba_servicio_web_mensaje $mensaje) { toba::logger()->debug('Entro al servicio web'); $xml = new SimpleXMLElement($mensaje->get_payload()); toba::logger()->debug('El payload para testeo es: ' . $xml->texto); $texto = xml_encode(xml_decode($xml->texto)); $payload = <<<XML <ns1:eco xmlns:ns1="http://siu.edu.ar/toba/pruebas"> \t<texto>{$texto}</texto> </ns1:eco> XML; return new toba_servicio_web_mensaje($payload); }
/** * Utility method used to catch problems decoding the JSON. * * @param string $string * @return mixed * @link http://php.net/manual/en/function.json-decode.php */ public static function xml_decode($string) { $decodedXml = xml_decode($string); if (is_null($decodedXml)) { throw new Webserivce\Exception('An error occurred decoding the XML received: ' . xml_last_error()); } return $decodedXml; }
/** * Responde exactamente con la misma cadena enviada * @param string $texto texto a repetir * @return string $texto texto repetido */ function op__test(toba_servicio_web_mensaje $mensaje) { $xml = new SimpleXMLElement($mensaje->get_payload()); $texto = xml_encode(xml_decode($xml->texto)); $dependencia = xml_encode($this->get_id_cliente('dependencia')); $payload = <<<XML <ns1:test xmlns:ns1="http://siu.edu.ar/toba_referencia/pruebas"> \t<texto>Texto: {$texto} \tDependencia: {$dependencia}</texto> </ns1:test> XML; return new toba_servicio_web_mensaje($payload); }