Skip to content

Commit 9e19958

Browse files
committed
adapt to new interface and common library
1 parent 82460a6 commit 9e19958

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

src/SapRfc.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ protected function getConnection(): Connection
124124
} catch (IIncompleteConfigException $exception) {
125125
throw new IncompleteConfigException(
126126
$exception->getMessage(),
127-
$exception->getCode(),
128-
$exception
127+
$exception->getCode()
129128
);
130129
}
131130
/**
@@ -134,9 +133,9 @@ protected function getConnection(): Connection
134133
try {
135134
if ($config->getTrace() !== null) {
136135
/**
137-
* \SAPNWRFC\Connection::TRACE_LEVEL_* uses the same values as
138-
* \phpsap\interfaces\Config\IConfigCommon::TRACE_*. Therefore
139-
* no mapping is necessary.
136+
* \SAPNWRFC\Connection::TRACE_LEVEL_* uses the same values
137+
* as \phpsap\interfaces\Config\IConfigCommon::TRACE_*.
138+
* Therefore, no mapping is necessary.
140139
*/
141140
Connection::setTraceLevel($config->getTrace());
142141
}
@@ -162,13 +161,13 @@ public function extractApi(): RemoteApi
162161
$api = new RemoteApi();
163162
foreach ($this->saprfcFunctionInterface() as $name => $element) {
164163
try {
165-
$api->add($this->createApiValue(
164+
$api->add($this->createApiElement(
166165
strtoupper($name),
167166
$this->mapType($element['type']),
168167
$this->mapDirection($element['direction']),
169168
$element
170169
));
171-
} catch (SapLogicException $exception) {
170+
} catch (IInvalidArgumentException | SapLogicException $exception) {
172171
/**
173172
* InvalidArgumentException is a child of SapLogicException and will
174173
* be caught too.
@@ -213,7 +212,7 @@ public function invoke(): array
213212
*/
214213
$params = array_merge(
215214
$this->getInputParams(
216-
$this->getApi()->getInputValues(),
215+
$this->getApi()->getInputElements(),
217216
$this->getParams()
218217
),
219218
$this->getTableParams(
@@ -238,8 +237,8 @@ public function invoke(): array
238237
/**
239238
* Typecast the return values.
240239
*/
241-
return $this->castOutputValues(array_merge(
242-
$this->getApi()->getOutputValues(),
240+
return $this->castOutput(array_merge(
241+
$this->getApi()->getOutputElements(),
243242
$this->getApi()->getTables()
244243
), $result);
245244
}

src/Traits/ApiTrait.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
namespace phpsap\saprfc\Traits;
66

7-
use phpsap\classes\Api\Element;
7+
use phpsap\classes\Api\Member;
88
use phpsap\classes\Api\Struct;
99
use phpsap\classes\Api\Table;
1010
use phpsap\classes\Api\Value;
1111
use phpsap\exceptions\SapLogicException;
12-
use phpsap\interfaces\Api\IElement;
12+
use phpsap\interfaces\Api\IApiElement;
1313
use phpsap\interfaces\Api\IStruct;
1414
use phpsap\interfaces\Api\ITable;
1515
use phpsap\interfaces\Api\IValue;
16+
use phpsap\interfaces\exceptions\IInvalidArgumentException;
1617

1718
use function array_key_exists;
1819
use function is_array;
@@ -29,37 +30,38 @@ trait ApiTrait
2930
/**
3031
* Create either Value, Struct or Table from a given remote function parameter
3132
* or return value.
32-
* @param string $name The name of the parameter or return value.
33-
* @param string $type The type of the parameter or return value.
33+
* @param string $name The name of the parameter or return value.
34+
* @param string $type The type of the parameter or return value.
3435
* @param string $direction The direction indicating whether it's a parameter or
3536
* return value.
36-
* @param array $def The complete API value defintion from the module.
37+
* @param array $def The complete API value defintion from the module.
3738
* @return Value|Struct|Table
39+
* @throws IInvalidArgumentException
3840
*/
39-
private function createApiValue(string $name, string $type, string $direction, array $def)
41+
private function createApiElement(string $name, string $type, string $direction, array $def): Value|Table|Struct
4042
{
4143
$optional = $def['optional'];
4244
if ($type === ITable::TYPE_TABLE) {
43-
return new Table($name, $direction, $optional, $this->createMembers($def));
45+
return Table::create($name, $direction, $optional, $this->createMembers($def));
4446
}
4547
if ($type === IStruct::TYPE_STRUCT) {
46-
return new Struct($name, $direction, $optional, $this->createMembers($def));
48+
return Struct::create($name, $direction, $optional, $this->createMembers($def));
4749
}
48-
return new Value($type, $name, $direction, $optional);
50+
return Value::create($type, $name, $direction, $optional);
4951
}
5052

5153
/**
5254
* Create either struct or table members from the def array of the remote function API.
5355
* @param array $def The complete API value defintion.
54-
* @return Element[] An array of IElement compatible objects.
56+
* @return Member[] An array of Member objects.
5557
* @throws SapLogicException In case a datatype is missing in the mappings array.
5658
*/
5759
private function createMembers(array $def): array
5860
{
5961
$result = [];
6062
if (array_key_exists('typedef', $def) && is_array($def['typedef'])) {
6163
foreach ($def['typedef'] as $name => $member) {
62-
$result[] = new Element($this->mapType($member['type']), $name);
64+
$result[] = Member::create($this->mapType($member['type']), $name);
6365
}
6466
}
6567
return $result;
@@ -74,18 +76,18 @@ private function createMembers(array $def): array
7476
private function mapType(string $type): string
7577
{
7678
$mapping = [
77-
'RFCTYPE_DATE' => IElement::TYPE_DATE,
78-
'RFCTYPE_TIME' => IElement::TYPE_TIME,
79-
'RFCTYPE_INT' => IElement::TYPE_INTEGER,
80-
'RFCTYPE_NUM' => IElement::TYPE_INTEGER,
81-
'RFCTYPE_INT1' => IElement::TYPE_INTEGER,
82-
'RFCTYPE_INT2' => IElement::TYPE_INTEGER,
83-
'RFCTYPE_BCD' => IElement::TYPE_FLOAT,
84-
'RFCTYPE_FLOAT' => IElement::TYPE_FLOAT,
85-
'RFCTYPE_CHAR' => IElement::TYPE_STRING,
86-
'RFCTYPE_STRING' => IElement::TYPE_STRING,
87-
'RFCTYPE_BYTE' => IElement::TYPE_HEXBIN,
88-
'RFCTYPE_XSTRING' => IElement::TYPE_HEXBIN,
79+
'RFCTYPE_DATE' => IValue::TYPE_DATE,
80+
'RFCTYPE_TIME' => IValue::TYPE_TIME,
81+
'RFCTYPE_INT' => IValue::TYPE_INTEGER,
82+
'RFCTYPE_NUM' => IValue::TYPE_INTEGER,
83+
'RFCTYPE_INT1' => IValue::TYPE_INTEGER,
84+
'RFCTYPE_INT2' => IValue::TYPE_INTEGER,
85+
'RFCTYPE_BCD' => IValue::TYPE_FLOAT,
86+
'RFCTYPE_FLOAT' => IValue::TYPE_FLOAT,
87+
'RFCTYPE_CHAR' => IValue::TYPE_STRING,
88+
'RFCTYPE_STRING' => IValue::TYPE_STRING,
89+
'RFCTYPE_BYTE' => IValue::TYPE_HEXBIN,
90+
'RFCTYPE_XSTRING' => IValue::TYPE_HEXBIN,
8991
'RFCTYPE_STRUCTURE' => IStruct::TYPE_STRUCT,
9092
'RFCTYPE_TABLE' => ITable::TYPE_TABLE
9193
];
@@ -104,8 +106,8 @@ private function mapType(string $type): string
104106
private function mapDirection(string $direction): string
105107
{
106108
$mapping = [
107-
'RFC_EXPORT' => IValue::DIRECTION_OUTPUT,
108-
'RFC_IMPORT' => IValue::DIRECTION_INPUT,
109+
'RFC_EXPORT' => IApiElement::DIRECTION_OUTPUT,
110+
'RFC_IMPORT' => IApiElement::DIRECTION_INPUT,
109111
'RFC_TABLES' => ITable::DIRECTION_TABLE
110112
];
111113
if (!array_key_exists($direction, $mapping)) {

src/Traits/ConfigTrait.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
namespace phpsap\saprfc\Traits;
66

7-
use phpsap\interfaces\Config\IConfigCommon;
7+
use phpsap\exceptions\IncompleteConfigException;
88
use phpsap\interfaces\Config\IConfigTypeA;
99
use phpsap\interfaces\Config\IConfigTypeB;
1010
use phpsap\interfaces\Config\IConfiguration;
1111
use phpsap\interfaces\exceptions\IIncompleteConfigException;
1212

1313
use function array_merge;
14+
use function get_class;
1415

1516
/**
1617
* Trait ConfigTrait
@@ -47,7 +48,10 @@ private function getSpecificConfig(IConfiguration $config): array
4748
if ($config instanceof IConfigTypeA) {
4849
return $this->getTypeAConfig($config);
4950
}
50-
return $this->getTypeBConfig($config);
51+
if ($config instanceof IConfigTypeB) {
52+
return $this->getTypeBConfig($config);
53+
}
54+
throw new IncompleteConfigException(sprintf('Unknown config type %s', get_class($config)));
5155
}
5256

5357
/**
@@ -56,11 +60,11 @@ private function getSpecificConfig(IConfiguration $config): array
5660
* I chose a "stupid" (and repetitive) way because it is more readable
5761
* and thus better maintainable for others than an "intelligent" way.
5862
*
59-
* @param IConfigCommon $config
63+
* @param IConfiguration $config
6064
* @return array
6165
* @throws IIncompleteConfigException
6266
*/
63-
private function getCommonConfig(IConfigCommon $config): array
67+
private function getCommonConfig(IConfiguration $config): array
6468
{
6569
$common = [];
6670
if ($config->getLang() !== null) {

src/Traits/ParamTrait.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
namespace phpsap\saprfc\Traits;
66

77
use phpsap\exceptions\FunctionCallException;
8-
use phpsap\interfaces\Api\IElement;
9-
use phpsap\interfaces\Api\IStruct;
10-
use phpsap\interfaces\Api\ITable;
11-
use phpsap\interfaces\Api\IValue;
8+
use phpsap\interfaces\Api\IApiElement;
129
use phpsap\interfaces\exceptions\IInvalidArgumentException;
1310

1411
use function array_key_exists;
1512
use function count;
1613
use function is_array;
17-
use function is_string;
1814
use function sprintf;
1915

2016
/**
@@ -28,7 +24,7 @@ trait ParamTrait
2824
/**
2925
* Generate a function call parameter array from a list of known input values
3026
* and the previously set parameters.
31-
* @param IValue[] $inputs API input values.
27+
* @param IApiElement[] $inputs API input values.
3228
* @param array $params Parameters
3329
* @return array
3430
* @throws FunctionCallException
@@ -54,7 +50,7 @@ private function getInputParams(array $inputs, array $params): array
5450
/**
5551
* Generate a function call parameter array from a list of known tables and the
5652
* previously set parameters.
57-
* @param ITable[] $tables
53+
* @param IApiElement[] $tables
5854
* @param array $params
5955
* @return array
6056
*/
@@ -75,12 +71,12 @@ private function getTableParams(array $tables, array $params): array
7571
}
7672

7773
/**
78-
* @param IValue[] $outputs
74+
* @param IApiElement[] $outputs
7975
* @param array $result
8076
* @return array
8177
* @throws IInvalidArgumentException
8278
*/
83-
private function castOutputValues(array $outputs, array $result): array
79+
private function castOutput(array $outputs, array $result): array
8480
{
8581
$return = [];
8682
foreach ($outputs as $output) {

0 commit comments

Comments
 (0)