Skip to content

Commit 608e02b

Browse files
committed
update response format
1 parent e986032 commit 608e02b

4 files changed

Lines changed: 26 additions & 21 deletions

File tree

src/Ocpp/Messages/Call.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ public function __construct()
1212
{
1313
$this->messageId = Uuid::uuid4()->toString();
1414
}
15-
15+
1616
public function toArray(): array
1717
{
18-
$array = parent::toArray();
19-
$array['action'] = (new \ReflectionClass($this))->getShortName();
18+
$payload = $this->getPayload();
19+
$action = (new \ReflectionClass($this))->getShortName();
2020

21-
return $array;
21+
return [
22+
$this->messageTypeID,
23+
$this->messageId,
24+
$action,
25+
$payload,
26+
];
2227
}
2328
}

src/Ocpp/Messages/CallError.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function __construct(string $messageId, ?string $errorCode = null, ?strin
3030
public function toArray(): array
3131
{
3232
return [
33-
'messageTypeID' => $this->messageTypeID,
34-
'messageId' => $this->messageId,
35-
'errorCode' => $this->errorCode,
36-
'errorDescription' => $this->errorDescription,
37-
'errorDetails' => (object) $this->errorDetails,
33+
$this->messageTypeID,
34+
$this->messageId,
35+
$this->errorCode,
36+
$this->errorDescription,
37+
(object) $this->errorDetails,
3838
];
3939
}
4040
}

src/Ocpp/Messages/CallResult.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ public function __construct(string $messageId)
1010
{
1111
$this->messageId = $messageId;
1212
}
13+
14+
public function toArray(): array
15+
{
16+
$payload = $this->getPayload();
17+
18+
return [
19+
$this->messageTypeID,
20+
$this->messageId,
21+
$payload,
22+
];
23+
}
24+
1325
}

src/Ocpp/Messages/Message.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ abstract class Message
88

99
public string $messageId;
1010

11-
public function toArray(): array
12-
{
13-
$payload = $this->getPayload();
14-
15-
return [
16-
'messageTypeID' => $this->messageTypeID,
17-
'messageId' => $this->messageId,
18-
'payload' => $payload,
19-
];
20-
}
21-
2211
public function getPayload(): object
2312
{
2413
$payload = (array) $this;
@@ -33,5 +22,4 @@ public function getMessageId(): string
3322
{
3423
return $this->messageId;
3524
}
36-
3725
}

0 commit comments

Comments
 (0)