• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • SoapServer::setClass()

    (PHP 5, PHP 7)

    Sets the class which handles SOAP requests

    说明

    publicSoapServer::setClass(string $class_name[,mixed$...]): void

    Exports all methods from specified class.

    The object can be made persistent across request for a given PHP session with the SoapServer::setPersistence() method.

    参数

    $class_name

    The name of the exported class.

    ...

    These optional parameters will be passed to the default class constructor during object creation.

    返回值

    没有返回值。

    参见

    • SoapServer::SoapServer() SoapServer constructor
    • SoapServer::addFunction() 添加一个或多个函数来处理SOAP请求
    • SoapServer::setPersistence() Sets SoapServer persistence mode
    If you want your SOAP client to be able to save and then retrieve the object properties, you need to set the SOAP server to be persistent by setting session.auto_start=0, invoking session_start(), and SoapServer->setPersistence(SOAP_PERSISTENCE_SESSION) in the following manner:
    <?php
     //set ini
     ini_set("soap.wsdl_cache_enabled", 0);
     ini_set("session.auto_start", 0);
     //class file
     require_once('MyClass.php');
     //for persistent session
     session_start();
     //service
     $server = new SoapServer('service.wsdl');
     $server->setClass("MyClass");
     $server->setPersistence(SOAP_PERSISTENCE_SESSION);
     $server->handle();
    ?>
    
    You can also retrieve object properties the following way while using __autoload($class_name).
    <?php
    # Start Session
    session_start();
    # Auto Load Class as Required
    function __autoload($class_name)
    {
      require_once "/var/www/example/class/". $class_name. ".php";
    }
    //service
    $_SESSION[_bogus_session_name] = unserialize($_SESSION[_bogus_session_name]);
    $server = new SoapServer('service.wsdl');
    $server->setClass("MyClass");
    $server->setPersistence(SOAP_PERSISTENCE_SESSION);
    $server->handle();
    $_SESSION[_bogus_session_name] = serialize($_SESSION[_bogus_session_name])
    ?>
    
    When passing arguments to the default class constructor, make sure that you don't try and use the magic __construct method because that won't work.
    <?php
    class MyClass
    {
     function MyClass($arg1, $arg2)
     {
     }
    } 
    // Not:
    class MyClass
    {
     function __construct($arg1, $arg2)
     {
     }
    }
    ?>