2828class SapRfcFunction extends AbstractFunction
2929{
3030 /**
31- * SAP remote function resource.
32- * @var mixed
31+ * @var mixed SAP connection resource.
3332 */
34- private $ function ;
33+ protected $ connection ;
34+
35+ /**
36+ * @var mixed SAP remote function resource.
37+ */
38+ protected $ function ;
3539
3640 /**
3741 * SAP remote function interface.
@@ -43,16 +47,17 @@ class SapRfcFunction extends AbstractFunction
4347 * Invoke the prepared function call.
4448 * @return array
4549 * @throws \phpsap\exceptions\FunctionCallException
50+ * @throws \LogicException
4651 */
4752 protected function execute ()
4853 {
4954 $ this ->setSaprfcParameters ();
50- $ result = @saprfc_call_and_receive ($ this ->getFunction () );
55+ $ result = @saprfc_call_and_receive ($ this ->function );
5156 if ($ result !== 0 ) {
5257 throw new FunctionCallException (sprintf (
5358 'Function call %s failed: %s ' ,
5459 $ this ->getName (),
55- @saprfc_exception ($ this ->getFunction () )
60+ @saprfc_exception ($ this ->function )
5661 ));
5762 }
5863 return $ this ->getSaprfcResults ();
@@ -78,6 +83,7 @@ public function __destruct()
7883 * @param string $name
7984 * @param array|string|float|int|bool|null $value
8085 * @return \phpsap\interfaces\IFunction $this
86+ * @throws \InvalidArgumentException
8187 */
8288 public function setParam ($ name , $ value )
8389 {
@@ -94,18 +100,16 @@ public function setParam($name, $value)
94100 */
95101 protected function getFunction ()
96102 {
97- if ($ this ->function === null ) {
98- $ this ->function = @saprfc_function_discover ($ this ->connection , $ this ->getName ());
99- if ($ this ->function === false ) {
100- $ this ->function = null ;
101- throw new UnknownFunctionException (sprintf (
102- 'Unknown function %s: %s ' ,
103- $ this ->getName (),
104- @saprfc_error ()
105- ));
106- }
103+ $ function = @saprfc_function_discover ($ this ->connection , $ this ->getName ());
104+ if ($ function === false ) {
105+ $ function = null ;
106+ throw new UnknownFunctionException (sprintf (
107+ 'Unknown function %s: %s ' ,
108+ $ this ->getName (),
109+ @saprfc_error ()
110+ ));
107111 }
108- return $ this -> function ;
112+ return $ function ;
109113 }
110114
111115 /**
@@ -158,7 +162,7 @@ private function remoteInterfaceType($type, $def)
158162 */
159163 private function saprfcFunctionInterface ()
160164 {
161- $ definitions = @saprfc_function_interface ($ this ->getFunction () );
165+ $ definitions = @saprfc_function_interface ($ this ->function );
162166 if ($ definitions === false ) {
163167 return [];
164168 }
@@ -191,13 +195,14 @@ private function setSaprfcParameters()
191195 * @param string $type The remote function call parameter type.
192196 * @param array $members The members of a remote function call parameter.
193197 * @return bool success?
198+ * @throws \LogicException
194199 */
195200 private function setSapRfcParameter ($ name , $ type , $ members )
196201 {
197202 switch ($ type ) {
198203 case 'IMPORT ' :
199204 $ param = $ this ->getParam ($ name , '' );
200- $ result = @saprfc_import ($ this ->getFunction () , $ name , $ param );
205+ $ result = @saprfc_import ($ this ->function , $ name , $ param );
201206 break ;
202207 case 'IMPORT_STRUCT ' :
203208 $ param = $ this ->getParam ($ name , []);
@@ -206,10 +211,10 @@ private function setSapRfcParameter($name, $type, $members)
206211 $ param [$ member ] = '' ;
207212 }
208213 }
209- $ result = @saprfc_import ($ this ->getFunction () , $ name , $ param );
214+ $ result = @saprfc_import ($ this ->function , $ name , $ param );
210215 break ;
211216 case 'TABLE ' :
212- $ result = @saprfc_table_init ($ this ->getFunction () , $ name );
217+ $ result = @saprfc_table_init ($ this ->function , $ name );
213218 break ;
214219 case 'EXPORT ' : //fall through
215220 case 'EXPORT_STRUCT ' :
@@ -240,13 +245,13 @@ private function getSaprfcResults()
240245 break ;
241246 case 'EXPORT ' : //fall through
242247 case 'EXPORT_STRUCT ' :
243- $ result [$ name ] = trim (@saprfc_export ($ this ->getFunction () , $ name ));
248+ $ result [$ name ] = trim (@saprfc_export ($ this ->function , $ name ));
244249 break ;
245250 case 'TABLE ' :
246251 $ result [$ name ] = [];
247- $ max = @saprfc_table_rows ($ this ->getFunction () , $ this ->getName ());
252+ $ max = @saprfc_table_rows ($ this ->function , $ this ->getName ());
248253 for ($ index = 1 ; $ index <= $ max ; $ index ++) {
249- $ result [$ name ][] = @saprfc_table_read ($ this ->getFunction () , $ this ->getName (), $ index );
254+ $ result [$ name ][] = @saprfc_table_read ($ this ->function , $ this ->getName (), $ index );
250255 }
251256 break ;
252257 default :
0 commit comments