Skip to content

Commit

Permalink
Add getFunctionDescription() of current master branch of Kraliks sapn…
Browse files Browse the repository at this point in the history
…wrfc 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.
:-)
  • Loading branch information
gregor-j committed Feb 18, 2020
1 parent c0173e9 commit 2b8308f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/SapRfc.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function extractApi(): RemoteApi
strtoupper($name),
$this->mapType($element['type']),
$this->mapDirection($element['direction']),
$element['optional']
$element
));
} catch (SapLogicException $exception) {
/**
Expand All @@ -184,7 +184,11 @@ public function extractApi(): RemoteApi
*/
public function saprfcFunctionInterface(): array
{
$result = get_object_vars($this->getFunction());
$function = $this->getFunction();
if (method_exists($function, 'getFunctionDescription')) {
return $function->getFunctionDescription();
}
$result = get_object_vars($function);
unset($result['name']);
return $result;
}
Expand Down
40 changes: 23 additions & 17 deletions src/Traits/ApiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace phpsap\saprfc\Traits;

use phpsap\classes\Api\Element;
use phpsap\classes\Api\Struct;
use phpsap\classes\Api\Table;
use phpsap\classes\Api\Value;
Expand All @@ -25,33 +26,38 @@ trait ApiTrait
* @param string $type The type of the parameter or return value.
* @param string $direction The direction indicating whether it's a parameter or
* return value.
* @param bool $optional The flag, whether this parameter or return value is
* required.
* @param array $def The complete API value defintion from the module.
* @return Value|Struct|Table
* @throws \phpsap\exceptions\SapLogicException
* @throws \phpsap\exceptions\InvalidArgumentException
*/
private function createApiValue($name, $type, $direction, $optional)
private function createApiValue($name, $type, $direction, $def)
{
$optional = $def['optional'];
if ($direction === IArray::DIRECTION_TABLE) {
/**
* The members array is empty because there is no information about it
* from the sapnwrfc module class.
* @todo Write to Gregor Kralik.
*/
return new Table($name, $optional, []);
return new Table($name, $optional, $this->createMembers($def));
}
if ($type === IArray::TYPE_ARRAY) {
/**
* The members array is empty because there is no information about it
* from the sapnwrfc module class.
* @todo Write to Gregor Kralik.
*/
return new Struct($name, $direction, $optional, []);
return new Struct($name, $direction, $optional, $this->createMembers($def));
}
return new Value($type, $name, $direction, $optional);
}

/**
* Create either struct or table members from the def array of the remote function API.
* @param array $def The complete API value defintion.
* @return \phpsap\classes\Api\Element[] An array of IElement compatible objects.
* @throws \phpsap\exceptions\SapLogicException In case a datatype is missing in the mappings array.
*/
private function createMembers($def): array
{
$result = [];
if (array_key_exists('typedef', $def) && is_array($def['typedef'])) {
foreach ($def['typedef'] as $name => $member) {
$result[] = new Element($this->mapType($member['type']), $name);
}
}
return $result;
}

/**
* Convert SAP Netweaver RFC types into PHP/SAP types.
* @param string $type The remote function parameter type.
Expand Down

0 comments on commit 2b8308f

Please sign in to comment.