Skip to content

Commit 868ffbf

Browse files
committed
multiple examples on how to use the project
1 parent 6049d33 commit 868ffbf

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

motivation.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ I inherited a project running on PHP 5.5.x containing undocumented code dealing
1818
4. The configuration has to be as interchangeable as possible between the PHP
1919
modules.
2020

21-
### Example
21+
### Example 1: connect->prepare->invoke
2222

2323
```php
2424
<?php
@@ -42,4 +42,69 @@ $function = $connection->prepareFunction('remoteFunctionName');
4242
$result = $function->invoke(['paramName' => 'value']);
4343
```
4444

45-
[koucky]: http://saprfc.sourceforge.net/ "SAPRFC extension module for PHP"
45+
### Example 2: extend remote function call
46+
47+
```php
48+
<?php
49+
50+
use phpsap\common\AbstractRemoteFunctionCall;
51+
use phpsap\interfaces\IConfig;
52+
use phpsap\saprfc\SapRfcConnection;
53+
54+
class ZMyCoolSapRemoteFunction extends AbstractRemoteFunctionCall
55+
{
56+
/**
57+
* Create a connection instance using the given config.
58+
* @param \phpsap\interfaces\IConfig $config
59+
* @return \phpsap\saprfc\SapRfcConnection
60+
*/
61+
protected function createConnectionInstance(IConfig $config)
62+
{
63+
return new SapRfcConnection($config);
64+
}
65+
66+
/**
67+
* Define the name of the remote function.
68+
* @return string
69+
*/
70+
public function getName()
71+
{
72+
return 'Z_My_Cool_Sap_Remote_Function';
73+
}
74+
75+
/**
76+
* Create the SAP remote function call parameters as code.
77+
* @param int $value
78+
* @return $this
79+
*/
80+
public function paramA($value)
81+
{
82+
if (!is_int($value)) {
83+
throw new InvalidArgumentException('Expected value to be int.');
84+
}
85+
return $this->setParam('paramA', $value);
86+
}
87+
}
88+
```
89+
```php
90+
<?php
91+
92+
use phpsap\saprfc\SapRfcConfigA;
93+
94+
//stored configuration, JSON encoded
95+
$config = '{
96+
"ashost": "sap.example.com",
97+
"sysnr": "001",
98+
"client": "01",
99+
"user": "username",
100+
"passwd": "password"
101+
}';
102+
//create a new SAP remote function instance using the stored configuration
103+
$zMyCoolSapRemoteFuntion = new ZMyCoolSapRemoteFunction(new SapRfcConfigA($config));
104+
//set the parameter for the SAP remote function
105+
$zMyCoolSapRemoteFuntion->paramA(123);
106+
//call the SAP remote function
107+
$result = $zMyCoolSapRemoteFuntion->invoke();
108+
```
109+
110+
[koucky]: http://saprfc.sourceforge.net/ "SAPRFC extension module for PHP"

0 commit comments

Comments
 (0)