mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 16:29:24 +03:00
* Changed class docblock to include link to readme for instructions.
* Added docblocks for functions and member variables. * Updated constants to use constants classes * Changed finalize() - removing the return (since the sendMessage() method already does not return anything)
This commit is contained in:
parent
3e55c2bcd2
commit
7fed60d881
@ -2,23 +2,49 @@
|
|||||||
|
|
||||||
namespace Mailgun\Messages;
|
namespace Mailgun\Messages;
|
||||||
|
|
||||||
use Mailgun\Messages\MessageBuilder;
|
use Mailgun\Constants\Api;
|
||||||
|
use Mailgun\Constants\ExceptionMessages;
|
||||||
use Mailgun\Messages\Exceptions\TooManyParameters;
|
use Mailgun\Messages\Exceptions\TooManyParameters;
|
||||||
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
use Mailgun\Messages\Exceptions\MissingRequiredMIMEParameters;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
This class is used for batch sending. See the official documentation
|
* This class is used for batch sending. See the official documentation (link below)
|
||||||
for usage instructions.
|
* for usage instructions.
|
||||||
*/
|
*
|
||||||
|
* @link https://github.com/mailgun/mailgun-php/blob/master/src/Mailgun/Messages/README.md
|
||||||
|
*/
|
||||||
class BatchMessage extends MessageBuilder{
|
class BatchMessage extends MessageBuilder{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
private $batchRecipientAttributes;
|
private $batchRecipientAttributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
private $autoSend;
|
private $autoSend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Mailgun\Connection\RestClient
|
||||||
|
*/
|
||||||
private $restClient;
|
private $restClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
private $workingDomain;
|
private $workingDomain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
private $messageIds = array();
|
private $messageIds = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Mailgun\Connection\RestClient $restClient
|
||||||
|
* @param string $workingDomain
|
||||||
|
* @param boolean $autoSend
|
||||||
|
*/
|
||||||
public function __construct($restClient, $workingDomain, $autoSend){
|
public function __construct($restClient, $workingDomain, $autoSend){
|
||||||
$this->batchRecipientAttributes = array();
|
$this->batchRecipientAttributes = array();
|
||||||
$this->autoSend = $autoSend;
|
$this->autoSend = $autoSend;
|
||||||
@ -27,11 +53,18 @@ class BatchMessage extends MessageBuilder{
|
|||||||
$this->endpointUrl = $workingDomain . "/messages";
|
$this->endpointUrl = $workingDomain . "/messages";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $headerName
|
||||||
|
* @param string $address
|
||||||
|
* @param array $variables
|
||||||
|
* @throws MissingRequiredMIMEParameters
|
||||||
|
* @throws TooManyParameters
|
||||||
|
*/
|
||||||
protected function addRecipient($headerName, $address, $variables){
|
protected function addRecipient($headerName, $address, $variables){
|
||||||
if(array_key_exists($headerName, $this->counters['recipients'])){
|
if(array_key_exists($headerName, $this->counters['recipients'])){
|
||||||
if($this->counters['recipients'][$headerName] == RECIPIENT_COUNT_LIMIT){
|
if($this->counters['recipients'][$headerName] == Api::RECIPIENT_COUNT_LIMIT){
|
||||||
if($this->autoSend == false){
|
if($this->autoSend == false){
|
||||||
throw new TooManyParameters(TOO_MANY_RECIPIENTS);
|
throw new TooManyParameters(ExceptionMessages::TOO_MANY_RECIPIENTS);
|
||||||
}
|
}
|
||||||
$this->sendMessage();
|
$this->sendMessage();
|
||||||
}
|
}
|
||||||
@ -58,22 +91,27 @@ class BatchMessage extends MessageBuilder{
|
|||||||
$this->batchRecipientAttributes["$address"] = $variables;
|
$this->batchRecipientAttributes["$address"] = $variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $message
|
||||||
|
* @param array $files
|
||||||
|
* @throws MissingRequiredMIMEParameters
|
||||||
|
*/
|
||||||
public function sendMessage($message = array(), $files = array()){
|
public function sendMessage($message = array(), $files = array()){
|
||||||
if(count($message) < 1){
|
if(count($message) < 1){
|
||||||
$message = $this->message;
|
$message = $this->message;
|
||||||
$files = $this->files;
|
$files = $this->files;
|
||||||
}
|
}
|
||||||
if(!array_key_exists("from", $message)){
|
if(!array_key_exists("from", $message)){
|
||||||
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||||
}
|
}
|
||||||
elseif(!array_key_exists("to", $message)){
|
elseif(!array_key_exists("to", $message)){
|
||||||
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||||
}
|
}
|
||||||
elseif(!array_key_exists("subject", $message)){
|
elseif(!array_key_exists("subject", $message)){
|
||||||
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||||
}
|
}
|
||||||
elseif((!array_key_exists("text", $message) && !array_key_exists("html", $message))){
|
elseif((!array_key_exists("text", $message) && !array_key_exists("html", $message))){
|
||||||
throw new MissingRequiredMIMEParameters(EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
throw new MissingRequiredMIMEParameters(ExceptionMessages::EXCEPTION_MISSING_REQUIRED_MIME_PARAMETERS);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
|
$message["recipient-variables"] = json_encode($this->batchRecipientAttributes);
|
||||||
@ -87,10 +125,16 @@ class BatchMessage extends MessageBuilder{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws MissingRequiredMIMEParameters
|
||||||
|
*/
|
||||||
public function finalize(){
|
public function finalize(){
|
||||||
return $this->sendMessage();
|
$this->sendMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
public function getMessageIds(){
|
public function getMessageIds(){
|
||||||
return $this->messageIds;
|
return $this->messageIds;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user