Skip to content

Commit 336c609

Browse files
committed
create common api element class for all data classes but members #10
1 parent 7ccf5c0 commit 336c609

File tree

5 files changed

+81
-179
lines changed

5 files changed

+81
-179
lines changed

src/Api/IApi.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
/**
1010
* Interface IApi
1111
*
12-
* Describes the SAP remote function API. To be precise it describes the SAP remote
13-
* function call parameters (input), the returns (output) and the tables (input/
14-
* output).
12+
* Describes the SAP remote function API. To be precise it describes the SAP
13+
* remote function call parameters (input), the returns (output), and the tables
14+
* (input/output/table).
1515
*
1616
* @package phpsap\interfaces
1717
* @author Gregor J.
@@ -21,26 +21,26 @@ interface IApi extends IJsonSerializable
2121
{
2222
/**
2323
* Add a value, struct or table of the remote function.
24-
* @param IValue $value
24+
* @param IApiElement $element
2525
* @return $this
2626
*/
27-
public function add(IValue $value): IApi;
27+
public function add(IApiElement $element): IApi;
2828

2929
/**
3030
* Get all input values of the remote function.
31-
* @return IValue[]
31+
* @return IApiElement[]
3232
*/
3333
public function getInputValues(): array;
3434

3535
/**
3636
* Get all output values of the remote function.
37-
* @return IValue[]
37+
* @return IApiElement[]
3838
*/
3939
public function getOutputValues(): array;
4040

4141
/**
4242
* Get all tables of the remote function.
43-
* @return ITable[]
43+
* @return IApiElement[]
4444
*/
4545
public function getTables(): array;
4646
}

src/Api/IApiElement.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpsap\interfaces\Api;
6+
7+
use phpsap\interfaces\Util\IJsonSerializable;
8+
9+
/**
10+
* Interface IApiElement
11+
* Common interface for elements of an API: IValue, IStruct and ITable.
12+
*/
13+
interface IApiElement extends IJsonSerializable
14+
{
15+
/**
16+
* JSON configuration key for type value.
17+
*/
18+
public const JSON_TYPE = 'type';
19+
20+
/**
21+
* JSON configuration key for name value.
22+
*/
23+
public const JSON_NAME = 'name';
24+
25+
/**
26+
* JSON configuration key for direction value.
27+
*/
28+
public const JSON_DIRECTION = 'direction';
29+
30+
/**
31+
* JSON configuration key for is optional flag.
32+
*/
33+
public const JSON_OPTIONAL = 'optional';
34+
35+
/**
36+
* API input element.
37+
*/
38+
public const DIRECTION_INPUT = 'input';
39+
40+
/**
41+
* API output element.
42+
*/
43+
public const DIRECTION_OUTPUT = 'output';
44+
45+
46+
/**
47+
* The PHP type of the element.
48+
* @return string
49+
*/
50+
public function getType(): string;
51+
52+
/**
53+
* The name of the element.
54+
* @return string
55+
*/
56+
public function getName(): string;
57+
58+
/**
59+
* Get the direction of the parameter.
60+
* interface.
61+
* @return string
62+
*/
63+
public function getDirection(): string;
64+
65+
/**
66+
* Is the element optional?
67+
* @return bool
68+
*/
69+
public function isOptional(): bool;
70+
}

src/Api/IStruct.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use phpsap\interfaces\exceptions\IArrayElementMissingException;
88
use phpsap\interfaces\exceptions\IInvalidArgumentException;
9-
use phpsap\interfaces\Util\IJsonSerializable;
109

