PDA

View Full Version : [PHP] Webservice implementato ad Oggetti


race2
10-06-2011, 15:54
Salve,
non riesco a trovare esempi su Google, ho fatto un semplice WS in PHP per inviare pių Email e funziona molto bene.

Il mio codice č procedurale come si vede nell'esempio sotto, vorrei implementare un WS ad Oggetti in modo da gestire molte pių cose in maniera semplice,

io sviluppo ad oggetti ma un WS non l'ho mai fatto, non lo so come si implementa ad Oggetti.

Come potrei trasformare il mio WS ad Oggetti ???



<?
require_once("lib/nusoap.php");
$ns = "http://www.mio-sito.it/php_webservice/";

$server = new soap_server();
$server->configureWSDL('WS_GladiatorMail', $ns);
$server->wsdl->schemaTargetNamespace = $ns;

//Register Function
$server->register('SendMail', array(
'_sEmails' => 'xsd:string',
'_sSubject' => 'xsd:string',
'_sHtml' => 'xsd:string',
'_sFrom' => 'xsd:string'
),
array('return' => 'xsd:string'), $ns);


function SendMail($_sEmails, $_sSubject, $_sHtml, $_sFrom)
{
$sResult = '';
$aEmail = preg_split("/[|]+/", $_sEmails);

$sHeader .= "From: <$_sFrom>\n";
$sHeader .= "X-Mailer: PHP/".phpversion()."\n";
$sHeader .= "MIME-Version: 1.0\n";
$sHeader .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$sHeader .= "Content-Transfer-Encoding: 7bit\n\n";

foreach($aEmail as $sEmail)
{
if($sEmail != '')
{
if(!mail($sEmail, $_sSubject, $_sHtml, $sHeader))
{
$sResult .= "|$sEmail";
}
}
}

return new soapval('return', 'xsd:string', substr($sResult, 1, strlen($sResult)));
}


$server->service($HTTP_RAW_POST_DATA);
?>