-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIFunction.php
185 lines (168 loc) · 6.21 KB
/
IFunction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
declare(strict_types=1);
namespace phpsap\interfaces;
use phpsap\interfaces\Api\IApi;
use phpsap\interfaces\Config\IConfiguration;
use phpsap\interfaces\exceptions\IConnectionFailedException;
use phpsap\interfaces\exceptions\IFunctionCallException;
use phpsap\interfaces\exceptions\IIncompleteConfigException;
use phpsap\interfaces\exceptions\IInvalidArgumentException;
use phpsap\interfaces\exceptions\IUnknownFunctionException;
use phpsap\interfaces\Util\IJsonSerializable;
/**
* Interface IFunction
*
* Prepare and invoke a SAP remote function call.
*
* As with all classes of this package, this class can be serialized using
* json_encode() and unserialized using the static method IFunction::jsonDecode().
*
* @package phpsap\interfaces
* @author Gregor J.
* @license MIT
*/
interface IFunction extends IJsonSerializable
{
/**
* JSON configuration key for the SAP remote function name.
*/
public const JSON_NAME = 'name';
/**
* JSON configuration key for the SAP remote function API.
*/
public const JSON_API = 'api';
/**
* JSON configuration key for the SAP remote function call parameters.
*/
public const JSON_PARAM = 'params';
/**
* Create a remote function call with at least a name.
*
* In order to add SAP remote function call parameters, an API needs to be
* present. In case no SAP remote function call API has been defined, it will be
* queried on the fly by connecting to the SAP remote system. In order to
* connect to the SAP remote system, a SAP connection configuration needs to be
* present.
*
* @param string $name SAP remote function name.
* @param array<string, mixed>|null $params SAP remote function call parameters. Default: null
* @param IConfiguration|null $config SAP connection configuration. Default: null
* @param IApi|null $api SAP remote function call API. Default: null
* @throws IInvalidArgumentException
* @throws IIncompleteConfigException
* @throws IConnectionFailedException
* @throws IUnknownFunctionException
*/
public static function create(string $name, array $params = null, IConfiguration $config = null, IApi $api = null): IFunction;
/**
* Get the SAP remote function name.
* @return string
*/
public function getName(): string;
/**
* Get the SAP connection configuration for this remote function.
*
* In case no configuration has been set, null will be returned.
*
* @return IConfiguration|null
*/
public function getConfiguration(): ?IConfiguration;
/**
* Set the SAP connection configuration for this remote function.
*
* Using this configuration, the SAP remote function API can be queried and
* SAP remote function calls can be invoked.
*
* @param IConfiguration $config
* @return $this
*/
public function setConfiguration(IConfiguration $config): IFunction;
/**
* Connect to the SAP remote system and extract the API of the SAP remote
* function.
*
* In order to query the SAP remote system and extract the API of the SAP remote
* function, a connection configuration needs to be present. Use
* setConfiguration() to set the connection configuration.
*
* This method ignores the cached API of this class and doesn't overwrite it.
* Every time this method is called, it will query the SAP remote system and
* extract the API of the SAP remote function.
*
* @return IApi
* @throws IIncompleteConfigException
* @throws IConnectionFailedException
* @throws IUnknownFunctionException
*/
public function extractApi(): IApi;
/**
* Get the remote function API.
*
* In case no SAP remote function call API has been defined using setApi(), it
* will be queried on the fly using extractApi() the first time this method is
* called.
*
* In case extractApi() has to be called, a connection configuration needs to be
* present. Use setConfiguration() to set the connection configuration.
*
* @return IApi
* @throws IIncompleteConfigException
* @throws IConnectionFailedException
* @throws IUnknownFunctionException
*/
public function getApi(): IApi;
/**
* Set the SAP remote function API (e.g. from cache).
*
* By setting the API, it will not be queried from the SAP remote system when
* calling getApi(). Instead, getApi() will return whatever has been set using
* this method.
*
* @param IApi $api
* @return $this
*/
public function setApi(IApi $api): IFunction;
/**
* Returns all previously set parameters.
*
* @return array<string, mixed> Associative array of all parameters that have been set.
*/
public function getParams(): array;
/**
* Extract all expected SAP remote function call parameters from the given array
* and merge them with the existing ones.
*
* The expected SAP remote function call parameters are queried using getApi(),
* therefore either a remote API needs to be set using setApi(), or a SAP
* connection configuration for this remote function needs to be set using
* setConfiguration().
*
* @param array<string, mixed> $params An array of SAP remote function call parameters.
* @return $this
* @throws IInvalidArgumentException
* @throws IIncompleteConfigException
* @throws IConnectionFailedException
* @throws IUnknownFunctionException
*/
public function setParams(array $params): IFunction;
/**
* Remove all SAP remote function call parameters that have been set before
* and start over.
*
* @return $this
*/
public function resetParams(): IFunction;
/**
* Invoke the SAP remote function call.
*
* A SAP connection configuration needs to be present for a remote function
* call. Use setConfiguration() to set the connection configuration.
*
* @return array<string, mixed>
* @throws IIncompleteConfigException
* @throws IConnectionFailedException
* @throws IUnknownFunctionException
* @throws IFunctionCallException
*/
public function invoke(): array;
}