package updates

This commit is contained in:
2018-12-19 23:27:43 -06:00
parent aa1da4d4fb
commit 1ffd21369f
1181 changed files with 51194 additions and 11046 deletions
+125
View File
@@ -0,0 +1,125 @@
<?php
/**
* Nexmo Client Library for PHP
*
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
*/
namespace Nexmo\Message\Response;
use Nexmo\Client\Response\Response;
use Nexmo\Client\Response\Error;
use Nexmo\Client\Response\ResponseInterface;
class Collection extends Response implements ResponseInterface, \Countable, \Iterator
{
/**
* @var int
*/
protected $count;
/**
* @var array
*/
protected $data;
/**
* @var Message[]
*/
protected $messages = array();
/**
* @var int
*/
protected $position = 0;
public function __construct(array $data)
{
$this->expected = array('message-count', 'messages');
$return = parent::__construct($data);
$this->count = $data['message-count'];
if(count($data['messages']) != $data['message-count']){
throw new \RuntimeException('invalid message count');
}
foreach($data['messages'] as $message){
if(0 != $message['status']){
$this->messages[] = new Error($message);
} else {
$this->messages[] = new Message($message);
}
}
$this->data = $data;
return $return;
}
public function getMessages()
{
return $this->messages;
}
public function isSuccess()
{
foreach($this->messages as $message){
if($message instanceof Error){
return false;
}
}
return true;
}
public function count()
{
return $this->count;
}
/**
* @link http://php.net/manual/en/iterator.current.php
* @return Message
*/
public function current()
{
return $this->messages[$this->position];
}
/**
* @link http://php.net/manual/en/iterator.next.php
* @return void
*/
public function next()
{
$this->position++;
}
/**
* @link http://php.net/manual/en/iterator.key.php
* @return int
*/
public function key()
{
return $this->position;
}
/**
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean
*/
public function valid()
{
return $this->position < $this->count;
}
/**
* @link http://php.net/manual/en/iterator.rewind.php
* @return void
*/
public function rewind()
{
$this->position = 0;
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
/**
* Nexmo Client Library for PHP
*
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
*/
namespace Nexmo\Message\Response;
use Nexmo\Client\Response\Response;
use Nexmo\Client\Response\ResponseInterface;
use Nexmo\Message\Callback\Receipt;
class Message extends Response implements ResponseInterface
{
/**
* @var Receipt
*/
protected $receipt;
public function __construct(Array $data, Receipt $receipt = null)
{
$this->expected = array(
'status',
'message-id',
'to',
'message-price',
'network'
);
//default value
$data = array_merge(array('client-ref' => null, 'remaining-balance' => null), $data);
$return = parent::__construct($data);
//validate receipt
if(!$receipt){
return $return;
}
if($receipt->getId() != $this->getId()){
throw new \UnexpectedValueException('receipt id must match message id');
}
$this->receipt = $receipt;
return $receipt;
}
/**
* @return int
*/
public function getStatus()
{
return (int) $this->data['status'];
}
/**
* @return string
*/
public function getId()
{
return (string) $this->data['message-id'];
}
/**
* @return string
*/
public function getTo()
{
return (string) $this->data['to'];
}
/**
* @return string
*/
public function getBalance()
{
return (string) $this->data['remaining-balance'];
}
/**
* @return string
*/
public function getPrice()
{
return (string) $this->data['message-price'];
}
/**
* @return string
*/
public function getNetwork()
{
return (string) $this->data['network'];
}
/**
* @return string
*/
public function getClientRef()
{
return (string) $this->data['client-ref'];
}
/**
* @return Receipt|null
*/
public function getReceipt()
{
return $this->receipt;
}
/**
* @return bool
*/
public function hasReceipt()
{
return $this->receipt instanceof Receipt;
}
}