33I inherited a project running on PHP 5.5.x containing undocumented code dealing
44 with SAP remote function calls. As a way to connect, [ Eduard Kouckys SAPRFC
55 module] [ koucky ] had been used. In order to switch to a more current PHP
6- version, I had rewrite the PHP code and replace the PHP module too. The
6+ version, I had to rewrite the PHP code and replace the PHP module too. The
77 question was: How can I be sure, that the code of this project dealing with
88 SAP remote function calls will not be the source of errors?
99
@@ -14,13 +14,10 @@ That lead to the following requirements:
14142 . The code in my project dealing with SAP remote function calls has to work
1515 for several [ PHP modules] ( php-modules ) and it still has to work, in case
1616 of a switch to a different way of communicating with SAP.
17- 3 . Any parameters of a SAP remote function call have to be defined as methods
18- as a way of documenting the API of a SAP remote function call via the
19- editors autocomplete functionality.
20- 4 . The configuration has to be as interchangeable as possible between the PHP
17+ 3 . The configuration has to be as interchangeable as possible between the PHP
2118 modules.
2219
23- ### Example 1 : connect ➔ prepare ➔ invoke
20+ ### Example: connect ➔ prepare ➔ invoke
2421
2522``` php
2623<?php
@@ -41,75 +38,7 @@ $connection = new SapRfcConnection(new SapRfcConfigA($config));
4138//prepare a function call
4239$function = $connection->prepareFunction('MY_COOL_SAP_REMOTE_FUNCTION');
4340//call the remote function
44- $result = $function->invoke(['paramName' => 'value']);
45- ```
46-
47- ### Example 2: extend remote function call
48-
49- ``` php
50- <?php
51-
52- use phpsap\saprfc\AbstractRemoteFunctionCall;
53-
54- class MyCoolSapRemoteFunction extends AbstractRemoteFunctionCall
55- {
56- /**
57- * Define the name of the remote function.
58- * @return string
59- */
60- public function getName()
61- {
62- return 'MY_COOL_SAP_REMOTE_FUNCTION';
63- }
64-
65- /**
66- * Create the SAP remote function call parameters as code.
67- * @param int $value
68- * @return $this
69- */
70- public function paramA($value)
71- {
72- if (!is_int($value)) {
73- throw new InvalidArgumentException('Expected value to be int.');
74- }
75- return $this->setParam('paramA', $value);
76- }
77-
78- /**
79- * Call SAP remote function to see, if paramA succeeds.
80- * @param null|array $params Optional parameter array.
81- * @return bool success?
82- * @throws \phpsap\interfaces\exceptions\IConnectionFailedException
83- * @throws \phpsap\interfaces\exceptions\IUnknownFunctionException
84- * @throws \phpsap\exceptions\FunctionCallException
85- */
86- protected function invoke($params = null)
87- {
88- //parent returns array
89- $result = parent::invoke($params);
90- return $result['E_OK'] !== 'X';
91- }
92- }
93- ```
94- ``` php
95- <?php
96-
97- use phpsap\saprfc\SapRfcConfigA;
98-
99- //stored configuration, JSON encoded
100- $config = '{
101- "ashost": "sap.example.com",
102- "sysnr": "001",
103- "client": "01",
104- "user": "username",
105- "passwd": "password"
106- }';
107- //create a new SAP remote function instance using the stored configuration
108- $remoteFunction = new MyCoolSapRemoteFunction(new SapRfcConfigA($config));
109- //set the parameter for the SAP remote function
110- $remoteFunction->paramA(123);
111- //call the SAP remote function
112- $result = $remoteFunction->invoke();
41+ $result = $function->setParam('paramName', 'value')->invoke();
11342```
11443
11544[ koucky ] : http://saprfc.sourceforge.net/ " SAPRFC extension module for PHP "
0 commit comments