use RecipientsList object instead of recipient objects array

This commit is contained in:
Daniel Seifert 2023-01-07 22:44:37 +01:00
bovenliggende 32ea723301
commit 2460281434
Getekend door: DanielS
GPG sleutel-ID: 6A513E13AEE66170
2 gewijzigde bestanden met toevoegingen van 20 en 14 verwijderingen

Bestand weergeven

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

Bestand weergeven

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