11
11
use phpsap \exceptions \IncompleteConfigException ;
12
12
use phpsap \exceptions \SapLogicException ;
13
13
use phpsap \exceptions \UnknownFunctionException ;
14
+ use phpsap \interfaces \Config \IConfiguration ;
14
15
use phpsap \interfaces \exceptions \IIncompleteConfigException ;
15
16
use phpsap \interfaces \exceptions \IInvalidArgumentException ;
16
17
use phpsap \saprfc \Traits \ApiTrait ;
20
21
use SAPNWRFC \ConnectionException as ModuleConnectionException ;
21
22
use SAPNWRFC \FunctionCallException as ModuleFunctionCallException ;
22
23
use SAPNWRFC \RemoteFunction ;
24
+ use TypeError ;
23
25
24
26
use function array_merge ;
25
27
use function get_object_vars ;
@@ -133,14 +135,19 @@ protected function getConnection(): Connection
133
135
try {
134
136
if ($ config ->getTrace () !== null ) {
135
137
/**
136
- * \SAPNWRFC\Connection::TRACE_LEVEL_* uses the same values
137
- * as \phpsap\interfaces\Config\IConfigCommon::TRACE_*.
138
- * Therefore, no mapping is necessary.
138
+ * SAPNWRFC introduced TRACE_DETAILED (3) in v2.1.0 which
139
+ * is not available via the interface.
139
140
*/
140
- Connection::setTraceLevel ($ config ->getTrace ());
141
+ $ trace = match ($ config ->getTrace ()) {
142
+ IConfiguration::TRACE_FULL => 4 ,
143
+ IConfiguration::TRACE_VERBOSE => 2 ,
144
+ IConfiguration::TRACE_BRIEF => 1 ,
145
+ default => 0 ,
146
+ };
147
+ Connection::setTraceLevel ($ trace );
141
148
}
142
149
$ this ->connection = new Connection ($ moduleConfig );
143
- } catch (ModuleConnectionException $ exception ) {
150
+ } catch (TypeError | ModuleConnectionException $ exception ) {
144
151
throw new ConnectionFailedException (sprintf (
145
152
'Connection creation failed: %s ' ,
146
153
$ exception ->getMessage ()
@@ -155,9 +162,6 @@ protected function getConnection(): Connection
155
162
*/
156
163
public function extractApi (): RemoteApi
157
164
{
158
- /**
159
- * InvalidArgumentException is never thrown, because no parameter is given.
160
- */
161
165
$ api = new RemoteApi ();
162
166
foreach ($ this ->saprfcFunctionInterface () as $ name => $ element ) {
163
167
try {
@@ -192,13 +196,7 @@ public function extractApi(): RemoteApi
192
196
*/
193
197
public function saprfcFunctionInterface (): array
194
198
{
195
- $ function = $ this ->getFunction ();
196
- if (method_exists ($ function , 'getFunctionDescription ' )) {
197
- return $ function ->getFunctionDescription ();
198
- }
199
- $ result = get_object_vars ($ function );
200
- unset($ result ['name ' ]);
201
- return $ result ;
199
+ return $ this ->getFunction ()->getFunctionDescription ();
202
200
}
203
201
204
202
/**
@@ -227,7 +225,7 @@ public function invoke(): array
227
225
$ result = $ this
228
226
->getFunction ()
229
227
->invoke ($ params , self ::$ invokeOptions );
230
- } catch (ModuleFunctionCallException $ exception ) {
228
+ } catch (TypeError | ModuleFunctionCallException $ exception ) {
231
229
throw new FunctionCallException (sprintf (
232
230
'Function call %s failed: %s ' ,
233
231
$ this ->getName (),
0 commit comments