XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
NusoapServer.class.php
1<?php
3 * @package ShadeSoap
4 * @version $Id: NusoapServer.class.php,v 1.3 2007/12/15 12:16:57 minahito Exp $
5 * @copyright (c) 2005-2025 The XOOPSCube Project
6 * @license GPL 2
7 */
8 // TODO prevent path disclosure, gigamaster
9 error_reporting(0);
10
11// if (!XC_CLASS_EXISTS('soap_server')) exit();
12
13if (version_compare(PHP_VERSION, '5.0', '>=')) {
14 if (!class_exists('soap_server', false)) {
15 exit();
16 }
17} else {
18 if (!class_exists('soap_server')) {
19 exit();
20 }
21}
22
23class ShadeSoap_NusoapServer extends soap_server
24{
25 public function invoke_method()
26 {
27 $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
28
29 if ($this->wsdl) {
30 if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
31 $this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
32 $this->appendDebug('opData=' . $this->varDump($this->opData));
33 } elseif ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction)) {
34 // Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
35 $this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
36 $this->appendDebug('opData=' . $this->varDump($this->opData));
37 $this->methodname = $this->opData['name'];
38 } else {
39 $this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
40 $this->fault('Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
41 return;
42 }
43 } else {
44 $this->debug('in invoke_method, no WSDL to validate method');
45 }
46
47 // if a . is present in $this->methodname, we see if there is a class in scope,
48 // which could be referred to. We will also distinguish between two deliminators,
49 // to allow methods to be called a the class or an instance
50 $class = '';
51 $method = '';
52 if (strpos($this->methodname, '..') > 0) {
53 $delim = '..';
54 } elseif (strpos($this->methodname, '.') > 0) {
55 $delim = '.';
56 } else {
57 $delim = '';
58 }
59
60 if (strlen($delim) > 0 && 1 == substr_count($this->methodname, $delim)
61 &&
62 XC_CLASS_EXISTS(substr($this->methodname, 0, strpos($this->methodname, $delim)))) {
63 // get the class and method name
64 $class = substr($this->methodname, 0, strpos($this->methodname, $delim));
65 $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
66 $this->debug("in invoke_method, class=$class method=$method delim=$delim");
67 }
68
69 // does method exist?
70 if ('' == $class) {
71 if (!function_exists($this->methodname)) {
72 $this->debug("in invoke_method, function '$this->methodname' not found!");
73 $this->result = 'fault: method not found';
74 $this->fault('Client', "method '$this->methodname' not defined in service");
75 return;
76 }
77 } else {
78 $method_to_compare = ('4.' == substr(phpversion(), 0, 2)) ? strtolower($method) : $method;
79 if (!in_array($method_to_compare, get_class_methods($class))) {
80 $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
81 $this->result = 'fault: method not found';
82 $this->fault('Client', "method '$this->methodname' not defined in service");
83 return;
84 }
85 }
86
87 // evaluate message, getting back parameters
88 // verify that request parameters match the method's signature
89 if (! $this->verify_method($this->methodname, $this->methodparams)) {
90 // debug
91 $this->debug('ERROR: request not verified against method signature');
92 $this->result = 'fault: request failed validation against method signature';
93 // return fault
94 $this->fault('Client', "Operation '$this->methodname' not defined in service.");
95 return;
96 }
97
98 // if there are parameters to pass
99 $this->debug('in invoke_method, params:');
100 $this->appendDebug($this->varDump($this->methodparams));
101 $this->debug("in invoke_method, calling '$this->methodname'");
102
103 if ('' == $class) {
104 $this->debug('in invoke_method, calling function using call_user_func_array()');
105 $call_arg = (string)$this->methodname; // straight assignment changes $this->methodname to lower case after call_user_func_array()
106 } elseif ('..' == $delim) {
107 $this->debug('in invoke_method, calling class method using call_user_func_array()');
108 $call_arg = [$class, $method];
109 } else {
110 $this->debug('in invoke_method, calling instance method using call_user_func_array()');
111 $instance = new $class ();
112 $call_arg = [&$instance, $method];
113 }
114
115 //
116 // Insert CUBE CODE
117 //
118 $root =& XCube_Root::getSingleton();
119 // $root->mContext->mUser->setService(true);
120 $retValue = call_user_func_array($call_arg, [$root->mContext->mUser, $this->methodparams]);
121
122 if (is_array($retValue)) {
123 $retValue = $this->_encodeUTF8($retValue, $root->mLanguageManager);
124 } else {
125 $retValue = $root->mLanguageManager->encodeUTF8($retValue);
126 }
127
128 $this->methodreturn = $retValue;
129
130 $this->debug('in invoke_method, methodreturn:');
131 $this->appendDebug($this->varDump($this->methodreturn));
132 $this->debug("in invoke_method, called method $this->methodname, received $this->methodreturn of type ".gettype($this->methodreturn));
133 }
134
135 public function _encodeUTF8($arr, &$languageManager)
136 {
137 foreach (array_keys($arr) as $key) {
138 if (is_array($arr[$key])) {
139 $arr[$key] = $this->_encodeUTF8($arr[$key], $languageManager);
140 } else {
141 $arr[$key] = $languageManager->encodeUTF8($arr[$key]);
142 }
143 }
144
145 return $arr;
146 }
147}
varDump($data)
Definition nusoap.php:903
appendDebug($string)
Definition nusoap.php:299
debug($string)
Definition nusoap.php:286
verify_method($operation, $request)
Definition nusoap.php:4391
fault($faultcode, $faultstring, $faultactor='', $faultdetail='')
Definition nusoap.php:4600