1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14:
15: function S_PUBLIC_FUNC($definition)
16: {
17: $pos = strpos($definition, '(');
18: if ($pos > 0) {
19: $params = array();
20: foreach (explode(',', substr($definition, $pos + 1, -1)) as $t_param) {
21: if ($t_param) {
22: list($k, $v) = explode(' ', trim($t_param));
23: $params[$k] = $v;
24: }
25: }
26: $ret = array('in' => $params);
27: list($ret['out'], $ret['name']) = explode(' ', substr($definition, 0, $pos));
28: return $ret;
29: }
30: return null;
31: }
32:
33: 34: 35: 36: 37: 38: 39:
40: class XCube_Service
41: {
42: 43: 44: 45:
46: var $mServiceName = "";
47:
48: 49: 50: 51:
52: var $mNameSpace = "";
53:
54: 55: 56:
57: var $mClassName = "XCube_Service";
58:
59: 60: 61: 62: 63:
64: var $_mActionStrategy = null;
65:
66: var $_mTypes = array();
67:
68: var $_mFunctions = array();
69:
70: function XCube_Service()
71: {
72: }
73:
74: function prepare()
75: {
76: }
77:
78: function addType($className)
79: {
80: $this->_mTypes[] = $className;
81: }
82:
83: function addFunction()
84: {
85: $args = func_get_args();
86: $n = func_num_args();
87: $arg0 = &$args[0];
88:
89: if ($n == 3) {
90: $this->_addFunctionStandard($arg0, $args[1], $args[2]);
91: }
92: elseif ($n == 1 && is_array($arg0)) {
93: $this->_addFunctionStandard($arg0['name'], $arg0['in'], $arg0['out']);
94: }
95: }
96:
97: function _addFunctionStandard($name, $in, $out)
98: {
99: $this->_mFunctions[$name] = array(
100: 'out' => $out,
101: 'name' => $name,
102: 'in' => $in
103: );
104: }
105:
106: 107: 108: 109:
110: function register($name, &$procedure)
111: {
112: }
113: }
114:
115: 116: 117: 118: 119: 120: 121:
122: class XCube_AbstractServiceClient
123: {
124: var $mService;
125: var $mClientErrorStr;
126:
127: var $mUser = null;
128:
129: function XCube_AbstractServiceClient(&$service)
130: {
131: $this->mService =& $service;
132: }
133:
134: function prepare()
135: {
136: }
137:
138: function setUser(&$user)
139: {
140: $this->mUser =& $user;
141: }
142:
143: function call($operation, $params)
144: {
145: }
146:
147: function getOperationData($operation)
148: {
149: }
150:
151: function setError($message)
152: {
153: $this->mClientErrorStr = $message;
154: }
155:
156: function getError()
157: {
158: return !empty($this->mClientErrorStr) ? $this->mClientErrorStr : $this->mService->mErrorStr;
159: }
160: }
161:
162: 163: 164: 165: 166: 167: 168: 169: 170:
171: class XCube_ServiceClient extends XCube_AbstractServiceClient
172: {
173: function call($operation, $params)
174: {
175: $this->mClientErrorStr = null;
176:
177: if(!is_object($this->mService)) {
178: $this->mClientErrorStr = "This instance is not connected to service";
179: return null;
180: }
181:
182: $root =& XCube_Root::getSingleton();
183: $request_bak =& $root->mContext->mRequest;
184: unset($root->mContext->mRequest);
185:
186: $root->mContext->mRequest = new XCube_GenericRequest($params);
187:
188: if (isset($this->mService->_mFunctions[$operation])) {
189: $ret = call_user_func(array($this->mService, $operation));
190:
191: unset($root->mContext->mRequest);
192: $root->mContext->mRequest =& $request_bak;
193:
194: return $ret;
195: }
196: else {
197: $this->mClientErrorStr = "operation ${operation} not present.";
198: return null;
199: }
200: }
201: }
202:
203: ?>