Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c96b3e1

Browse files
authored
Feature/send capabilties for endpoint (#12)
* Draft for encoding capabilities messages. * Format. * Remove empty lines. * Change namespace to braced. * Add positive test cases for sending messages. * Add negative test cases for sending messages.
1 parent b64f643 commit c96b3e1

39 files changed

+1436
-265
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
<?php
2+
3+
namespace App\Api\Builder {
4+
5+
use Agrirouter\Request\Payload\Endpoint\CapabilitySpecification\Capability;
6+
use App\Definitions\CapabilityTypeDefinitions;
7+
8+
/**
9+
* Builder for capabilities.
10+
* @package App\Api\Builder
11+
*/
12+
class CapabilityBuilder
13+
{
14+
private array $capabilities = [];
15+
16+
/**
17+
* Add capability.
18+
* @param int $direction Direction, could be sending or retrieving.
19+
* @return $this Instance of the builder for fluent style.
20+
*/
21+
public function withTaskdata(int $direction): CapabilityBuilder
22+
{
23+
$capability = new Capability();
24+
$capability->setDirection($direction);
25+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::ISO_11783_TASKDATA_ZIP);
26+
array_push($this->capabilities,$capability);
27+
return $this;
28+
}
29+
30+
/**
31+
* Add capability.
32+
* @param int $direction Direction, could be sending or retrieving.
33+
* @return $this Instance of the builder for fluent style.
34+
*/
35+
public function withDeviceDescription(int $direction): CapabilityBuilder
36+
{
37+
$capability = new Capability();
38+
$capability->setDirection($direction);
39+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::ISO_11783_DEVICE_DESCRIPTION_PROTOBUF);
40+
array_push($this->capabilities,$capability);
41+
return $this;
42+
}
43+
44+
/**
45+
* Add capability.
46+
* @param int $direction Direction, could be sending or retrieving.
47+
* @return $this Instance of the builder for fluent style.
48+
*/
49+
public function withTimeLog(int $direction): CapabilityBuilder
50+
{
51+
$capability = new Capability();
52+
$capability->setDirection($direction);
53+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::ISO_11783_TIMELOG_PROTOBUF);
54+
array_push($this->capabilities,$capability);
55+
return $this;
56+
}
57+
58+
/**
59+
* Add capability.
60+
* @param int $direction Direction, could be sending or retrieving.
61+
* @return $this Instance of the builder for fluent style.
62+
*/
63+
public function withBmp(int $direction): CapabilityBuilder
64+
{
65+
$capability = new Capability();
66+
$capability->setDirection($direction);
67+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::IMG_BMP);
68+
array_push($this->capabilities,$capability);
69+
return $this;
70+
}
71+
72+
/**
73+
* Add capability.
74+
* @param int $direction Direction, could be sending or retrieving.
75+
* @return $this Instance of the builder for fluent style.
76+
*/
77+
public function withJpg(int $direction): CapabilityBuilder
78+
{
79+
$capability = new Capability();
80+
$capability->setDirection($direction);
81+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::IMG_JPEG);
82+
array_push($this->capabilities,$capability);
83+
return $this;
84+
}
85+
86+
/**
87+
* Add capability.
88+
* @param int $direction Direction, could be sending or retrieving.
89+
* @return $this Instance of the builder for fluent style.
90+
*/
91+
public function withPng(int $direction): CapabilityBuilder
92+
{
93+
$capability = new Capability();
94+
$capability->setDirection($direction);
95+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::IMG_PNG);
96+
array_push($this->capabilities,$capability);
97+
return $this;
98+
}
99+
100+
/**
101+
* Add capability.
102+
* @param int $direction Direction, could be sending or retrieving.
103+
* @return $this Instance of the builder for fluent style.
104+
*/
105+
public function withShape(int $direction): CapabilityBuilder
106+
{
107+
$capability = new Capability();
108+
$capability->setDirection($direction);
109+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::SHP_SHAPE_ZIP);
110+
array_push($this->capabilities,$capability);
111+
return $this;
112+
}
113+
114+
/**
115+
* Add capability.
116+
* @param int $direction Direction, could be sending or retrieving.
117+
* @return $this Instance of the builder for fluent style.
118+
*/
119+
public function withPdf(int $direction): CapabilityBuilder
120+
{
121+
$capability = new Capability();
122+
$capability->setDirection($direction);
123+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::DOC_PDF);
124+
array_push($this->capabilities,$capability);
125+
return $this;
126+
}
127+
128+
/**
129+
* Add capability.
130+
* @param int $direction Direction, could be sending or retrieving.
131+
* @return $this Instance of the builder for fluent style.
132+
*/
133+
public function withAvi(int $direction): CapabilityBuilder
134+
{
135+
$capability = new Capability();
136+
$capability->setDirection($direction);
137+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::VID_AVI);
138+
array_push($this->capabilities,$capability);
139+
return $this;
140+
}
141+
142+
/**
143+
* Add capability.
144+
* @param int $direction Direction, could be sending or retrieving.
145+
* @return $this Instance of the builder for fluent style.
146+
*/
147+
public function withMp4(int $direction): CapabilityBuilder
148+
{
149+
$capability = new Capability();
150+
$capability->setDirection($direction);
151+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::VID_MP4);
152+
array_push($this->capabilities,$capability);
153+
return $this;
154+
}
155+
156+
/**
157+
* Add capability.
158+
* @param int $direction Direction, could be sending or retrieving.
159+
* @return $this Instance of the builder for fluent style.
160+
*/
161+
public function withWmv(int $direction): CapabilityBuilder
162+
{
163+
$capability = new Capability();
164+
$capability->setDirection($direction);
165+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::VID_WMV);
166+
array_push($this->capabilities,$capability);
167+
return $this;
168+
}
169+
170+
/**
171+
* Add capability.
172+
* @param int $direction Direction, could be sending or retrieving.
173+
* @return $this Instance of the builder for fluent style.
174+
*/
175+
public function withGpsInfo(int $direction): CapabilityBuilder
176+
{
177+
$capability = new Capability();
178+
$capability->setDirection($direction);
179+
$capability->setTechnicalMessageType(CapabilityTypeDefinitions::GPS_INFO);
180+
array_push($this->capabilities,$capability);
181+
return $this;
182+
}
183+
184+
/**
185+
* Build.
186+
* @return array Array containing all the capabilities defined.
187+
*/
188+
public function build(): array
189+
{
190+
return $this->capabilities;
191+
}
192+
193+
}
194+
}

