Skip to content

Commit 2b8308f

Browse files
committed
Add getFunctionDescription() of current master branch of Kraliks sapnwrfc module
... instead of just get_object_vars(). That way, the member elements of tables and structs can now be added to the internal API definition too. :-)
1 parent c0173e9 commit 2b8308f

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/SapRfc.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function extractApi(): RemoteApi
158158
strtoupper($name),
159159
$this->mapType($element['type']),
160160
$this->mapDirection($element['direction']),
161-
$element['optional']
161+
$element
162162
));
163163
} catch (SapLogicException $exception) {
164164
/**
@@ -184,7 +184,11 @@ public function extractApi(): RemoteApi
184184
*/
185185
public function saprfcFunctionInterface(): array
186186
{
187-
$result = get_object_vars($this->getFunction());
187+
$function = $this->getFunction();
188+
if (method_exists($function, 'getFunctionDescription')) {
189+
return $function->getFunctionDescription();
190+
}
191+
$result = get_object_vars($function);
188192
unset($result['name']);
189193
return $result;
190194
}

src/Traits/ApiTrait.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace phpsap\saprfc\Traits;
44

5+
use phpsap\classes\Api\Element;
56
use phpsap\classes\Api\Struct;
67
use phpsap\classes\Api\Table;
78
use phpsap\classes\Api\Value;
@@ -25,33 +26,38 @@ trait ApiTrait
2526
* @param string $type The type of the parameter or return value.
2627
* @param string $direction The direction indicating whether it's a parameter or
2728
* return value.
28-
* @param bool $optional The flag, whether this parameter or return value is
29-
* required.
29+
* @param array $def The complete API value defintion from the module.
3030
* @return Value|Struct|Table
31-
* @throws \phpsap\exceptions\SapLogicException
32-
* @throws \phpsap\exceptions\InvalidArgumentException
3331
*/
34-
private function createApiValue($name, $type, $direction, $optional)
32+
private function createApiValue($name, $type, $direction, $def)
3533
{
34+
$optional = $def['optional'];
3635
if ($direction === IArray::DIRECTION_TABLE) {
37-
/**
38-
* The members array is empty because there is no information about it
39-
* from the sapnwrfc module class.
40-
* @todo Write to Gregor Kralik.
41-
*/
42-
return new Table($name, $optional, []);
36+
return new Table($name, $optional, $this->createMembers($def));
4337
}
4438
if ($type === IArray::TYPE_ARRAY) {
45-
/**
46-
* The members array is empty because there is no information about it
47-
* from the sapnwrfc module class.
48-
* @todo Write to Gregor Kralik.
49-
*/
50-
return new Struct($name, $direction, $optional, []);
39+
return new Struct($name, $direction, $optional, $this->createMembers($def));
5140
}
5241
return new Value($type, $name, $direction, $optional);
5342
}
5443

44+
/**
45+
* Create either struct or table members from the def array of the remote function API.
46+
* @param array $def The complete API value defintion.
47+
* @return \phpsap\classes\Api\Element[] An array of IElement compatible objects.
48+
* @throws \phpsap\exceptions\SapLogicException In case a datatype is missing in the mappings array.
49+
*/
50+
private function createMembers($def): array
51+
{
52+
$result = [];
53+
if (array_key_exists('typedef', $def) && is_array($def['typedef'])) {
54+
foreach ($def['typedef'] as $name => $member) {
55+
$result[] = new Element($this->mapType($member['type']), $name);
56+
}
57+
}
58+
return $result;
59+
}
60+
5561
/**
5662
* Convert SAP Netweaver RFC types into PHP/SAP types.
5763
* @param string $type The remote function parameter type.

0 commit comments

Comments
 (0)