22
33namespace phpsap \saprfc \Traits ;
44
5+ use phpsap \classes \Api \Element ;
56use phpsap \classes \Api \Struct ;
67use phpsap \classes \Api \Table ;
78use 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