src/Api/Common/MessagingService.php renamed to src/Api/Common/MessagingServiceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @package App\Service\Common
1010
* @template T
1111
*/
12-
interface MessagingService
12+
interface MessagingServiceInterface
1313
{
1414
/**
1515
* Sending a message using the given message parameters.

src/Api/Dto/JsonDeserializable.php renamed to src/Api/Dto/JsonDeserializableInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Interface JsonDeserializable - Classes that implement this Interface deserialize itself out of json data
77
* @package App\Helper
88
*/
9-
interface JsonDeserializable
9+
interface JsonDeserializableInterface
1010
{
1111
/**
1212
* Creates a new object of itself with the data of a given array or string
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Api\Service\Messaging {
4+
5+
use App\Api\Common\MessagingServiceInterface;
6+
7+
/**
8+
* Interface for the service to send capabilities for an endpoint.
9+
* @package App\Api\Service\Messaging
10+
*/
11+
interface CapabilitiesServiceInterface extends MessagingServiceInterface
12+
{
13+
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Api\Service\Messaging {
4+
5+
use App\Dto\Messaging\EncodedMessage;
6+
7+
/**
8+
* Interface for all services encoding messages.
9+
* @package App\Service\Common
10+
* @template T
11+
*/
12+
interface EncodeMessageServiceInterface
13+
{
14+
/**
15+
* Encode a message using the given message parameters.
16+
* @param T $parameters Parameters for message sending.
17+
* @return EncodedMessage -
18+
*/
19+
public function encode($parameters): EncodedMessage;
20+
21+
}
22+
}

src/Api/Service/Parameters/MessageParameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Parameter container definition.
99
* @package App\Api\Service\Parameters
1010
*/
11-
abstract class MessageParameters extends Parameters implements Validatable
11+
abstract class MessageParameters extends Parameters implements ValidatableInterface
1212
{
1313
private OnboardResponse $onboardResponse;
1414

src/Api/Service/Parameters/MessagingParameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Parameter container definition.
99
* @package App\Api\Service\Parameters
1010
*/
11-
class MessagingParameters extends MessageParameters implements Validatable
11+
class MessagingParameters extends MessageParameters implements ValidatableInterface
1212
{
1313
private array $encodedMessages = [];
1414

src/Api/Service/Parameters/Parameters.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Parameter container definition.
77
* @package App\Api\Service\Parameters
88
*/
9-
abstract class Parameters implements Validatable
9+
abstract class Parameters implements ValidatableInterface
1010
{
11-
private string $applicationMessageSeqNo;
12-
private string $applicationMessageId;
13-
private string $teamSetContextId;
11+
private int $applicationMessageSeqNo;
12+
private ?string $applicationMessageId = "";
13+
private ?string $teamSetContextId = "";
1414

1515
public function getApplicationMessageId(): string
1616
{
@@ -32,12 +32,12 @@ public function setTeamSetContextId(string $teamSetContextId): void
3232
$this->teamSetContextId = $teamSetContextId;
3333
}
3434

35-
public function getApplicationMessageSeqNo(): string
35+
public function getApplicationMessageSeqNo(): int
3636
{
3737
return $this->applicationMessageSeqNo;
3838
}
3939

40-
public function setApplicationMessageSeqNo(string $applicationMessageSeqNo): void
40+
public function setApplicationMessageSeqNo(int $applicationMessageSeqNo): void
4141
{
4242
$this->applicationMessageSeqNo = $applicationMessageSeqNo;
4343
}

src/Api/Service/Parameters/Validatable.php renamed to src/Api/Service/Parameters/ValidatableInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Interface to mark parameters as validatable.
88
* @package App\Api\Service\Parameters
99
*/
10-
interface Validatable
10+
interface ValidatableInterface
1111
{
1212

1313
/**

src/Definitions/ApplicationTypeDefinitions.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88
*/
99
class ApplicationTypeDefinitions
1010
{
11-
1211
/**
1312
* Type "Application".
14-
* @return string -
1513
*/
16-
public static function application(): string
17-
{
18-
return "Application";
19-
}
14+
public const APPLICATION = "Application";
2015

2116
}
2217
}

0 commit comments

Comments
 (0)