1110
/**
1211
* Interface IStruct
@@ -17,43 +16,13 @@
1716
* @author Gregor J.
1817
* @license MIT
1918
*/
20-
interface IStruct extends IJsonSerializable
19+
interface IStruct extends IApiElement
2120
{
2221
/**
2322
* API element that casts to an associative array in PHP.
2423
*/
2524
public const TYPE_STRUCT = 'struct';
2625

27-
/**
28-
* API input element.
29-
*/
30-
public const DIRECTION_INPUT = 'input';
31-
32-
/**
33-
* API output element.
34-
*/
35-
public const DIRECTION_OUTPUT = 'output';
36-
37-
/**
38-
* JSON configuration key for type value.
39-
*/
40-
public const JSON_TYPE = 'type';
41-
42-
/**
43-
* JSON configuration key for name value.
44-
*/
45-
public const JSON_NAME = 'name';
46-
47-
/**
48-
* JSON configuration key for direction value.
49-
*/
50-
public const JSON_DIRECTION = 'direction';
51-
52-
/**
53-
* JSON configuration key for is optional flag.
54-
*/
55-
public const JSON_OPTIONAL = 'optional';
56-
5726
/**
5827
* JSON configuration key for members array.
5928
*/
@@ -77,31 +46,6 @@ public function __construct(array $array);
7746
*/
7847
public static function create(string $name, string $direction, bool $isOptional, array $members): IStruct;
7948

80-
/**
81-
* The PHP type of the element.
82-
* @return string
83-
*/
84-
public function getType(): string;
85-
86-
/**
87-
* The name of the element.
88-
* @return string
89-
*/
90-
public function getName(): string;
91-
92-
/**
93-
* Get the direction of the parameter.
94-
* interface.
95-
* @return string
96-
*/
97-
public function getDirection(): string;
98-
99-
/**
100-
* Is the element optional?
101-
* @return bool
102-
*/
103-
public function isOptional(): bool;
104-
10549
/**
10650
* Returns an array of members.
10751
* @return IMember[]

src/Api/ITable.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use phpsap\interfaces\exceptions\IArrayElementMissingException;
88
use phpsap\interfaces\exceptions\IInvalidArgumentException;
9-
use phpsap\interfaces\Util\IJsonSerializable;
109

1110
/**
1211
* Interface ITable
@@ -17,7 +16,7 @@
1716
* @author Gregor J.
1817
* @license MIT
1918
*/
20-
interface ITable extends IJsonSerializable
19+
interface ITable extends IApiElement
2120
{
2221
/**
2322
* API element that casts to a PHP array of associative arrays.
@@ -29,36 +28,6 @@ interface ITable extends IJsonSerializable
2928
*/
3029
public const DIRECTION_TABLE = 'table';
3130

32-
/**
33-
* API input element.
34-
*/
35-
public const DIRECTION_INPUT = 'input';
36-
37-
/**
38-
* API output element.
39-
*/
40-
public const DIRECTION_OUTPUT = 'output';
41-
42-
/**
43-
* JSON configuration key for type value.
44-
*/
45-
public const JSON_TYPE = 'type';
46-
47-
/**
48-
* JSON configuration key for name value.
49-
*/
50-
public const JSON_NAME = 'name';
51-
52-
/**
53-
* JSON configuration key for direction value.
54-
*/
55-
public const JSON_DIRECTION = 'direction';
56-
57-
/**
58-
* JSON configuration key for is optional flag.
59-
*/
60-
public const JSON_OPTIONAL = 'optional';
61-
6231
/**
6332
* JSON configuration key for members array.
6433
*/
@@ -82,31 +51,6 @@ public function __construct(array $array);
8251
*/
8352
public static function create(string $name, string $direction, bool $isOptional, array $members): ITable;
8453

85-
/**
86-
* The PHP type of the element.
87-
* @return string
88-
*/
89-
public function getType(): string;
90-
91-
/**
92-
* The name of the element.
93-
* @return string
94-
*/
95-
public function getName(): string;
96-
97-
/**
98-
* Get the direction of the parameter.
99-
* interface.
100-
* @return string
101-
*/
102-
public function getDirection(): string;
103-
104-
/**
105-
* Is the element optional?
106-
* @return bool
107-
*/
108-
public function isOptional(): bool;
109-
11054
/**
11155
* Returns an array of an array of members.
11256
* @return IMember[]

src/Api/IValue.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use DateInterval;
88
use DateTime;
99
use phpsap\interfaces\exceptions\IInvalidArgumentException;
10-
use phpsap\interfaces\Util\IJsonSerializable;
1110

1211
/**
1312
* Interface IValue
@@ -18,7 +17,7 @@
1817
* @author Gregor J.
1918
* @license MIT
2019
*/
21-
interface IValue extends IJsonSerializable
20+
interface IValue extends IApiElement
2221
{
2322
/**
2423
* API element that casts to PHP bool.
@@ -66,36 +65,6 @@ interface IValue extends IJsonSerializable
6665
*/
6766
public const TYPE_WEEK = 'week';
6867

69-
/**
70-
* API input element.
71-
*/
72-
public const DIRECTION_INPUT = 'input';
73-
74-
/**
75-
* API output element.
76-
*/
77-
public const DIRECTION_OUTPUT = 'output';
78-
79-
/**
80-
* JSON configuration key for type value.
81-
*/
82-
public const JSON_TYPE = 'type';
83-
84-
/**
85-
* JSON configuration key for name value.
86-
*/
87-
public const JSON_NAME = 'name';
88-
89-
/**
90-
* JSON configuration key for direction value.
91-
*/
92-
public const JSON_DIRECTION = 'direction';
93-
94-
/**
95-
* JSON configuration key for is optional flag.
96-
*/
97-
public const JSON_OPTIONAL = 'optional';
98-
9968
/**
10069
* Initialize this class from an array.
10170
* @param array<string, string|bool> $array Array containing the properties of this class.
@@ -114,31 +83,6 @@ public function __construct(array $array);
11483
*/
11584
public static function create(string $type, string $name, string $direction, bool $isOptional): IValue;
11685

117-
/**
118-
* The PHP type of the element.
119-
* @return string
120-
*/
121-
public function getType(): string;
122-
123-
/**
124-
* The name of the element.
125-
* @return string
126-
*/
127-
public function getName(): string;
128-
129-
/**
130-
* Get the direction of the parameter.
131-
* interface.
132-
* @return string
133-
*/
134-
public function getDirection(): string;
135-
136-
/**
137-
* Is the element optional?
138-
* @return bool
139-
*/
140-
public function isOptional(): bool;
141-
14286
/**
14387
* Cast a given value according to this class.
14488
* @param float|bool|int|string $value The value to typecast.

0 commit comments

Comments
 (0)