url_service=$url_service;
$this->processIdentifier=$processIdentifier;
}
/**
* Cette fonction permet de lancer l'appel du service WPS
* $params : string : chaine xml contenant les paramétres d'appel du service WPS. Normalement la chaine est issue de la fonction makeXMLRequestParams
*/
function send_request($params){
if($this->url_service!='' && $params){
//dsm($params);
$curl =curl_init($this->url_service);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params); // post the xml
$response = curl_exec($curl);
//dsm($response);
return $response;
//if($Response!='') return $Response;
//else return "pas de réponse";
}
//par defaut on retourne false
return "pas de bons parametres";
}
/**
* Cette fonction permet de generer la chaine xml d'appel du service wps
* $file_data_source : string : url du fichier contenant la source de données pour le traitement WPS
* $ref : tableau contant la liste des référentiels à utiliser pour l'appel du WPS
*/
function makeXMLRequestParams($inputs=array(), $outputs=array(), $xmlTag = true, $lineage = true, $storeExecuteResponse = true, $status = true){
/* Default attrubutes in Execute tag */
/*
service ="WPS"
version="1.0.0"
xmlns:wps="http://www.opengis.net/wps/1.0.0"
xmlns:ows="http://www.opengis.net/ows/1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_request.xsd">
*/
//if($file_data_source!='' && !empty($ref)){
$xml_params = '';
if($xmlTag) $xml_params.= '';
//Entete du fichier
$xml_params.=
'';
//Identifiant du process
$xml_params.=''.$this->processIdentifier.'';
//DataInputs
$xml_params.='';
$xml_params.=$this->formatInputs($inputs);
$xml_params.='';
//Bloc ResponseForm
$xml_params.= '
'
.$this->formatOutputs($outputs).'
';
$xml_params.='';
$xml = new DOMDocument;
$xml->preserveWhiteSpace = FALSE;
$xml->loadXML($xml_params);
//$xml->formatOutput = TRUE;
$request = $xml->saveXml();
if(!$xmlTag) {
//Remove xml header lik :
$request = trim(substr($request, 22));
}
return $request;
}
private function buildAttributeString($arrAttributes)
{
$strAtt = " ";
foreach ($arrAttributes as $key => $value) {
$strAtt .= $key.'="'.$value.'" ';
}
return $strAtt;
}
private function formatOutputs($outputs){
if (empty($outputs)) {
return '
output
';
} else {
$outputs_string = '';
foreach ($outputs as $output) {
$outputs_string .= '
buildAttributeString($output['attributes']) : ' wps:asReference="false"') .'>
'.$output['Identifier'].'
';
}
return $outputs_string;
}
}
private function formatInputs($inputs){
$inputs_string='';
foreach($inputs as $input){
$inputs_string.='
';
$inputs_string.='
'.$input['Identifier'].'';
if (isset($input['Title'])) {
$inputs_string.='
'.$input['Title'].'';
}
//2 cas possible Data ou Reference
if(isset($input['Reference'])){
$inputs_string.=' ';
}
if(isset($input['Data'])){
$inputs_string .= '
';
$inputs_string .= '
buildAttributeString($input['Data']['attributes']) : '') .'>';
if ($input['Data']['value'] == 'gml') {
$inputs_string .= '
';
$inputs_string .= $input['Data']['gml'];
$inputs_string .= '
';
}
/*
elseif($input['Data']['value'] == 'feature'){
}*/
else {
$inputs_string .= $input['Data']['value'];
}
$inputs_string .= '';
$inputs_string .= '
';
}
$inputs_string.='
';
}
return $inputs_string;
}
}