initial
This commit is contained in:
commit
0cdfd0185b
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
```
|
||||
$client = new Client('accesstoken');
|
||||
$request = (new \D3\LinkmobilityClient\SMS\Request('me', 'message'))
|
||||
->addRecipient(new Recipient('recipient'));
|
||||
$client->request($request)
|
||||
```
|
43
composer.json
Normal file
43
composer.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "d3/linkmobility-php-client",
|
||||
"type": "library",
|
||||
"description": "PHP client for Linkmobility API (de)",
|
||||
"keywords": [
|
||||
"linkmobility",
|
||||
"php",
|
||||
"sms",
|
||||
"sms gateway"
|
||||
],
|
||||
"homepage": "https://d3data.de/",
|
||||
"authors": [
|
||||
{
|
||||
"name": "D3 Data Development (Inh. Thomas Dartsch)",
|
||||
"email": "info@shopmodule.com",
|
||||
"homepage": "https://www.d3data.de",
|
||||
"role": "Owner"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"beberlei/assert": "^2.7",
|
||||
"guzzlehttp/guzzle": "~6.2",
|
||||
"psr/http-message": "~1.0",
|
||||
"symfony/options-resolver": "^3.0|^4.0",
|
||||
"phlib/sms-length": "^1.1.0 || ^2.0.0",
|
||||
"giggsey/libphonenumber-for-php": "^8.12"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit" : "~5.7||~6.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"D3\\LinkmobilityClient\\": "src"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit",
|
||||
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
||||
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose"
|
||||
}
|
||||
}
|
79
src/Client.php
Normal file
79
src/Client.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\LinkmobilityClient;
|
||||
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
|
||||
class Client
|
||||
{
|
||||
private $accessToken;
|
||||
public $apiUrl;
|
||||
public $requestClient;
|
||||
|
||||
public function __construct(string $accessToken, $apiUrl = false, $client = false)
|
||||
{
|
||||
if ($apiUrl !== false && false === $apiUrl instanceof UrlInterface) {
|
||||
throw new \RuntimeException('ApiUrl instance must implement UrlInterface');
|
||||
}
|
||||
|
||||
$this->accessToken = $accessToken;
|
||||
$this->apiUrl = $apiUrl ?: new Url();
|
||||
$this->requestClient = $client ?: new \GuzzleHttp\Client( [ 'base_uri' => $this->apiUrl->getBaseUri() ] );
|
||||
}
|
||||
|
||||
public function request(RequestInterface $request) : ResponseInterface
|
||||
{
|
||||
$request->validate();
|
||||
$responseClass = $request->getResponseClass();
|
||||
return $request->getResponseInstance(
|
||||
$this->rawRequest($request->getUri(), $request->getMethod(), $request->getOptions())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param string $method
|
||||
* @param array $postArgs
|
||||
*
|
||||
* @return string
|
||||
* @throws ApiException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
protected function rawRequest( $url, string $method = RequestInterface::METHOD_GET, array $options = []): string
|
||||
{
|
||||
$options['headers']['Authorization'] = 'access_token '.$this->accessToken;
|
||||
|
||||
if (!empty($body)) {
|
||||
$options['json'] = $body;
|
||||
}
|
||||
dumpvar(__METHOD__.__LINE__.PHP_EOL);
|
||||
dumpvar($options);
|
||||
dumpVar($method);
|
||||
dumpvar($url);
|
||||
die();
|
||||
$response = $this->requestClient->request(
|
||||
$method,
|
||||
$url,
|
||||
$options
|
||||
);
|
||||
|
||||
if ($response->getStatusCode() != 200) {
|
||||
throw new ApiException('request '.$url.' returns status code '.$response->getStatusCode());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
82
src/RecipientsList/RecipientsList.php
Normal file
82
src/RecipientsList/RecipientsList.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\RecipientsList;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
|
||||
class RecipientsList implements RecipientsListInterface, \Iterator
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $recipients = [];
|
||||
|
||||
public function add(Recipient $recipient)
|
||||
{
|
||||
$this->recipients[md5(serialize($recipient))] = $recipient;
|
||||
}
|
||||
|
||||
public function clearRecipents()
|
||||
{
|
||||
$this->recipients = [];
|
||||
}
|
||||
|
||||
public function getRecipients() : array
|
||||
{
|
||||
return array_values(
|
||||
array_map(
|
||||
function (Recipient $recipient) {
|
||||
return $recipient->get();
|
||||
},
|
||||
$this->recipients
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getRecipientsList() : array
|
||||
{
|
||||
return $this->recipients;
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return current($this->recipients);
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
return next($this->recipients);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return key($this->recipients);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
return reset($this->recipients);
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return (false !== current($this->recipients) && current($this->recipients) instanceof Recipient);
|
||||
}
|
||||
|
||||
//stract methods and must therefore be declared abstract or implement the remaining methods (Iterator::current, Iterator::next, Iterator::key, ...) in
|
||||
}
|
29
src/RecipientsList/RecipientsListInterface.php
Normal file
29
src/RecipientsList/RecipientsListInterface.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\RecipientsList;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
|
||||
interface RecipientsListInterface
|
||||
{
|
||||
public function add(Recipient $recipient);
|
||||
|
||||
public function clearRecipents();
|
||||
|
||||
public function getRecipients() : array;
|
||||
}
|
449
src/Request/Request.php
Normal file
449
src/Request/Request.php
Normal file
@ -0,0 +1,449 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\Request;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessage;
|
||||
use D3\LinkmobilityClient\ValueObject\StringValueObject;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
abstract class Request implements RequestInterface
|
||||
{
|
||||
/**
|
||||
* @var StringValueObject
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $method = RequestInterface::METHOD_GET;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $contentType = RequestInterface::CONTENTTYPE_JSON;
|
||||
|
||||
/**
|
||||
* @var null|string
|
||||
*/
|
||||
private $clientMessageId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $contentCategory = RequestInterface::CONTENTCATEGORY_INFORMATIONAL;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $messageType = RequestInterface::MESSAGETYPE_DEFAULT;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $notificationCallbackUrl = null;
|
||||
|
||||
/**
|
||||
* @var null|int
|
||||
*/
|
||||
private $priority = null;
|
||||
|
||||
/**
|
||||
* @var RecipientsListInterface
|
||||
*/
|
||||
private $recipientsList;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $sendAsFlashSms = false;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $senderAddress = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $senderAddressType = null;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $validityPeriode = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $test = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $maxSmsPerMessage = 0;
|
||||
|
||||
public function __construct(StringValueObject $message)
|
||||
{
|
||||
$this->recipientsList = new RecipientsList();
|
||||
$this->setMessage( $message );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function validate(): void
|
||||
{
|
||||
Assert::that( $this->getMethod() )->choice( self::getMethods() );
|
||||
Assert::that( $this->getUri() )->string()->startsWith( '/' );
|
||||
|
||||
Assert::that($this->getBody())->isArray();
|
||||
Assert::that($this->getResponseClass())->implementsInterface(ResponseInterface::class);
|
||||
Assert::that($this->getOptions())->isArray();
|
||||
|
||||
Assert::that( $this->getRecipientsList() )->isInstanceOf(RecipientsList::class)->notEmpty();
|
||||
Assert::thatAll( $this->getRecipientsList() )->isInstanceOf( Recipient::class );
|
||||
|
||||
// optional properties
|
||||
Assert::thatNullOr( $this->getClientMessageId() )->string();
|
||||
Assert::thatNullOr( $this->getContentCategory() )->choice(self::getContentCategories());
|
||||
Assert::thatNullOr( $this->getNotificationCallbackUrl() )->url();
|
||||
Assert::thatNullOr( $this->getPriority() )->integer();
|
||||
Assert::thatNullOr( $this->getSendAsFlashSms() )->boolean();
|
||||
Assert::thatNullOr( $this->getSenderAddress() )->isInstanceOf(Sender::class);
|
||||
Assert::thatNullOr( $this->getSenderAddressType() )->choice(self::getSenderAddressTypes());
|
||||
Assert::thatNullOr( $this->isTest() )->boolean();
|
||||
Assert::thatNullOr( $this->getValidityPeriode() )->integer();
|
||||
}
|
||||
|
||||
public function getRawBody() : array
|
||||
{
|
||||
return [
|
||||
'clientMessageId' => $this->getClientMessageId(),
|
||||
'contentCategory' => $this->getContentCategory(),
|
||||
'maxSmsPerMessage' => $this->getMaxSmsPerMessage(),
|
||||
'messageContent' => (string) $this->getMessage(),
|
||||
'messageType' => $this->getMessageType(),
|
||||
'notificationCallbackUrl' => $this->getNotificationCallbackUrl(),
|
||||
'priority' => $this->getPriority(),
|
||||
'recipientAddressList' => $this->getRecipientsList()->getRecipients(),
|
||||
'sendAsFlashSms' => $this->getSendAsFlashSms(),
|
||||
'senderAddress' => $this->getSenderAddress()->get(),
|
||||
'senderAddressType' => $this->getSenderAddressType(),
|
||||
'test' => $this->isTest(),
|
||||
'validityPeriode' => $this->getValidityPeriode()
|
||||
];
|
||||
}
|
||||
|
||||
public function getBody(): array
|
||||
{
|
||||
$body = array_filter( $this->getRawBody(), function( $elm ) {
|
||||
return ! is_null( $elm );
|
||||
} );
|
||||
|
||||
switch ($this->getContentType()) {
|
||||
case RequestInterface::CONTENTTYPE_JSON:
|
||||
return ['json' => json_encode($body)];
|
||||
default:
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOptions(): array
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
'headers' => [
|
||||
'Accept' => $this->contentType,
|
||||
'Content-Type' => $this->contentType,
|
||||
]
|
||||
|
||||
],
|
||||
$this->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
public function setMessage(StringValueObject $message)
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMessage(): StringValueObject
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setMethod(string $method)
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMethod(): string
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public static function getMethods(): array
|
||||
{
|
||||
return [
|
||||
RequestInterface::METHOD_GET => RequestInterface::METHOD_GET,
|
||||
RequestInterface::METHOD_POST => RequestInterface::METHOD_POST,
|
||||
RequestInterface::METHOD_PUT => RequestInterface::METHOD_PUT,
|
||||
RequestInterface::METHOD_PATCH => RequestInterface::METHOD_PATCH,
|
||||
RequestInterface::METHOD_DELETE => RequestInterface::METHOD_DELETE,
|
||||
];
|
||||
}
|
||||
|
||||
public function setContentType(string $contentType)
|
||||
{
|
||||
$this->contentType = $contentType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContentType() : string
|
||||
{
|
||||
return $this->contentType;
|
||||
}
|
||||
|
||||
public function setClientMessageId($clientMessageId)
|
||||
{
|
||||
$this->clientMessageId = $clientMessageId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClientMessageId()
|
||||
{
|
||||
return $this->clientMessageId;
|
||||
}
|
||||
|
||||
public function setContentCategory(string $contentCategory)
|
||||
{
|
||||
$this->contentCategory = $contentCategory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContentCategory() : string
|
||||
{
|
||||
return $this->contentCategory;
|
||||
}
|
||||
|
||||
public static function getContentCategories(): array
|
||||
{
|
||||
return [
|
||||
RequestInterface::CONTENTCATEGORY_ADVERTISEMENT => RequestInterface::CONTENTCATEGORY_ADVERTISEMENT,
|
||||
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL
|
||||
];
|
||||
}
|
||||
|
||||
public function setTest(bool $test)
|
||||
{
|
||||
$this->test = $test;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isTest() : bool
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
public function setMaxSmsPerMessage(int $maxSmsPerMessage)
|
||||
{
|
||||
$this->maxSmsPerMessage = $maxSmsPerMessage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxSmsPerMessage() : int
|
||||
{
|
||||
return $this->maxSmsPerMessage;
|
||||
}
|
||||
|
||||
public function setMessageType(string $messageType)
|
||||
{
|
||||
$this->messageType = $messageType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMessageType() : string
|
||||
{
|
||||
return $this->messageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $notificationCallbackUrl
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setNotificationCallbackUrl($notificationCallbackUrl)
|
||||
{
|
||||
$this->notificationCallbackUrl = $notificationCallbackUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNotificationCallbackUrl()
|
||||
{
|
||||
return $this->notificationCallbackUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $priority
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPriority($priority)
|
||||
{
|
||||
$this->priority = $priority;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RecipientsListInterface
|
||||
*/
|
||||
public function getRecipientsList() : RecipientsListInterface
|
||||
{
|
||||
return $this->recipientsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $recipientList
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSendAsFlashSms(bool $flashSms)
|
||||
{
|
||||
$this->sendAsFlashSms = $flashSms;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSendAsFlashSms() : bool
|
||||
{
|
||||
return $this->sendAsFlashSms;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Sender $senderAddress
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSenderAddress(Sender $senderAddress)
|
||||
{
|
||||
$this->senderAddress = $senderAddress;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSenderAddress() : Sender
|
||||
{
|
||||
return $this->senderAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $senderAddressType
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSenderAddressType($senderAddressType)
|
||||
{
|
||||
$this->senderAddressType = $senderAddressType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSenderAddressType()
|
||||
{
|
||||
return $this->senderAddressType;
|
||||
}
|
||||
|
||||
public static function getSenderAddressTypes(): array
|
||||
{
|
||||
return [
|
||||
RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC => RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC,
|
||||
RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL => RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL,
|
||||
RequestInterface::SENDERADDRESSTYPE_NATIONAL => RequestInterface::SENDERADDRESSTYPE_NATIONAL,
|
||||
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $validityPeriode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setValidityPeriode($validityPeriode)
|
||||
{
|
||||
$this->validityPeriode = $validityPeriode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getValidityPeriode()
|
||||
{
|
||||
return $this->validityPeriode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getResponseInstance(\Psr\Http\Message\ResponseInterface $rawResponse): ResponseInterface
|
||||
{
|
||||
return new $this->getResponseClass($rawResponse);
|
||||
}
|
||||
}
|
93
src/Request/RequestInterface.php
Normal file
93
src/Request/RequestInterface.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\Request;
|
||||
|
||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||
|
||||
interface RequestInterface
|
||||
{
|
||||
const METHOD_GET = 'GET';
|
||||
const METHOD_POST = 'POST';
|
||||
const METHOD_PUT = 'PUT';
|
||||
const METHOD_PATCH = 'PATCH';
|
||||
const METHOD_DELETE = 'DELETE';
|
||||
|
||||
const CONTENTTYPE_JSON = 'application/json';
|
||||
|
||||
const CONTENTCATEGORY_INFORMATIONAL = 'informational';
|
||||
const CONTENTCATEGORY_ADVERTISEMENT = 'advertisement';
|
||||
|
||||
const MESSAGETYPE_DEFAULT = 'default';
|
||||
const MESSAGETYPE_VOICE = 'voice';
|
||||
|
||||
const SENDERADDRESSTYPE_NATIONAL = 'national';
|
||||
const SENDERADDRESSTYPE_INTERNATIONAL = 'international';
|
||||
const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric';
|
||||
const SENDERADDRESSTYPE_SHORTCODE = 'shortcode';
|
||||
|
||||
public function setMethod(string $method);
|
||||
|
||||
/**
|
||||
* Must return the HTTP verb for this request, i.e. GET, POST, PUT
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod() : string;
|
||||
|
||||
/**
|
||||
* Must return the URI for the request with a leading slash, i.e. /messages.json
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUri() : string;
|
||||
|
||||
/**
|
||||
* Must return the body which is being sent as json
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBody() : array;
|
||||
|
||||
/**
|
||||
* Must return the class to where the response is handed over. It must implement the ResponseInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseClass() : string;
|
||||
|
||||
/**
|
||||
* @param \Psr\Http\Message\ResponseInterface $rawResponse
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getResponseInstance(\Psr\Http\Message\ResponseInterface $rawResponse): ResponseInterface;
|
||||
|
||||
/**
|
||||
* Must return the options for this request. If there are none, return [] (empty array)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions() : array;
|
||||
|
||||
/**
|
||||
* Must validate the input of the request
|
||||
* This is called before sending the request
|
||||
* Must throw an exception if the validation fails
|
||||
*/
|
||||
public function validate() : void;
|
||||
}
|
45
src/Response/Response.php
Normal file
45
src/Response/Response.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\Response;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
abstract class Response implements ResponseInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
Assert::that($data)->keyExists('status');
|
||||
|
||||
$this->data = $data;
|
||||
$this->status = (int)$this->data['status'];
|
||||
|
||||
if ($this->isSuccessful()) {
|
||||
$this->init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful(): bool
|
||||
{
|
||||
return $this->status >= 200 && $this->status < 300;
|
||||
}
|
||||
|
||||
public function getError(): string
|
||||
{
|
||||
return $this->isSuccessful() ? '' : $this->data['message'];
|
||||
}
|
||||
}
|
29
src/Response/ResponseInterface.php
Normal file
29
src/Response/ResponseInterface.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\Response;
|
||||
|
||||
interface ResponseInterface
|
||||
{
|
||||
/**
|
||||
* Should instantiate the object from the data given
|
||||
*/
|
||||
public function init() : void;
|
||||
|
||||
public function __construct(array $data);
|
||||
|
||||
/**
|
||||
* Must return true if the request was successful
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccessful() : bool;
|
||||
|
||||
/**
|
||||
* This must return the error, if any occurred, else it must return ''
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getError() : string;
|
||||
}
|
34
src/SMS/Request.php
Normal file
34
src/SMS/Request.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessage;
|
||||
|
||||
class Request
|
||||
{
|
||||
public function __construct( Sender $sender, SmsMessage $message)
|
||||
{
|
||||
$this = new TextRequest($sender, $message);
|
||||
/*
|
||||
if ($message->isGsm7()) {
|
||||
return new TextRequest($sender, $message);
|
||||
}
|
||||
|
||||
return new TextRequest($sender, $message);
|
||||
*/
|
||||
}
|
||||
}
|
49
src/SMS/Response.php
Normal file
49
src/SMS/Response.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use Assert\Assert;
|
||||
use Loevgaard\Linkmobility\Response\BatchStatusResponse\Details;
|
||||
use Loevgaard\Linkmobility\Response\BatchStatusResponse\Stat;
|
||||
|
||||
class Response extends \D3\LinkmobilityClient\Response\Response
|
||||
{
|
||||
/**
|
||||
* @var Stat
|
||||
*/
|
||||
protected $stat;
|
||||
|
||||
/**
|
||||
* @var Details
|
||||
*/
|
||||
protected $details;
|
||||
|
||||
public function init() : void
|
||||
{
|
||||
Assert::that($this->data)
|
||||
->keyExists('stat')
|
||||
->keyExists('details')
|
||||
;
|
||||
|
||||
$this->stat = new Stat($this->data['stat']);
|
||||
$this->details = new Details($this->data['details']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Stat
|
||||
*/
|
||||
public function getStat(): Stat
|
||||
{
|
||||
return $this->stat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Details
|
||||
*/
|
||||
public function getDetails(): Details
|
||||
{
|
||||
return $this->details;
|
||||
}
|
||||
}
|
502
src/SMS/TextRequest.php
Normal file
502
src/SMS/TextRequest.php
Normal file
@ -0,0 +1,502 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\Url;
|
||||
use D3\LinkmobilityClient\ValueObject\Message;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessage;
|
||||
|
||||
class TextRequest extends \D3\LinkmobilityClient\Request\Request
|
||||
{
|
||||
/**
|
||||
* @var Sender
|
||||
*/
|
||||
protected $sender;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $statusUrl;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $returnData;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
/**
|
||||
* @var \DateTimeInterface
|
||||
*/
|
||||
protected $sendTime;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $price;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $charity;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $invoiceText;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $validity;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $format;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $udh;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attachment;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pushUrl;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pushExpire;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $filter;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $segmentation;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $pid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $advanced;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $protocol;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $revenueText;
|
||||
|
||||
public function getUri(): string
|
||||
{
|
||||
return '/smsmessaging/text/';
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
parent::validate();
|
||||
|
||||
Assert::thatNullOr( $this->getMessage() )->isInstanceOf(SmsMessage::class);
|
||||
}
|
||||
|
||||
public function getResponseClass(): string
|
||||
{
|
||||
return Response::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Message $message
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
/*
|
||||
public function setMessage( SmsMessage $message )
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
if ($message->isGsm7()) {
|
||||
$this->setFormat(SmsMessage::GSM_7BIT);
|
||||
} else {
|
||||
$this->setFormat(SmsMessage::GSM_UCS2);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isStatus(): bool
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $status
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setStatus( bool $status )
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReturnData(): string
|
||||
{
|
||||
return $this->returnData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $returnData
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setReturnData( string $returnData )
|
||||
{
|
||||
$this->returnData = $returnData;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getClass(): int
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $class
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setClass( int $class )
|
||||
{
|
||||
$this->class = $class;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTimeInterface
|
||||
*/
|
||||
public function getSendTime(): \DateTimeInterface
|
||||
{
|
||||
return $this->sendTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface $sendTime
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setSendTime( \DateTimeInterface $sendTime )
|
||||
{
|
||||
$this->sendTime = $sendTime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getValidity(): int
|
||||
{
|
||||
return $this->validity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|\DateInterval $validity In minutes
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setValidity( $validity )
|
||||
{
|
||||
if ( $validity instanceof \DateInterval ) {
|
||||
$now = new \DateTimeImmutable();
|
||||
$seconds = $now->add( $validity )->getTimestamp() - $now->getTimestamp();
|
||||
$validity = ceil( $seconds / 60 );
|
||||
}
|
||||
|
||||
$validity = (int) $validity;
|
||||
|
||||
$this->validity = $validity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFormat(): string
|
||||
{
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setFormat( string $format )
|
||||
{
|
||||
$this->format = $format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUdh(): string
|
||||
{
|
||||
return $this->udh;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $udh
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setUdh( string $udh )
|
||||
{
|
||||
$this->udh = $udh;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAttachment(): array
|
||||
{
|
||||
return $this->attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attachment
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setAttachment( array $attachment )
|
||||
{
|
||||
$this->attachment = $attachment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPushUrl(): string
|
||||
{
|
||||
return $this->pushUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pushUrl
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setPushUrl( string $pushUrl )
|
||||
{
|
||||
$this->pushUrl = $pushUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPushExpire(): string
|
||||
{
|
||||
return $this->pushExpire;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|\DateTimeInterface $pushExpire
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setPushExpire( $pushExpire )
|
||||
{
|
||||
if ( $pushExpire instanceof \DateTimeInterface ) {
|
||||
$pushExpire = (string) $pushExpire->getTimestamp();
|
||||
}
|
||||
|
||||
$this->pushExpire = $pushExpire;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilter(): array
|
||||
{
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $filter
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setFilter( array $filter )
|
||||
{
|
||||
$this->filter = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSegmentation(): array
|
||||
{
|
||||
return $this->segmentation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $segmentation
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setSegmentation( array $segmentation )
|
||||
{
|
||||
$this->segmentation = $segmentation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPid(): int
|
||||
{
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pid
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setPid( int $pid )
|
||||
{
|
||||
$this->pid = $pid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAdvanced(): string
|
||||
{
|
||||
return $this->advanced;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $advanced
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setAdvanced( string $advanced )
|
||||
{
|
||||
$this->advanced = $advanced;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProtocol(): string
|
||||
{
|
||||
return $this->protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $protocol
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setProtocol( string $protocol )
|
||||
{
|
||||
$this->protocol = $protocol;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRevenueText(): string
|
||||
{
|
||||
return $this->revenueText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $revenueText
|
||||
*
|
||||
* @return PostMessageRequest
|
||||
*/
|
||||
public function setRevenueText( string $revenueText )
|
||||
{
|
||||
$this->revenueText = $revenueText;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
101
src/Url.php
Normal file
101
src/Url.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\LinkmobilityClient;
|
||||
|
||||
class Url implements UrlInterface
|
||||
{
|
||||
public $baseUri = 'https://api.linkmobility.eu/rest';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUri(): string
|
||||
{
|
||||
return $this->baseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $lat
|
||||
* @param float $lng
|
||||
* @param float $radius
|
||||
* @param string $sort
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getListUrl(float $lat, float $lng, float $radius, string $sort, string $type): string
|
||||
{
|
||||
$query = http_build_query(
|
||||
[
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
'rad' => $radius,
|
||||
'sort' => $sort,
|
||||
'type' => $type,
|
||||
'apikey'=> $this->apiKey
|
||||
]
|
||||
);
|
||||
return "list.php?$query";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $stationId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStationDetailUrl($stationId): string
|
||||
{
|
||||
$query = http_build_query(
|
||||
[
|
||||
'id' => $stationId,
|
||||
'apikey'=> $this->apiKey
|
||||
]
|
||||
);
|
||||
return "detail.php?$query";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $stationList
|
||||
*
|
||||
* @return string
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function getPricesUrl(array $stationList): string
|
||||
{
|
||||
if (count($stationList) < 1 || count($stationList) > 10) {
|
||||
throw new ApiException('Preisabfrage darf nur zwischen 1 und 10 Stationen beinhalten');
|
||||
}
|
||||
|
||||
$query = http_build_query(
|
||||
[
|
||||
'ids' => implode( ',', $stationList),
|
||||
'apikey'=> $this->apiKey
|
||||
]
|
||||
);
|
||||
|
||||
return "prices.php?$query";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getComplaintUrl(): string
|
||||
{
|
||||
$query = http_build_query(['apikey'=> $this->apiKey]);
|
||||
|
||||
return $this->baseUri . "complaint.php?$query";
|
||||
}
|
||||
}
|
21
src/UrlInterface.php
Normal file
21
src/UrlInterface.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\LinkmobilityClient;
|
||||
|
||||
interface UrlInterface
|
||||
{
|
||||
public function getBaseUri(): string;
|
||||
}
|
25
src/ValueObject/Recipient.php
Normal file
25
src/ValueObject/Recipient.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
class Recipient extends StringValueObject
|
||||
{
|
||||
public function __construct(string $value)
|
||||
{
|
||||
// ohne +, dafür mit Ländervorwahl
|
||||
// eine führende 0 scheint lokale Version
|
||||
// zwei führende Nullen einfach weggeschnitten
|
||||
|
||||
//https://github.com/matmar10/msisdn-format-bundle/blob/master/Matmar10/Bundle/MsisdnFormatBundle/Resources/config/msisdn-country-formats.xml
|
||||
|
||||
|
||||
// valid formats can be found here: https://linkmobility.atlassian.net/wiki/spaces/COOL/pages/26017807/08.+Messages#id-08.Messages-recipients
|
||||
Assert::that($value)->regex('/^(\+|c)?[0-9]+$/i', 'Recipient does not match valid phone number.');
|
||||
|
||||
parent::__construct($value);
|
||||
}
|
||||
}
|
20
src/ValueObject/Sender.php
Normal file
20
src/ValueObject/Sender.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
class Sender extends StringValueObject
|
||||
{
|
||||
public function __construct(string $value)
|
||||
{
|
||||
// if the sender is alphanumeric, test the length
|
||||
if (!preg_match('/^\+[0-9]+$/i', $value)) {
|
||||
Assert::that($value)->maxLength(11);
|
||||
}
|
||||
|
||||
parent::__construct($value);
|
||||
}
|
||||
}
|
54
src/ValueObject/SmsMessage.php
Normal file
54
src/ValueObject/SmsMessage.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
|
||||
class SmsMessage extends StringValueObject
|
||||
{
|
||||
const GSM_7BIT = '7-bit';
|
||||
const GSM_UCS2 = 'ucs-2';
|
||||
|
||||
public function __construct(string $value)
|
||||
{
|
||||
parent::__construct($value);
|
||||
|
||||
$smsLength = new SmsLength($this->value);
|
||||
$smsLength->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $gsm7;
|
||||
|
||||
public function chunkCount() : int
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
return $smsLength->getMessageCount();
|
||||
}
|
||||
|
||||
public function length() : int
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
$smsLength->getSize();
|
||||
}
|
||||
|
||||
public function isGsm7() : bool
|
||||
{
|
||||
$smsLength = new SmsLength($this->value);
|
||||
if (is_null($this->gsm7)) {
|
||||
$this->gsm7 = $smsLength->getEncoding() === self::GSM_7BIT;
|
||||
}
|
||||
|
||||
return $this->gsm7;
|
||||
}
|
||||
|
||||
public function isUnicode() : bool
|
||||
{
|
||||
return !$this->isGsm7();
|
||||
}
|
||||
}
|
27
src/ValueObject/StringValueObject.php
Normal file
27
src/ValueObject/StringValueObject.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
abstract class StringValueObject extends ValueObject
|
||||
{
|
||||
public function __construct(string $value)
|
||||
{
|
||||
Assert::that($value)->notEmpty();
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->get();
|
||||
}
|
||||
|
||||
public function get() : string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
10
src/ValueObject/ValueObject.php
Normal file
10
src/ValueObject/ValueObject.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
abstract class ValueObject
|
||||
{
|
||||
protected $value;
|
||||
}
|
Loading…
Reference in New Issue
Block a user