use RecipientsList object instead of recipient objects array

This commit is contained in:
Daniel Seifert 2023-01-07 22:44:37 +01:00
parent 32ea723301
commit 2460281434
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
2 changed files with 20 additions and 14 deletions

View File

@ -15,8 +15,8 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model\MessageTypes;
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception;
use OxidEsales\Eshop\Application\Model\Remark;
@ -26,15 +26,18 @@ abstract class AbstractMessage
/** @var string */
protected $message;
/** @var bool */
protected $removeLineBreaks = true;
/** @var bool */
protected $removeMultipleSpaces = true;
/** @var ResponseInterface */
protected $response;
/** @var Recipient[] */
protected $recipients = [];
/** @var RecipientsList */
protected $recipients;
/**
* @param string $message
@ -80,10 +83,10 @@ abstract class AbstractMessage
}
/**
* @param array<Recipient> $recipients
* @param RecipientsList $recipients
* @return void
*/
protected function setRecipients(array $recipients)
protected function setRecipients(RecipientsList $recipients)
{
$this->recipients = $recipients;
}
@ -94,7 +97,7 @@ abstract class AbstractMessage
public function getRecipientsList(): string
{
$list = [];
foreach ($this->recipients as $recipient) {
foreach ($this->recipients->getRecipientsList() as $recipient) {
$list[] = $recipient->get();
}

View File

@ -23,6 +23,7 @@ use D3\Linkmobility4OXID\Application\Model\OrderRecipients;
use D3\Linkmobility4OXID\Application\Model\RequestFactory;
use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\SMS\SmsRequestInterface;
use D3\LinkmobilityClient\ValueObject\Recipient;
@ -47,7 +48,8 @@ class Sms extends AbstractMessage
try {
Registry::getLogger()->debug('startRequest', ['userId' => $user->getId()]);
$return = $this->sendCustomRecipientMessage(
[ oxNew(UserRecipients::class, $user)->getSmsRecipient() ]
oxNew(RecipientsList::class, oxNew(MessageClient::class)->getClient())
->add(oxNew(UserRecipients::class, $user)->getSmsRecipient())
);
if ($return) {
$this->setRemark($user->getId(), $this->getRecipientsList(), $this->getMessage());
@ -74,7 +76,8 @@ class Sms extends AbstractMessage
try {
Registry::getLogger()->debug('startRequest', ['orderId' => $order->getId()]);
$return = $this->sendCustomRecipientMessage(
[ $this->getOrderRecipient($order) ]
oxNew(RecipientsList::class, oxNew(MessageClient::class)->getClient())
->add($this->getOrderRecipient($order))
);
if ($return) {
$this->setRemark($order->getOrderUser()->getId(), $this->getRecipientsList(), $this->getMessage());
@ -98,14 +101,14 @@ class Sms extends AbstractMessage
}
/**
* @param array<Recipient> $recipientsArray
* @param RecipientsList $recipientsList
*
* @return bool
*/
public function sendCustomRecipientMessage(array $recipientsArray): bool
public function sendCustomRecipientMessage(RecipientsList $recipientsList): bool
{
try {
$this->setRecipients($recipientsArray);
$this->setRecipients($recipientsList);
$configuration = oxNew(Configuration::class);
$client = oxNew(MessageClient::class)->getClient();
@ -121,9 +124,9 @@ class Sms extends AbstractMessage
)
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
$recipientsList = $request->getRecipientsList();
foreach ($recipientsArray as $recipient) {
$recipientsList->add($recipient);
$requestRecipientsList = $request->getRecipientsList();
foreach ($recipientsList as $recipient) {
$requestRecipientsList->add($recipient);
}
$response = $client->request($request);