linkmobility-php-client/src/SMS/RequestFactory.php

60 lines
1.5 KiB
PHP

<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\LinkmobilityClient\SMS;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
use Phlib\SmsLength\SmsLength;
class RequestFactory implements RequestFactoryInterface
{
protected $message;
protected $client;
/**
* @param $message
* @param Client $client
*/
public function __construct($message, Client $client)
{
$this->message = $message;
$this->client = $client;
}
/**
* @return SmsRequestInterface
*/
public function getSmsRequest(): SmsRequestInterface
{
if ($this->getSmsLength()->getEncoding() === SmsLength::ENCODING_7BIT) {
$message = new SmsTextMessage($this->message);
return new TextRequest($message, $this->client);
}
$message = new SmsBinaryMessage($this->message);
return new BinaryRequest($message, $this->client);
}
/**
* @return SmsLength
*/
protected function getSmsLength(): SmsLength
{
return new SmsLength($this->message);
}
}