XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
XCube_Service.class.php
1<?php
15
23function S_PUBLIC_FUNC( $definition ) {
24 $pos = strpos( $definition, '(' );
25 if ( $pos > 0 ) {
26 $params = [];
27 foreach ( explode( ',', substr( $definition, $pos + 1, - 1 ) ) as $t_param ) {
28 if ( $t_param ) {
29 [$k, $v] = explode( ' ', trim( $t_param ) );
30 $params[ $k ] = $v;
31 }
32 }
33 $ret = [ 'in' => $params ];
34 [$ret['out'], $ret['name']] = explode( ' ', substr( $definition, 0, $pos ) );
35
36 return $ret;
37 }
38
39 return null;
40}
41
42
48 public $mServiceName = '';
49
54 public $mNameSpace = '';
55
59 public $mClassName = 'XCube_Service';
60
67
68 public $_mTypes = [];
69
70 public $_mFunctions = [];
71
72 public function __construct() {
73 }
74
75 public function prepare() {
76 }
77
78 public function addType( $className ) {
79 $this->_mTypes[] = $className;
80 }
81
82 public function addFunction() {
83 $args = func_get_args();
84 $n = func_num_args();
85 $arg0 = &$args[0];
86
87 if ( 3 === $n ) {
88 $this->_addFunctionStandard( $arg0, $args[1], $args[2] );
89 } elseif ( 1 === $n && is_array( $arg0 ) ) {
90 $this->_addFunctionStandard( $arg0['name'], $arg0['in'], $arg0['out'] );
91 }
92 }
93
94 public function _addFunctionStandard( $name, $in, $out ) {
95 $this->_mFunctions[ $name ] = [
96 'out' => $out,
97 'name' => $name,
98 'in' => $in
99 ];
100 }
101
109 public function register( $name, &$procedure ) {
110 }
111}
112
121 public $mService;
122 public $mClientErrorStr;
123
124 public $mUser;
125
126 public function __construct( &$service ) {
127 $this->mService =& $service;
128 }
129
130 public function prepare() {
131 }
132
133 public function setUser( &$user ) {
134 $this->mUser =& $user;
135 }
136
137 public function call( $operation, $params ) {
138 }
139
140 public function getOperationData( $operation ) {
141 }
142
143 public function setError( $message ) {
144 $this->mClientErrorStr = $message;
145 }
146
147 public function getError() {
148 return ! empty( $this->mClientErrorStr ) ? $this->mClientErrorStr : $this->mService->mErrorStr;
149 }
150}
151
162 public function call( $operation, $params ) {
163 $this->mClientErrorStr = null;
164
165 if ( ! is_object( $this->mService ) ) {
166 $this->mClientErrorStr = 'This instance is not connected to service';
167
168 return null;
169 }
170
171 $root =& XCube_Root::getSingleton();
172 $request_bak =& $root->mContext->mRequest;
173 unset( $root->mContext->mRequest );
174
175 $root->mContext->mRequest = new XCube_GenericRequest( $params );
176
177 if ( isset( $this->mService->_mFunctions[ $operation ] ) ) {
178 $ret = call_user_func( [ $this->mService, $operation ] );
179
180 unset( $root->mContext->mRequest );
181 $root->mContext->mRequest =& $request_bak;
182
183 return $ret;
184 }
185
186 $this->mClientErrorStr = "operation {$operation} not present.";
187
188 return null;
189 }
190}
[Experiment Class] The adapter for a service class.
[Abstract] Interface to be used for accessing a Service.
$_mActionStrategy
XCube_ActionStrategy(?) — 'deprecated'.