4
4
5
5
namespace phpsap \saprfc \Traits ;
6
6
7
- use phpsap \classes \Api \Element ;
7
+ use phpsap \classes \Api \Member ;
8
8
use phpsap \classes \Api \Struct ;
9
9
use phpsap \classes \Api \Table ;
10
10
use phpsap \classes \Api \Value ;
11
11
use phpsap \exceptions \SapLogicException ;
12
- use phpsap \interfaces \Api \IElement ;
12
+ use phpsap \interfaces \Api \IApiElement ;
13
13
use phpsap \interfaces \Api \IStruct ;
14
14
use phpsap \interfaces \Api \ITable ;
15
15
use phpsap \interfaces \Api \IValue ;
16
+ use phpsap \interfaces \exceptions \IInvalidArgumentException ;
16
17
17
18
use function array_key_exists ;
18
19
use function is_array ;
@@ -29,37 +30,38 @@ trait ApiTrait
29
30
/**
30
31
* Create either Value, Struct or Table from a given remote function parameter
31
32
* or return value.
32
- * @param string $name The name of the parameter or return value.
33
- * @param string $type The type of the parameter or return value.
33
+ * @param string $name The name of the parameter or return value.
34
+ * @param string $type The type of the parameter or return value.
34
35
* @param string $direction The direction indicating whether it's a parameter or
35
36
* return value.
36
- * @param array $def The complete API value defintion from the module.
37
+ * @param array $def The complete API value defintion from the module.
37
38
* @return Value|Struct|Table
39
+ * @throws IInvalidArgumentException
38
40
*/
39
- private function createApiValue (string $ name , string $ type , string $ direction , array $ def )
41
+ private function createApiElement (string $ name , string $ type , string $ direction , array $ def ): Value | Table | Struct
40
42
{
41
43
$ optional = $ def ['optional ' ];
42
44
if ($ type === ITable::TYPE_TABLE ) {
43
- return new Table ($ name , $ direction , $ optional , $ this ->createMembers ($ def ));
45
+ return Table:: create ($ name , $ direction , $ optional , $ this ->createMembers ($ def ));
44
46
}
45
47
if ($ type === IStruct::TYPE_STRUCT ) {
46
- return new Struct ($ name , $ direction , $ optional , $ this ->createMembers ($ def ));
48
+ return Struct:: create ($ name , $ direction , $ optional , $ this ->createMembers ($ def ));
47
49
}
48
- return new Value ($ type , $ name , $ direction , $ optional );
50
+ return Value:: create ($ type , $ name , $ direction , $ optional );
49
51
}
50
52
51
53
/**
52
54
* Create either struct or table members from the def array of the remote function API.
53
55
* @param array $def The complete API value defintion.
54
- * @return Element [] An array of IElement compatible objects.
56
+ * @return Member [] An array of Member objects.
55
57
* @throws SapLogicException In case a datatype is missing in the mappings array.
56
58
*/
57
59
private function createMembers (array $ def ): array
58
60
{
59
61
$ result = [];
60
62
if (array_key_exists ('typedef ' , $ def ) && is_array ($ def ['typedef ' ])) {
61
63
foreach ($ def ['typedef ' ] as $ name => $ member ) {
62
- $ result [] = new Element ($ this ->mapType ($ member ['type ' ]), $ name );
64
+ $ result [] = Member:: create ($ this ->mapType ($ member ['type ' ]), $ name );
63
65
}
64
66
}
65
67
return $ result ;
@@ -74,18 +76,18 @@ private function createMembers(array $def): array
74
76
private function mapType (string $ type ): string
75
77
{
76
78
$ mapping = [
77
- 'RFCTYPE_DATE ' => IElement ::TYPE_DATE ,
78
- 'RFCTYPE_TIME ' => IElement ::TYPE_TIME ,
79
- 'RFCTYPE_INT ' => IElement ::TYPE_INTEGER ,
80
- 'RFCTYPE_NUM ' => IElement ::TYPE_INTEGER ,
81
- 'RFCTYPE_INT1 ' => IElement ::TYPE_INTEGER ,
82
- 'RFCTYPE_INT2 ' => IElement ::TYPE_INTEGER ,
83
- 'RFCTYPE_BCD ' => IElement ::TYPE_FLOAT ,
84
- 'RFCTYPE_FLOAT ' => IElement ::TYPE_FLOAT ,
85
- 'RFCTYPE_CHAR ' => IElement ::TYPE_STRING ,
86
- 'RFCTYPE_STRING ' => IElement ::TYPE_STRING ,
87
- 'RFCTYPE_BYTE ' => IElement ::TYPE_HEXBIN ,
88
- 'RFCTYPE_XSTRING ' => IElement ::TYPE_HEXBIN ,
79
+ 'RFCTYPE_DATE ' => IValue ::TYPE_DATE ,
80
+ 'RFCTYPE_TIME ' => IValue ::TYPE_TIME ,
81
+ 'RFCTYPE_INT ' => IValue ::TYPE_INTEGER ,
82
+ 'RFCTYPE_NUM ' => IValue ::TYPE_INTEGER ,
83
+ 'RFCTYPE_INT1 ' => IValue ::TYPE_INTEGER ,
84
+ 'RFCTYPE_INT2 ' => IValue ::TYPE_INTEGER ,
85
+ 'RFCTYPE_BCD ' => IValue ::TYPE_FLOAT ,
86
+ 'RFCTYPE_FLOAT ' => IValue ::TYPE_FLOAT ,
87
+ 'RFCTYPE_CHAR ' => IValue ::TYPE_STRING ,
88
+ 'RFCTYPE_STRING ' => IValue ::TYPE_STRING ,
89
+ 'RFCTYPE_BYTE ' => IValue ::TYPE_HEXBIN ,
90
+ 'RFCTYPE_XSTRING ' => IValue ::TYPE_HEXBIN ,
89
91
'RFCTYPE_STRUCTURE ' => IStruct::TYPE_STRUCT ,
90
92
'RFCTYPE_TABLE ' => ITable::TYPE_TABLE
91
93
];
@@ -104,8 +106,8 @@ private function mapType(string $type): string
104
106
private function mapDirection (string $ direction ): string
105
107
{
106
108
$ mapping = [
107
- 'RFC_EXPORT ' => IValue ::DIRECTION_OUTPUT ,
108
- 'RFC_IMPORT ' => IValue ::DIRECTION_INPUT ,
109
+ 'RFC_EXPORT ' => IApiElement ::DIRECTION_OUTPUT ,
110
+ 'RFC_IMPORT ' => IApiElement ::DIRECTION_INPUT ,
109
111
'RFC_TABLES ' => ITable::DIRECTION_TABLE
110
112
];
111
113
if (!array_key_exists ($ direction , $ mapping )) {
0 commit comments