Skip to content

Commit 0b2c852

Browse files
committed
Revert "refactor API interfaces #10"
This reverts commit 3c18ea1.
1 parent 39c266d commit 0b2c852

File tree

5 files changed

+69
-77
lines changed

5 files changed

+69
-77
lines changed

src/Api/IArray.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
/**
1111
* Interface IArray
1212
*
13-
* API arrays extend the logic of elements to contain member elements. They are
14-
* the basis for structs and tables.
13+
* API extend the logic of values to contain member elements.
1514
*
1615
* @package phpsap\interfaces\Api
1716
* @author Gregor J.
1817
* @license MIT
1918
*/
20-
interface IArray extends IElement
19+
interface IArray extends IValue
2120
{
2221
/**
2322
* JSON configuration key for members array.
@@ -26,12 +25,12 @@ interface IArray extends IElement
2625

2726
/**
2827
* Cast a given output value to the implemented value.
29-
* @param array<int|string, mixed> $value The output array to typecast.
30-
* @return array<int|string, mixed>
28+
* @param array $value The output array to typecast.
29+
* @return array
3130
* @throws IArrayElementMissingException
3231
* @throws IInvalidArgumentException
3332
*/
34-
public function cast(array $value): array;
33+
public function cast($value): array;
3534

3635
/**
3736
* Return an array of member elements.

src/Api/IElement.php

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
/**
1313
* Interface IElement
1414
*
15-
* API elements build the basis for API values, structs and tables. They have a
16-
* name, a type, a direction and an optional flag. However, they don't contain
17-
* any values.
15+
* API elements are struct or table members and have no direction or optional flag
16+
* of their own.
1817
*
1918
* @package phpsap\interfaces\Api
2019
* @author Gregor J.
@@ -23,34 +22,60 @@
2322
interface IElement extends IJsonSerializable
2423
{
2524
/**
26-
* JSON configuration key for type value.
25+
* API element that casts to PHP string.
2726
*/
28-
public const JSON_TYPE = 'type';
27+
public const TYPE_STRING = 'string';
2928

3029
/**
31-
* JSON configuration key for name value.
30+
* API element that casts to PHP int.
3231
*/
33-
public const JSON_NAME = 'name';
32+
public const TYPE_INTEGER = 'int';
33+
34+
/**
35+
* API element that casts to PHP bool.
36+
*/
37+
public const TYPE_BOOLEAN = 'bool';
3438

3539
/**
36-
* API input element.
40+
* API element that casts to PHP float.
3741
*/
38-
public const DIRECTION_INPUT = 'input';
42+
public const TYPE_FLOAT = 'float';
3943

4044
/**
41-
* API output element.
45+
* API element that casts to a hexadecimal encoded binary to a binary.
46+
* (direction: output)
4247
*/
43-
public const DIRECTION_OUTPUT = 'output';
48+
public const TYPE_HEXBIN = 'hexbin';
4449

4550
/**
46-
* JSON configuration key for direction value.
51+
* API date element that casts to a DateTime object.
4752
*/
48-
public const JSON_DIRECTION = 'direction';
53+
public const TYPE_DATE = 'date';
4954

5055
/**
51-
* JSON configuration key for is optional flag.
56+
* API time element that casts to a DateTime object.
5257
*/
53-
public const JSON_OPTIONAL = 'optional';
58+
public const TYPE_TIME = 'time';
59+
60+
/**
61+
* API virtual timestamp element (e.g. string) that casts to a DateTime object.
62+
*/
63+
public const TYPE_TIMESTAMP = 'timestamp';
64+
65+
/**
66+
* API virtual calendar week element (e.g. string) that casts to a DateTime object.
67+
*/
68+
public const TYPE_WEEK = 'week';
69+
70+
/**
71+
* JSON configuration key for type value.
72+
*/
73+
public const JSON_TYPE = 'type';
74+
75+
/**
76+
* JSON configuration key for name value.
77+
*/
78+
public const JSON_NAME = 'name';
5479

5580
/**
5681
* The PHP type of the element.
@@ -65,15 +90,10 @@ public function getType(): string;
6590
public function getName(): string;
6691

6792
/**
68-
* Get the direction of the parameter.
69-
* interface.
70-
* @return string
71-
*/
72-
public function getDirection(): string;
73-
74-
/**
75-
* Is the element optional?
76-
* @return bool
93+
* Cast a given output value to the implemented value.
94+
* @param bool|int|float|string $value The output to typecast.
95+
* @return bool|int|float|string|SapDateTime|SapDateInterval
96+
* @throws IInvalidArgumentException
7797
*/
78-
public function isOptional(): bool;
98+
public function cast($value);
7999
}

