downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SoapServer::addSoapHeader> <SoapServer
[edit] Last updated: Fri, 25 May 2012

view this page in

SoapServer::addFunction

(PHP 5 >= 5.0.1)

SoapServer::addFunctionSOAP リクエストによって処理される単一もしくはいくつかの関数を追加する

説明

public void SoapServer::addFunction ( mixed $functions )

リモートクライアント用に単一もしくは複数の関数をエクスポートします。

パラメータ

functions

単一の関数をエクスポートするには、 このパラメータに文字列として関数名を渡してください。

いくつかの関数をエクスポートするには、関数名の配列を渡してください。

全ての関数をエクスポートする場合、特別な定数 SOAP_FUNCTIONS_ALL を渡してください。

注意:

functions は、全ての入力引数を WSDL ファイルで定義されている順序と同じ順序で受け取る必要があり (これらの関数は出力パラメータを引数として受け取ることはありません) 、一つまたは複数の値を返す必要があります。 複数の値を返すには、名前付き出力パラメータの配列を返す必要があります。

返り値

値を返しません。

例1 SoapServer::addFunction() の例

<?php

function echoString($inputString)
{
    return 
$inputString;
}

$server->addFunction("echoString");

function 
echoTwoStrings($inputString1$inputString2)
{
    return array(
"outputString1" => $inputString1,
                 
"outputString2" => $inputString2);
}
$server->addFunction(array("echoString""echoTwoStrings"));

$server->addFunction(SOAP_FUNCTIONS_ALL);

?>

参考



SoapServer::addSoapHeader> <SoapServer
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes SoapServer::addFunction
dotpointer at gmail dot com 26-Oct-2007 06:52
Be careful with SOAP_FUNCTIONS_ALL, as it adds ALL availiable PHP functions to your server.

This can be a potential security threat, imagine clients doing this:

echo $client->file_get_contents("c:\\my files\\my_passwords.doc");

And voila, they have the contents of your file my_passwords.doc.
Evan Borgstrom 23-Aug-2006 03:42
In response to comment by Nathan O'Sullivan about returning (or passing) a complex type, you can also use the stdClass() object.

Assume you define a complex type like so:

<xsd:complexType name="TestType">
        <xsd:all>
                <xsd:element name="A" type="xsd:string" />
                <xsd:element name="B" type="xsd:int" />
                <xsd:element name="C" type="xsd:boolean" />
        </xsd:all>
</xsd:complexType>

To use an object in place of an array you can do:

$test = new stdClass();
$test->A = "test string";
$test->B = 45;
$test->C = false;

$result = $client->Test($test);
15-Jun-2005 05:10
function Login($username, $password)
{
  return array("LoginResult" => array("Id"=>1, "Name"=>"Nathan", "Nickname"=>"Nathan", "Email"=>"email address") );
}

Ok, Only a litte error in the last note.. :
"LoginResult" => array    and NOT      "LoginResult" , array
Nathan O'Sullivan 28-Apr-2005 11:36
You may be left wondering, as I was, how to return a complex type - consider the following WSDL snippets, for a method called Login:

 <xs:element name="Login">
        <xs:complexType>
          <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="username" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="password" type="xs:string" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>

   <xs:complexType name="UserInfo">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string" />
          <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
          <xs:element minOccurs="0" maxOccurs="1" name="Nickname" type="xs:string" />
          <xs:element minOccurs="0" maxOccurs="1" name="Email" type="xs:string" />
        </xs:sequence>
      </xs:complexType>

   <xs:element name="LoginResponse">
        <xs:complexType>
          <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="LoginResult" type="s0:UserInfo" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>

Here's a working Login function  that I've added with add SoapServer::addFunction

function Login($username, $password)
{
  return array("LoginResult", array("Id"=>1, "Name"=>"Nathan", "Nickname"=>"Nathan", "Email"=>"email address") );
}

The UserInfo complextype is represented by the inner array.  The outer array has just one element, "LoginResult".  The LogineResponse element  seems to be treated as a one-member array by PHP.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites