在同一个PHP SOAP服务器中处理对多个类的请求

在同一个PHP SOAP服务器中处理对多个类的请求,php,web-services,soap,wsdl,Php,Web Services,Soap,Wsdl,有可能只有一个PHP SOAP服务器来处理对多个类(服务)的请求吗 如果是,请给出一个示例实现 如果没有,请描述一下原因好吗?能否将其他服务打包成一个类?完全未经测试,这只是一个想法 class MySoapService { public function __construct() { $this->_service1 = new Service1(); $this->_service2 = new Service2(); } // You could

有可能只有一个PHP SOAP服务器来处理对多个类(服务)的请求吗

如果是,请给出一个示例实现


如果没有,请描述一下原因好吗?

能否将其他服务打包成一个类?完全未经测试,这只是一个想法

class MySoapService { public function __construct() { $this->_service1 = new Service1(); $this->_service2 = new Service2(); } // You could probably use __call() here and intercept any calls, // thus avoiding the need for these declarations in the wrapper class... public function add($a, $b) { return $this->_service1->add($a, $b); } public function sub($a, $b) { return $this->_service2->sub($a, $b); } } class Service1 { public function add($a, $b) { return $a + $b; } } class Service2 { public function sub($a, $b) { return $a - $b; } } 类MySoapService { 公共函数构造() { $this->_service1=new service1(); $this->_service2=新服务2(); } //您可以在此处使用_call()截取任何调用, //这样就避免了在包装类中需要这些声明。。。 公共职能增加($a$b) { 返回$this->\u service1->add($a,$b); } 公共职能分部(a$b) { 返回$this->_service2->sub($a,$b); } } 类别服务1 { 公共职能增加($a$b) { 返回$a+$b; } } 类别服务2 { 公共职能分部(a$b) { 返回$a-$b; } }
对于php5,另一个采用了相同的总体思想(代理类) 使用哈希将函数映射到回调

class ServiceProxy {
    private $map = array();

    public function addMethod($name, $callback) {
        if(is_callable($callback)) {
            $this->map[$name] = $callback;
            return true;
        }
        return false;
    }      

    function __call($name, $args) {
        if(isset($map[$name])) {
            return call_user_func_array($map[$name], $args);
        } else {
            return null;
        }
    }
}

例如,该类还可以使用反射API并添加来自对象的所有pulic方法。

如果两个类都有名称相同(但参数不同)的方法,则可以使用func_get_args()来分析参数并以这种方式区分方法

如果他们采取相同的论点。。。那你就有点困了

为什么不能只使用两个单独的Web服务