Skip to content

Commit 0c793c8

Browse files
committed
add abstract remote function call class documentation
1 parent 7d6ee68 commit 0c793c8

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

Diff for: abstract-rfc.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## Usage: extending `AbstractRemoteFunctionCall`
2+
3+
Let's assume you have a SAP remote function called
4+
`MY_COOL_SAP_REMOTE_FUNCTION`, that takes a date as input value and returns
5+
the according week.
6+
7+
The class `MyCoolSapRemoteFunction` contains only code, that configures the API
8+
of your SAP remote function:
9+
10+
* `getName()` returns the SAP remote function name.
11+
* `setDate()` sets the SAP remote function parameter.
12+
* `getReturnTypecast()` casts the result of the SAP remote function call to a
13+
DateTime object.
14+
15+
```php
16+
<?php
17+
18+
use phpsap\saprfc\AbstractRemoteFunctionCall;
19+
use kbATeam\TypeCast\TypeCastValue;
20+
use phpsap\DateTime\SapDateTime;
21+
22+
/**
23+
* Class MyCoolSapRemoteFunction
24+
*
25+
* Get the calendar week to a given date.
26+
*/
27+
class MyCoolSapRemoteFunction extends AbstractRemoteFunctionCall
28+
{
29+
/**
30+
* Define the name of the remote function.
31+
* @return string
32+
*/
33+
public function getName()
34+
{
35+
return 'MY_COOL_SAP_REMOTE_FUNCTION';
36+
}
37+
38+
/**
39+
* Set the Date parameter for the remote function call.
40+
* @param \DateTime $dateTime The date to set.
41+
* @return $this
42+
*/
43+
public function setDate(\DateTime $dateTime)
44+
{
45+
$this->setParam('IV_DATE', $dateTime->format(SapDateTime::SAP_DATE));
46+
return $this;
47+
}
48+
49+
/**
50+
* Define typecasting for SAP remote function return value.
51+
* @return \kbATeam\TypeCast\TypeCastValue
52+
*/
53+
protected function getReturnTypecast()
54+
{
55+
return new TypeCastValue(function ($result) {
56+
return SapDateTime::createFromFormat(SapDateTime::SAP_WEEK, $result['E_WEEK']);
57+
});
58+
}
59+
}
60+
```
61+
62+
With this you will be able to call your SAP remote function in your PHP code
63+
without having to worry about modules or connections. Plus you get an implicit
64+
documentation about your SAP remote function in case your editor supports auto
65+
completion based on composers autoloader. You can even test the API of the SAP
66+
remote function using unit tests.
67+
68+
In case you're wondering about the SAP connection configuration here,
69+
[read how to configure a connection](saprfc-config).
70+
71+
```php
72+
<?php
73+
74+
use phpsap\saprfc\SapRfcConfigA;
75+
76+
//stored configuration, JSON encoded
77+
$config = '{
78+
"ashost": "sap.example.com",
79+
"sysnr": "001",
80+
"client": "01",
81+
"user": "username",
82+
"passwd": "password"
83+
}';
84+
//create a new SAP remote function instance using the stored configuration
85+
$dateToWeek = new MyCoolSapRemoteFunction(new SapRfcConfigA($config));
86+
/**
87+
* Set the parameter for the SAP remote function.
88+
* Your editor shows you the available parameters of the SAP remote function
89+
* and their value types.
90+
*/
91+
$dateToWeek->setDate(new DateTime('now'));
92+
//call the SAP remote function
93+
$week = $dateToWeek->invoke();
94+
//echo "<year>W<week>"
95+
echo $week->format('o\Ww') . PHP_EOL;
96+
```
97+
98+
---
99+
100+
[Go back to usage overview](usage)

Diff for: index.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ $result = (new SapRfcConnection(new SapRfcConfigA([
4949
- [Configure a connection](saprfc-config)
5050
- [Establish a connection](saprfc-connection)
5151
- [Invoke a function call](saprfc-function)
52+
* [Extend `AbstractRemoteFunctionCall`](abstract-rfc)

Diff for: saprfc-config.md

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ $config = new SapRfcConfigA($configArray);
112112

113113
[Go back to usage overview](usage)
114114
| [Continue with establishing a connection](saprfc-connection)
115+
| [Continue reading about extending `AbstractRemoteFunctionCall`](abstract-rfc)
115116

116117
[jsonserializable]: http://php.net/manual/en/class.jsonserializable.php
117118
[parse_ini_file]: http://php.net/manual/de/function.parse-ini-file.php

Diff for: usage.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ In order to call a SAP remote function, you need to
1010
[configure](saprfc-config) a [connection](saprfc-connection) and then invoke a
1111
[function](saprfc-function).
1212

13+
In case you want to use the SAP remote function API like any other PHP class,
14+
you can [extend `AbstractRemoteFunctionCall`](abstract-rfc) and you will get
15+
implicit documentation of your SAP remote function call parameters and the
16+
return value(s).
17+
1318
[Continue reading on how to configure a connection](saprfc-config).

0 commit comments

Comments
 (0)