src/Api/IStruct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Interface IStruct
99
*
10-
* API structs extend the logic of arrays to contain an associative array.
10+
* API extend the logic of arrays to contain member elements.
1111
*
1212
* @package phpsap\interfaces\Api
1313
* @author Gregor J.

src/Api/ITable.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
/**
88
* Interface ITable
99
*
10-
* API tables extend the logic of arrays to contain an array of associative
11-
* arrays.
10+
* API extend the logic of arrays but contains rows of member elements.
1211
*
1312
* @package phpsap\interfaces\Api
1413
* @author Gregor J.

src/Api/IValue.php

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55
namespace phpsap\interfaces\Api;
66

7-
use phpsap\DateTime\SapDateInterval;
8-
use phpsap\DateTime\SapDateTime;
9-
use phpsap\interfaces\exceptions\IInvalidArgumentException;
10-
117
/**
128
* Interface IValue
139
*
14-
* API values extend the logic of an element. They describe primitive values,
15-
* like integers, booleans, strings, etc., but also more complex values, like
16-
* date and time, or intervals.
10+
* API values extend the logic of an element but have a direction (input or output)
11+
* and an optional flag, unlike elements.
1712
*
1813
* @package phpsap\interfaces\Api
1914
* @author Gregor J.
@@ -22,56 +17,35 @@
2217
interface IValue extends IElement
2318
{
2419
/**
25-
* API element that casts to PHP string.
26-
*/
27-
public const TYPE_STRING = 'string';
28-
29-
/**
30-
* API element that casts to PHP int.
31-
*/
32-
public const TYPE_INTEGER = 'int';
33-
34-
/**
35-
* API element that casts to PHP bool.
36-
*/
37-
public const TYPE_BOOLEAN = 'bool';
38-
39-
/**
40-
* API element that casts to PHP float.
41-
*/
42-
public const TYPE_FLOAT = 'float';
43-
44-
/**
45-
* API element that casts to a hexadecimal encoded binary to a binary.
46-
* (direction: output)
20+
* API input element.
4721
*/
48-
public const TYPE_HEXBIN = 'hexbin';
22+
public const DIRECTION_INPUT = 'input';
4923

5024
/**
51-
* API date element that casts to a DateTime object.
25+
* API output element.
5226
*/
53-
public const TYPE_DATE = 'date';
27+
public const DIRECTION_OUTPUT = 'output';
5428

5529
/**
56-
* API time element that casts to a DateTime object.
30+
* JSON configuration key for direction value.
5731
*/
58-
public const TYPE_TIME = 'time';
32+
public const JSON_DIRECTION = 'direction';
5933

6034
/**
61-
* API virtual timestamp element (e.g. string) that casts to a DateTime object.
35+
* JSON configuration key for is optional flag.
6236
*/
63-
public const TYPE_TIMESTAMP = 'timestamp';
37+
public const JSON_OPTIONAL = 'optional';
6438

6539
/**
66-
* API virtual calendar week element (e.g. string) that casts to a DateTime object.
40+
* Get the direction of the parameter.
41+
* interface.
42+
* @return string
6743
*/
68-
public const TYPE_WEEK = 'week';
44+
public function getDirection(): string;
6945

7046
/**
71-
* Cast a given output value to the implemented value.
72-
* @param bool|int|float|string $value The output to typecast.
73-
* @return bool|int|float|string|SapDateTime|SapDateInterval
74-
* @throws IInvalidArgumentException
47+
* Is the element optional?
48+
* @return bool
7549
*/
76-
public function cast(bool|int|float|string $value): bool|int|float|string|SapDateTime|SapDateInterval;
50+
public function isOptional(): bool;
7751
}

0 commit comments

Comments
 (0)