Skip to content

Commit 11f476c

Browse files
authored
V2 (#1)
* introduce new functions to retrieve formerly set parameters and remove parameters from invoke() * introduce possibility to descript the remote function API * add constants and move value interface to common element interface * new API element hierarchy: value-element-array * Rename Interfaces and add comments for better understanding * Add exception for missing table elements * rename table element missing exception to array * add API interface and make API JSON serializeable Use API interface as return value and parameter for the API methods of the function interface. Make element interface JSON serializable and thus all children too. * add methods for adding API elements, values and arrays. * move IArray specific constants from IElement and IValue * combine all add() methods of the api interface * add json decode static functions * add json configuration keys * update comments of API specific methods. * add data types hex-bin and DateTime * split DateTime data type into date and time. * split hexbin to hex2bin and bin2hex for input and output directions The type would depend on the master type being either an input- or output- value. Tables are considered output values. * add virtual timestamp and week data types * update comments * rename const hex2bin to hexbin * fix typo * refactor configuration interfaces * Add JSON_* variables to be used for JSON encoded configurations. * Move methods handling the configuration to a separate interface. * Move configuration interfaces to a subdirectory. * Remove const TYPE from interfaces (the class names should do fine). * Remove incomplete configuration exception from configuration interfaces. This validation is expected to be job of the actual implementation. * Introduce jsonDecode() method as pendant to \JsonSerializeable interface. * refactor connection interface * Make connection JSON serializeable. * Add methods to retrieve the configuration class. * Remove getId() method. * Remove connect() isConnected() and close() methods because this should be handled by the actual implementation internally. * Remove ping() methods, because this is essentially a function call. * add JSON serialization of functions * add missing exceptions, reduce jsonDecode to string, update comments * unify comments * fix error in comment * overwrite cast() method for arrays * remove IConfiguration::getValidConfigKeys() * add JsonSerializable interface * Make all classes children of IJsonSerializable * make IFunction \JsonSerializable IJsonSerializable doesn't work because jsonDecode() requires a connection configuration as mandatory parameter to correctly decode a function. * remove addMember() from Api\IArray * remove connection class and adapt function class for configuration * rename retrieveApi() to extractApi() * fix line length * rename reset() to resetParams() and add missing exceptions * update comments * remove typecasting from IApi * Change default return of get*() in config class to null except for mandatory fields. * change order of methods and constants to reflect mandatory and optional properties * unify PHPdoc of methods * unify PHPdoc of methods * remove setParam() method and add the missing exceptions * fix typos and comments * fix typos and comments * fix typos and comments * update readme to v2 * set PHP versions
1 parent ebea601 commit 11f476c

23 files changed

+837
-353
lines changed

Diff for: README.md

-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44

55
This repository defines interfaces for implementing the [PHP/SAP][phpsap] API.
66

7-
[See PHP/SAP Interfaces for documentation][doc]
8-
97
[phpsap]: https://php-sap.github.io
108
[license-mit]: https://img.shields.io/badge/license-MIT-blue.svg
11-
[doc]: https://php-sap.github.io/interfaces "Interfaces | PHP/SAP"

Diff for: composer.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
}
1212
],
1313
"homepage": "https://php-sap.github.io",
14-
"support": {
15-
"docs": "https://php-sap.github.io/interfaces"
16-
},
1714
"keywords": [
1815
"phpsap",
1916
"php-sap",
@@ -24,7 +21,8 @@
2421
},
2522
"minimum-stability": "stable",
2623
"require": {
27-
"php": ">=5.5.0"
24+
"php": "^5.5|^7.0",
25+
"ext-json": "*"
2826
},
2927
"autoload": {
3028
"psr-4": {

Diff for: src/Api/IApi.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace phpsap\interfaces\Api;
4+
5+
use phpsap\interfaces\Util\IJsonSerializable;
6+
7+
/**
8+
* Interface IApi
9+
*
10+
* Describes the SAP remote function API. To be precise it describes the SAP remote
11+
* function call parameters (input), the returns (output) and the tables (input/
12+
* output).
13+
*
14+
* @package phpsap\interfaces
15+
* @author Gregor J.
16+
* @license MIT
17+
*/
18+
interface IApi extends IJsonSerializable
19+
{
20+
/**
21+
* Add a value, struct or table of the remote function.
22+
* @param \phpsap\interfaces\Api\IValue $value
23+
* @return $this
24+
*/
25+
public function add(IValue $value);
26+
27+
/**
28+
* Get all input values of the remote function.
29+
* @return \phpsap\interfaces\Api\IValue[]
30+
*/
31+
public function getInputValues();
32+
33+
/**
34+
* Get all output values of the remote function.
35+
* @return \phpsap\interfaces\Api\IValue[]
36+
*/
37+
public function getOutputValues();
38+
39+
/**
40+
* Get all tables of the remote function.
41+
* @return \phpsap\interfaces\Api\IArray[]
42+
*/
43+
public function getTables();
44+
}

Diff for: src/Api/IArray.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace phpsap\interfaces\Api;
4+
5+
/**
6+
* Interface IArray
7+
*
8+
* API extend the logic of values but contain member elements.
9+
*
10+
* @package phpsap\interfaces\Api
11+
* @author Gregor J.
12+
* @license MIT
13+
*/
14+
interface IArray extends IValue
15+
{
16+
/**
17+
* API table element.
18+
*/
19+
const DIRECTION_TABLE = 'table';
20+
21+
/**
22+
* API element that casts to PHP array.
23+
*/
24+
const TYPE_ARRAY = 'array';
25+
26+
/**
27+
* JSON configuration key for members array.
28+
*/
29+
const JSON_MEMBERS = 'members';
30+
31+
/**
32+
* Cast a given output value to the implemented value.
33+
* @param array $struct The output array to typecast.
34+
* @return array
35+
* @throws \phpsap\interfaces\exceptions\IArrayElementMissingException
36+
* @throws \phpsap\interfaces\exceptions\IInvalidArgumentException
37+
*/
38+
public function cast($struct);
39+
40+
/**
41+
* Return an array of member elements.
42+
* @return \phpsap\interfaces\Api\IElement[]
43+
*/
44+
public function getMembers();
45+
}

Diff for: src/Api/IElement.php

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace phpsap\interfaces\Api;
4+
5+
use phpsap\interfaces\Util\IJsonSerializable;
6+
7+
/**
8+
* Interface IElement
9+
*
10+
* API elements are struct or table members and have no direction or optional flag
11+
* of their own.
12+
*
13+
* @package phpsap\interfaces\Api
14+
* @author Gregor J.
15+
* @license MIT
16+
*/
17+
interface IElement extends IJsonSerializable
18+
{
19+
/**
20+
* API element that casts to PHP string.
21+
*/
22+
const TYPE_STRING = 'string';
23+
24+
/**
25+
* API element that casts to PHP int.
26+
*/
27+
const TYPE_INTEGER = 'int';
28+
29+
/**
30+
* API element that casts to PHP bool.
31+
*/
32+
const TYPE_BOOLEAN = 'bool';
33+
34+
/**
35+
* API element that casts to PHP float.
36+
*/
37+
const TYPE_FLOAT = 'float';
38+
39+
/**
40+
* API element that casts to a hexadecimal encoded binary to a binary.
41+
* (direction: output)
42+
*/
43+
const TYPE_HEXBIN = 'hexbin';
44+
45+
/**
46+
* API date element that casts to a DateTime object.
47+
*/
48+
const TYPE_DATE = 'date';
49+
50+
/**
51+
* API time element that casts to a DateTime object.
52+
*/
53+
const TYPE_TIME = 'time';
54+
55+
/**
56+
* API virtual timestamp element (e.g. string) that casts to a DateTime object.
57+
*/
58+
const TYPE_TIMESTAMP = 'timestamp';
59+
60+
/**
61+
* API virtual calendar week element (e.g. string) that casts to a DateTime object.
62+
*/
63+
const TYPE_WEEK = 'week';
64+
65+
/**
66+
* JSON configuration key for type value.
67+
*/
68+
const JSON_TYPE = 'type';
69+
70+
/**
71+
* JSON configuration key for name value.
72+
*/
73+
const JSON_NAME = 'name';
74+
75+
/**
76+
* The PHP type of the element.
77+
* @return string
78+
*/
79+
public function getType();
80+
81+
/**
82+
* The name of the element.
83+
* @return string
84+
*/
85+
public function getName();
86+
87+
/**
88+
* Cast a given output value to the implemented value.
89+
* @param bool|int|float|string $value The output to typecast.
90+
* @return bool|int|float|string|\phpsap\DateTime\SapDateTime
91+
* @throws \phpsap\interfaces\exceptions\IInvalidArgumentException
92+
*/
93+
public function cast($value);
94+
}

Diff for: src/Api/IValue.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace phpsap\interfaces\Api;
4+
5+
/**
6+
* Interface IValue
7+
*
8+
* API values extend the logic of an element but have a direction (input or output)
9+
* and an optional flag, unlike elements.
10+
*
11+
* @package phpsap\interfaces\Api
12+
* @author Gregor J.
13+
* @license MIT
14+
*/
15+
interface IValue extends IElement
16+
{
17+
/**
18+
* API input element.
19+
*/
20+
const DIRECTION_INPUT = 'input';
21+
22+
/**
23+
* API output element.
24+
*/
25+
const DIRECTION_OUTPUT = 'output';
26+
27+
/**
28+
* JSON configuration key for direction value.
29+
*/
30+
const JSON_DIRECTION = 'direction';
31+
32+
/**
33+
* JSON configuration key for is optional flag.
34+
*/
35+
const JSON_OPTIONAL = 'optional';
36+
37+
/**
38+
* Get the direction of the parameter.
39+
* interface.
40+
* @return string
41+
*/
42+
public function getDirection();
43+
44+
/**
45+
* Is the element optional?
46+
* @return bool
47+
*/
48+
public function isOptional();
49+
}

0 commit comments

Comments
 (0)