/** * normalizes $input into a CertissimXMLElement object with children * use cases: * createChild(XMLElement) --> won't do anything * createChild(simpleXMLElement) * createChild("<element a='1' b='2'>valeur</element>") * createChild("element","valeur", array('a'=>1, 'b'=>2)) * * @param mixed $input * @param string $value * @param string $attributes * @return XMLElement objet normalized */ private function createChild($input, $value = null, $attributes = array()) { if (is_string($input) && !SceauTools::isXMLstring($input)) { $str = "<{$input}"; foreach ($attributes as $name => $val) { $str .= " {$name}='{$val}'"; } $str .= '>'; if (!is_null($value)) { $str .= $value; } $str .= "</{$input}>"; $input = new SimpleXMLElement($str); } if (is_string($input) || SceauTools::isSimpleXMLElement($input)) { $input = new SceauXMLElement($input); } if (!SceauTools::isXMLElement($input)) { $msg = "Le type du paramètre entré n'est pas pris en compte par la classe SceauXMLElement : " . get_class($input); SceauTools::insertLog(get_class($this) . " - createChild()", $msg); throw new Exception($msg); } return $input; }
/** * conects to a server, reach the script and returns the response * * @param string $header header to send to the server to reach the script * @return type */ function connect($header) { //if connexion is secured if ($this->is_ssl) { //ssl connexion $socket = fsockopen('ssl://' . $this->host, $this->port, $this->errno, $this->errstr, self::TIMEOUT); //if connexion is not secured } else { //connexion without ssl $socket = fsockopen($this->host, $this->port); } if ($socket !== false) { $res = ''; //sending data to the server if (@fputs($socket, $header)) { //response reading while (!feof($socket)) { $res .= fgets($socket, 128); } //if sending data failed } else { //we put error on log file SceauTools::insertLog(get_class($this) . " - connect()", "Envoi des données impossible sur : " . $host); $res = false; } //connexion closed fclose($socket); } else { SceauTools::insertLog(get_class($this) . " - connect()", "Connexion socket impossible sur l'hôte {$host}. Erreur " . $this->errno . " : " . $this->errstr); $res = false; } return $res; }