diff --git a/CHANGELOG b/CHANGELOG index ddcd217..56bb1ac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +Date 2025-11-19 +Version 1.12.2 +- Fix properties + Date 2025-11-17 Version 1.12.1 - Fix encoding issue in path for unsubscribeContactByExternalId diff --git a/src/AbstractMaileonService.php b/src/AbstractMaileonService.php index fff9863..05e0aad 100644 --- a/src/AbstractMaileonService.php +++ b/src/AbstractMaileonService.php @@ -181,96 +181,6 @@ public function get( return $this->performRequest($curlSession, $deserializationType); } - /** - * Performs a PUT operation (i.e. an update) on a resource. - * - * @param string $resourcePath the path of the resource to PUT - * @param string $payload the payload data to PUT, i.e. the data to update the current state of the resource with - * @param array $queryParameters any additional query parameters - * @param string $mimeType the acceptable response MIME type - * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) - * to deserialize arrays of a type. - * - * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() - * - * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred - */ - public function put( - $resourcePath, - $payload = '', - $queryParameters = [], - $mimeType = 'application/vnd.maileon.api+xml', - $deserializationType = null - ) { - $curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType); - - /* - * PUT does not work as expected when passing post data, see - * http://developers.sugarcrm.com/wordpress/2011/11/22/howto-do-put-requests-with-php-curl-without-writing-to-a-file/ - * Because of this, we use a custom request here. - */ - curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload); - - return $this->performRequest($curlSession, $deserializationType); - } - - /** - * Performs a POST operation (i.e. creates a new instance) on a resource. - * - * @param string $resourcePath the path of the resource to POST. This is typically the parent (or owner) resource of the resource - * instance to create. - * @param string $payload the data to POST, i.e. the contents of the new resource instance - * @param array $queryParameters any additional query parameters - * @param string $mimeType the acceptable response MIME type - * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to - * deserialize arrays of a type. - * - * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() - * - * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred - */ - public function post( - $resourcePath, - $payload = '', - $queryParameters = [], - $mimeType = 'application/vnd.maileon.api+xml', - $deserializationType = null, - $contentType = null, - $contentLength = null - ) { - $curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType, $contentType, $contentLength); - curl_setopt($curlSession, CURLOPT_POST, true); - curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload); - - return $this->performRequest($curlSession, $deserializationType); - } - - /** - * Performs a DELETE operation on a resource. - * - * @param string $resourcePath the resource to DELETE - * @param array $queryParameters any additional query parameters - * @param string $mimeType the acceptable response MIME type - * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to - * deserialize arrays of a type. - * - * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() - * - * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred - */ - public function delete( - $resourcePath, - $queryParameters = [], - $mimeType = 'application/vnd.maileon.api+xml', - $deserializationType = null - ) { - $curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType); - curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'DELETE'); - - return $this->performRequest($curlSession, $deserializationType); - } - /** * @param $resourcePath * @param $queryParameters @@ -422,30 +332,6 @@ private function performRequest( } } - protected function appendArrayFields( - $params, - $name, - $fieldValues - ) { - if (is_array($fieldValues) && ! empty($fieldValues)) { - $params [(string) $name] = []; - - foreach ($fieldValues as $value) { - if ($value === true) { - $params [(string) $name] [] = 'true'; - } elseif ($value === false) { - $params [(string) $name] [] = 'false'; - } elseif ($value instanceof PreferenceCategory) { - $params[$name] = urlencode((string) $value->name); - } else { - $params [(string) $name] [] = urlencode($value); - } - } - } - - return $params; - } - private function printDebugInformation( $curlSession, $result = null, @@ -506,4 +392,118 @@ private function printDebugInformation( $this->verboseOut = null; } } + + /** + * Performs a PUT operation (i.e. an update) on a resource. + * + * @param string $resourcePath the path of the resource to PUT + * @param string $payload the payload data to PUT, i.e. the data to update the current state of the resource with + * @param array $queryParameters any additional query parameters + * @param string $mimeType the acceptable response MIME type + * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) + * to deserialize arrays of a type. + * + * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() + * + * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred + */ + public function put( + $resourcePath, + $payload = '', + $queryParameters = [], + $mimeType = 'application/vnd.maileon.api+xml', + $deserializationType = null + ) { + $curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType); + + /* + * PUT does not work as expected when passing post data, see + * http://developers.sugarcrm.com/wordpress/2011/11/22/howto-do-put-requests-with-php-curl-without-writing-to-a-file/ + * Because of this, we use a custom request here. + */ + curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload); + + return $this->performRequest($curlSession, $deserializationType); + } + + /** + * Performs a POST operation (i.e. creates a new instance) on a resource. + * + * @param string $resourcePath the path of the resource to POST. This is typically the parent (or owner) resource of the resource + * instance to create. + * @param string $payload the data to POST, i.e. the contents of the new resource instance + * @param array $queryParameters any additional query parameters + * @param string $mimeType the acceptable response MIME type + * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to + * deserialize arrays of a type. + * + * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() + * + * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred + */ + public function post( + $resourcePath, + $payload = '', + $queryParameters = [], + $mimeType = 'application/vnd.maileon.api+xml', + $deserializationType = null, + $contentType = null, + $contentLength = null + ) { + $curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType, $contentType, $contentLength); + curl_setopt($curlSession, CURLOPT_POST, true); + curl_setopt($curlSession, CURLOPT_POSTFIELDS, $payload); + + return $this->performRequest($curlSession, $deserializationType); + } + + /** + * Performs a DELETE operation on a resource. + * + * @param string $resourcePath the resource to DELETE + * @param array $queryParameters any additional query parameters + * @param string $mimeType the acceptable response MIME type + * @param mixed $deserializationType The name of the class this result should be deserialized as. Use array( 'array', 'typename' ) to + * deserialize arrays of a type. + * + * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() + * + * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred + */ + public function delete( + $resourcePath, + $queryParameters = [], + $mimeType = 'application/vnd.maileon.api+xml', + $deserializationType = null + ) { + $curlSession = $this->prepareSession($resourcePath, $queryParameters, $mimeType); + curl_setopt($curlSession, CURLOPT_CUSTOMREQUEST, 'DELETE'); + + return $this->performRequest($curlSession, $deserializationType); + } + + protected function appendArrayFields( + $params, + $name, + $fieldValues + ) { + if (is_array($fieldValues) && ! empty($fieldValues)) { + $params [(string) $name] = []; + + foreach ($fieldValues as $value) { + if ($value === true) { + $params [(string) $name] [] = 'true'; + } elseif ($value === false) { + $params [(string) $name] [] = 'false'; + } elseif ($value instanceof PreferenceCategory) { + $params[$name] = urlencode((string) $value->name); + } else { + $params [(string) $name] [] = urlencode($value); + } + } + } + + return $params; + } } diff --git a/src/MaileonAPIResult.php b/src/MaileonAPIResult.php index cf9cd7f..598f558 100644 --- a/src/MaileonAPIResult.php +++ b/src/MaileonAPIResult.php @@ -71,6 +71,22 @@ public function __construct( $this->checkResult($throwException); } + private function getBodyFromCurlResponse( + $curlSession, + $response + ) { + if ($response === null) { + return null; + } + + // In a recent case, a CMS2 mailing contained \r\n\r\n, so the old approach failed (https://stackoverflow.com/questions/10589889/returning-header-as-array-using-curl). + // Now, we use CURLINFO_HEADER_SIZE (https://blog.devgenius.io/how-to-get-the-response-headers-with-curl-in-php-2173b10d4fc5) and only split up the headers at \r\n\r\n. + // CURLINFO_HEADER_SIZE returns the size of the header including \r\n\r\n. + $headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE); + + return substr($response, $headerSize); + } + private function getHeaderArrayFromCurlResponse( $curlSession, $response @@ -102,22 +118,6 @@ private function getHeaderArrayFromCurlResponse( return $headers; } - private function getBodyFromCurlResponse( - $curlSession, - $response - ) { - if ($response === null) { - return null; - } - - // In a recent case, a CMS2 mailing contained \r\n\r\n, so the old approach failed (https://stackoverflow.com/questions/10589889/returning-header-as-array-using-curl). - // Now, we use CURLINFO_HEADER_SIZE (https://blog.devgenius.io/how-to-get-the-response-headers-with-curl-in-php-2173b10d4fc5) and only split up the headers at \r\n\r\n. - // CURLINFO_HEADER_SIZE returns the size of the header including \r\n\r\n. - $headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE); - - return substr($response, $headerSize); - } - /** * @param $throwException * @@ -137,30 +137,6 @@ private function checkResult($throwException) } } - private function checkForCURLError() - { - if (curl_errno($this->curlSession)) { - $curlErrorMessage = curl_error($this->curlSession); - $curlErrorCode = curl_errno($this->curlSession); - throw new MaileonAPIException( - "An error occurred in the connection to the REST API. Original cURL error message: $curlErrorMessage", - $curlErrorCode - ); - } - } - - private function checkForServerError() - { - $statusCode = $this->statusCode; - - if ($statusCode >= 500 && $statusCode <= 599) { - throw new MaileonAPIException( - "A server error occurred in the REST API (HTTP status code $statusCode).", - $this->bodyData - ); - } - } - /** * @return void * @@ -192,36 +168,44 @@ private function setResultFields() } } - /** - * @return mixed The deserialized result object as a subclass of AbstractXMLWrapper, or the free-form string result if the response body data was not a deserializable object, or null if there was no response body data - */ - public function getResult() - { - return $this->result; + private function startsWith( + $haystack, + $needle + ): bool { + // search backwards starting from haystack length characters from the end + return $needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false; } - /** - * @return int The HTTP status code that was returned by the HTTP request - */ - public function getStatusCode(): int + private function checkForCURLError() { - return $this->statusCode; + if (curl_errno($this->curlSession)) { + $curlErrorMessage = curl_error($this->curlSession); + $curlErrorCode = curl_errno($this->curlSession); + throw new MaileonAPIException( + "An error occurred in the connection to the REST API. Original cURL error message: $curlErrorMessage", + $curlErrorCode + ); + } } - /** - * @return bool true if a 2xx status code (success) was returned by the HTTP request - */ - public function isSuccess(): bool + private function checkForServerError() { - return $this->statusCode >= 200 and $this->statusCode <= 299; + $statusCode = $this->statusCode; + + if ($statusCode >= 500 && $statusCode <= 599) { + throw new MaileonAPIException( + "A server error occurred in the REST API (HTTP status code $statusCode).", + $this->bodyData + ); + } } /** - * @return bool true if a 4xx status code (client error) was returned by the HTTP request + * @return mixed The deserialized result object as a subclass of AbstractXMLWrapper, or the free-form string result if the response body data was not a deserializable object, or null if there was no response body data */ - public function isClientError(): bool + public function getResult() { - return $this->statusCode >= 400 and $this->statusCode <= 499; + return $this->result; } /** @@ -310,11 +294,27 @@ public function toString(): string return $result; } - private function startsWith( - $haystack, - $needle - ): bool { - // search backwards starting from haystack length characters from the end - return $needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false; + /** + * @return int The HTTP status code that was returned by the HTTP request + */ + public function getStatusCode(): int + { + return $this->statusCode; + } + + /** + * @return bool true if a 2xx status code (success) was returned by the HTTP request + */ + public function isSuccess(): bool + { + return $this->statusCode >= 200 and $this->statusCode <= 299; + } + + /** + * @return bool true if a 4xx status code (client error) was returned by the HTTP request + */ + public function isClientError(): bool + { + return $this->statusCode >= 400 and $this->statusCode <= 499; } } diff --git a/src/account/AccountService.php b/src/account/AccountService.php index 43add8b..dd3918d 100644 --- a/src/account/AccountService.php +++ b/src/account/AccountService.php @@ -74,6 +74,24 @@ public function setAccountPlaceholders($accountPlaceholders) ); } + /** + * Append a SimpleXMLElement to another + * + * @param SimpleXMLElement $to + * @param SimpleXMLElement $from + * + * @return void + */ + public function sxmlAppend( + SimpleXMLElement $to, + SimpleXMLElement $from + ) { + $toDom = dom_import_simplexml($to); + $fromDom = dom_import_simplexml($from); + + $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); + } + /** * Update account placeholders. If account placeholder is not existing yet, it will be added. * If account placeholder with given name is available the value will be updated. @@ -137,22 +155,4 @@ public function getAccountMailingDomains() 'application/xml' ); } - - /** - * Append a SimpleXMLElement to another - * - * @param SimpleXMLElement $to - * @param SimpleXMLElement $from - * - * @return void - */ - public function sxmlAppend( - SimpleXMLElement $to, - SimpleXMLElement $from - ) { - $toDom = dom_import_simplexml($to); - $fromDom = dom_import_simplexml($from); - - $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); - } } diff --git a/src/contacts/Permission.php b/src/contacts/Permission.php index fc8f017..0a38d33 100644 --- a/src/contacts/Permission.php +++ b/src/contacts/Permission.php @@ -21,22 +21,6 @@ class Permission public $code; public $type; - /** - * This is the initialization method for the permission types. This must be called once in the beginning. - */ - public static function init() - { - if (self::$initialized === false) { - self::$NONE = new Permission(1, 'none'); - self::$SOI = new Permission(2, 'soi'); - self::$COI = new Permission(3, 'coi'); - self::$DOI = new Permission(4, 'doi'); - self::$DOI_PLUS = new Permission(5, 'doi+'); - self::$OTHER = new Permission(6, 'other'); - self::$initialized = true; - } - } - /** * Constructor initializing the code of the permission. * @@ -55,28 +39,6 @@ public function __construct( } } - /** - * Get the code of this permission. - * 1 = NONE, 2 = SOI, 3 = COI, 4 = DOI, 5 = DOI+, 6 = OTHER. - * - * @return int The code of the permission object - */ - public function getCode(): int - { - return $this->code; - } - - /** - * Get the type string of this permission. - * none = NONE, soi = SOI, coi = COI, doi = DOI, doi+ = DOI+, other = OTHER. - * - * @return string The type of the permission object - */ - public function getString(): string - { - return $this->type; - } - private function getType($code) { switch ($code) { @@ -96,6 +58,22 @@ private function getType($code) } } + /** + * This is the initialization method for the permission types. This must be called once in the beginning. + */ + public static function init() + { + if (self::$initialized === false) { + self::$NONE = new Permission(1, 'none'); + self::$SOI = new Permission(2, 'soi'); + self::$COI = new Permission(3, 'coi'); + self::$DOI = new Permission(4, 'doi'); + self::$DOI_PLUS = new Permission(5, 'doi+'); + self::$OTHER = new Permission(6, 'other'); + self::$initialized = true; + } + } + /** * Get the permission object from the code * @@ -127,6 +105,28 @@ public static function getPermission($code) return self::$OTHER; } } + + /** + * Get the code of this permission. + * 1 = NONE, 2 = SOI, 3 = COI, 4 = DOI, 5 = DOI+, 6 = OTHER. + * + * @return int The code of the permission object + */ + public function getCode(): int + { + return $this->code; + } + + /** + * Get the type string of this permission. + * none = NONE, soi = SOI, coi = COI, doi = DOI, doi+ = DOI+, other = OTHER. + * + * @return string The type of the permission object + */ + public function getString(): string + { + return $this->type; + } } Permission::init(); diff --git a/src/contacts/SynchronizationMode.php b/src/contacts/SynchronizationMode.php index 3d3382b..d7476da 100644 --- a/src/contacts/SynchronizationMode.php +++ b/src/contacts/SynchronizationMode.php @@ -16,18 +16,6 @@ class SynchronizationMode public $code; - /** - * This is the initialization method for the synchronization modes. This must be called once in the beginning. - */ - public static function init() - { - if (self::$initialized === false) { - self::$UPDATE = new SynchronizationMode(1); - self::$IGNORE = new SynchronizationMode(2); - self::$initialized = true; - } - } - /** * Constructor initializing the code of the synchronization mode. * @@ -39,13 +27,15 @@ public function __construct($code = 0) } /** - * Get the code of this synchronization mode. 1 = UPDATE, 2 = IGNORE. - * - * @return int The code of the synchronization mode object + * This is the initialization method for the synchronization modes. This must be called once in the beginning. */ - public function getCode(): int + public static function init() { - return $this->code; + if (self::$initialized === false) { + self::$UPDATE = new SynchronizationMode(1); + self::$IGNORE = new SynchronizationMode(2); + self::$initialized = true; + } } /** @@ -65,6 +55,16 @@ public static function getSynchronizationMode($code) return self::$IGNORE; } } + + /** + * Get the code of this synchronization mode. 1 = UPDATE, 2 = IGNORE. + * + * @return int The code of the synchronization mode object + */ + public function getCode(): int + { + return $this->code; + } } SynchronizationMode::init(); diff --git a/src/json/AbstractJSONWrapper.php b/src/json/AbstractJSONWrapper.php index 1cc207d..5b5cc3f 100644 --- a/src/json/AbstractJSONWrapper.php +++ b/src/json/AbstractJSONWrapper.php @@ -33,6 +33,56 @@ public function __construct($params = []) } } + /** + * Used to initialize this object from JSON. Override this to modify JSON + * parameters. + * + * @param array $object_vars The array from json_decode + */ + public function fromArray($object_vars) + { + // copy each key to the property named the same way; if the property + // is a serializable Maileon class, call fromArray on it + foreach ($object_vars as $key => $value) { + if (class_exists(__CLASS__) + && is_subclass_of($this->{$key}, __CLASS__)) { + $this->{$key}->fromArray($value); + } else { + $this->{$key} = $value; + } + } + } + + /** + * Human-readable representation of this object + * + * @return string A human-readable representation of this object + */ + public function toString(): string + { + return $this->__toString(); + } + + /** + * Creates a string representation from this object in the following format: + * ObjectName [ property1=value1, property2=value2, ... , propertyN=valueN ] + * + * @return string + */ + public function __toString() + { + $object_vars = get_object_vars($this); + $elements = ''; + + // add each property of this class to a string + foreach ($object_vars as $key => $value) { + $flat = is_array($value) ? '[' . implode(',', $value) . ']' : $value; + $elements .= $key . '=' . $flat . ', '; + } + + return get_class($this) . ' [ ' . mb_substr($elements, 0, -2) . ' ]'; + } + protected function elementToArray($value) { // if $value is an object, we can call toArray on it, and it @@ -67,6 +117,16 @@ function($element) { return $value; } + /** + * Can be overridden in derived classes to signal that this object is empty + * + * @return boolean + */ + public function isEmpty(): bool + { + return false; + } + /** * Used to serialize this object to a JSON string. Override this to modify * JSON parameters. @@ -91,64 +151,4 @@ public function toArray(): array // return the resulting array return $result; } - - /** - * Used to initialize this object from JSON. Override this to modify JSON - * parameters. - * - * @param array $object_vars The array from json_decode - */ - public function fromArray($object_vars) - { - // copy each key to the property named the same way; if the property - // is a serializable Maileon class, call fromArray on it - foreach ($object_vars as $key => $value) { - if (class_exists(__CLASS__) - && is_subclass_of($this->{$key}, __CLASS__)) { - $this->{$key}->fromArray($value); - } else { - $this->{$key} = $value; - } - } - } - - /** - * Creates a string representation from this object in the following format: - * ObjectName [ property1=value1, property2=value2, ... , propertyN=valueN ] - * - * @return string - */ - public function __toString() - { - $object_vars = get_object_vars($this); - $elements = ''; - - // add each property of this class to a string - foreach ($object_vars as $key => $value) { - $flat = is_array($value) ? '[' . implode(',', $value) . ']' : $value; - $elements .= $key . '=' . $flat . ', '; - } - - return get_class($this) . ' [ ' . mb_substr($elements, 0, -2) . ' ]'; - } - - /** - * Human-readable representation of this object - * - * @return string A human-readable representation of this object - */ - public function toString(): string - { - return $this->__toString(); - } - - /** - * Can be overridden in derived classes to signal that this object is empty - * - * @return boolean - */ - public function isEmpty(): bool - { - return false; - } } diff --git a/src/mailings/DispatchLogicDeliveryLimitUnit.php b/src/mailings/DispatchLogicDeliveryLimitUnit.php index 06818b9..9bad3b8 100644 --- a/src/mailings/DispatchLogicDeliveryLimitUnit.php +++ b/src/mailings/DispatchLogicDeliveryLimitUnit.php @@ -26,17 +26,6 @@ class DispatchLogicDeliveryLimitUnit */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$DAY = new DispatchLogicDeliveryLimitUnit('day'); - self::$WEEK = new DispatchLogicDeliveryLimitUnit('week'); - self::$MONTH = new DispatchLogicDeliveryLimitUnit('month'); - self::$YEAR = new DispatchLogicDeliveryLimitUnit('year'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicDeliveryLimitUnit object. * @@ -47,12 +36,15 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the type descriptor string of this DispatchLogicDeliveryLimitUnit. Can be day, week, month or year. - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$DAY = new DispatchLogicDeliveryLimitUnit('day'); + self::$WEEK = new DispatchLogicDeliveryLimitUnit('week'); + self::$MONTH = new DispatchLogicDeliveryLimitUnit('month'); + self::$YEAR = new DispatchLogicDeliveryLimitUnit('year'); + self::$initialized = true; + } } /** @@ -77,6 +69,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the type descriptor string of this DispatchLogicDeliveryLimitUnit. Can be day, week, month or year. + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicDeliveryLimitUnit::init(); diff --git a/src/mailings/DispatchLogicInterval.php b/src/mailings/DispatchLogicInterval.php index da59192..614edc8 100644 --- a/src/mailings/DispatchLogicInterval.php +++ b/src/mailings/DispatchLogicInterval.php @@ -26,17 +26,6 @@ class DispatchLogicInterval */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$HOUR = new DispatchLogicInterval('hour'); - self::$DAY = new DispatchLogicInterval('day'); - self::$WEEK = new DispatchLogicInterval('week'); - self::$MONTH = new DispatchLogicInterval('month'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicInterval object. * @@ -47,12 +36,15 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the type descriptor string of this DispatchLogicInterval. Can be "hour", "day", "week" or "month". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$HOUR = new DispatchLogicInterval('hour'); + self::$DAY = new DispatchLogicInterval('day'); + self::$WEEK = new DispatchLogicInterval('week'); + self::$MONTH = new DispatchLogicInterval('month'); + self::$initialized = true; + } } /** @@ -77,6 +69,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the type descriptor string of this DispatchLogicInterval. Can be "hour", "day", "week" or "month". + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicInterval::init(); diff --git a/src/mailings/DispatchLogicRSSOrderBy.php b/src/mailings/DispatchLogicRSSOrderBy.php index 5768b9a..38f3481 100644 --- a/src/mailings/DispatchLogicRSSOrderBy.php +++ b/src/mailings/DispatchLogicRSSOrderBy.php @@ -25,16 +25,6 @@ class DispatchLogicRSSOrderBy */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$PUBDATE = new DispatchLogicRSSOrderBy('pubdate'); - self::$TITLE = new DispatchLogicRSSOrderBy('title'); - self::$LINK = new DispatchLogicRSSOrderBy('link'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicRSSOrderBy object. * @@ -45,12 +35,14 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the type descriptor string of this DispatchLogicRSSOrderBy. Can be "pubdate", "title" or "link". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$PUBDATE = new DispatchLogicRSSOrderBy('pubdate'); + self::$TITLE = new DispatchLogicRSSOrderBy('title'); + self::$LINK = new DispatchLogicRSSOrderBy('link'); + self::$initialized = true; + } } /** @@ -73,6 +65,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the type descriptor string of this DispatchLogicRSSOrderBy. Can be "pubdate", "title" or "link". + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicRSSOrderBy::init(); diff --git a/src/mailings/DispatchLogicRSSUniqueFeature.php b/src/mailings/DispatchLogicRSSUniqueFeature.php index 91b0266..ad67948 100644 --- a/src/mailings/DispatchLogicRSSUniqueFeature.php +++ b/src/mailings/DispatchLogicRSSUniqueFeature.php @@ -26,17 +26,6 @@ class DispatchLogicRSSUniqueFeature */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$DEFAULT = new DispatchLogicRSSUniqueFeature('default'); - self::$PUBDATE = new DispatchLogicRSSUniqueFeature('pubdate'); - self::$TITLE = new DispatchLogicRSSUniqueFeature('title'); - self::$LINK = new DispatchLogicRSSUniqueFeature('link'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicRSSUniqueFeature object. * @@ -47,12 +36,15 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the type descriptor string of this DispatchLogicRSSUniqueFeature. Can be "default", "pubdate", "title" or "link". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$DEFAULT = new DispatchLogicRSSUniqueFeature('default'); + self::$PUBDATE = new DispatchLogicRSSUniqueFeature('pubdate'); + self::$TITLE = new DispatchLogicRSSUniqueFeature('title'); + self::$LINK = new DispatchLogicRSSUniqueFeature('link'); + self::$initialized = true; + } } /** @@ -77,6 +69,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the type descriptor string of this DispatchLogicRSSUniqueFeature. Can be "default", "pubdate", "title" or "link". + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicRSSUniqueFeature::init(); diff --git a/src/mailings/DispatchLogicSpeedLevel.php b/src/mailings/DispatchLogicSpeedLevel.php index 3a79c59..52c774c 100644 --- a/src/mailings/DispatchLogicSpeedLevel.php +++ b/src/mailings/DispatchLogicSpeedLevel.php @@ -25,16 +25,6 @@ class DispatchLogicSpeedLevel */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$LOW = new DispatchLogicInterval('low'); - self::$MEDIUM = new DispatchLogicInterval('medium'); - self::$HIGH = new DispatchLogicInterval('high'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicSpeedLevel object. * @@ -45,12 +35,14 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the type descriptor string of this DispatchLogicSpeedLevel. Can be "low", "medium" or "high". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$LOW = new DispatchLogicInterval('low'); + self::$MEDIUM = new DispatchLogicInterval('medium'); + self::$HIGH = new DispatchLogicInterval('high'); + self::$initialized = true; + } } /** @@ -73,6 +65,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the type descriptor string of this DispatchLogicSpeedLevel. Can be "low", "medium" or "high". + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicSpeedLevel::init(); diff --git a/src/mailings/DispatchLogicTarget.php b/src/mailings/DispatchLogicTarget.php index c0b8334..6dee1de 100644 --- a/src/mailings/DispatchLogicTarget.php +++ b/src/mailings/DispatchLogicTarget.php @@ -25,16 +25,6 @@ class DispatchLogicTarget */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$EVENT = new DispatchLogicTarget('event'); - self::$CONTACTFILTER = new DispatchLogicTarget('contactfilter'); - self::$RSS = new DispatchLogicTarget('rss'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicTarget object. * @@ -45,12 +35,14 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the type descriptor string of this DispatchLogicTarget. Can be "event", "contactfilter" or "rss". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$EVENT = new DispatchLogicTarget('event'); + self::$CONTACTFILTER = new DispatchLogicTarget('contactfilter'); + self::$RSS = new DispatchLogicTarget('rss'); + self::$initialized = true; + } } /** @@ -74,6 +66,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the type descriptor string of this DispatchLogicTarget. Can be "event", "contactfilter" or "rss". + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicTarget::init(); diff --git a/src/mailings/DispatchLogicType.php b/src/mailings/DispatchLogicType.php index 9903be0..6b58416 100644 --- a/src/mailings/DispatchLogicType.php +++ b/src/mailings/DispatchLogicType.php @@ -24,15 +24,6 @@ class DispatchLogicType */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$SINGLE = new DispatchLogicType('single'); - self::$MULTI = new DispatchLogicType('multi'); - self::$initialized = true; - } - } - /** * Creates a new DispatchLogicType object. * @@ -43,12 +34,13 @@ public function __construct($value) $this->value = $value; } - /** - * @return string the DispatchLogicType descriptor string of this DispatchLogicType. Can be "single" or "multi". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$SINGLE = new DispatchLogicType('single'); + self::$MULTI = new DispatchLogicType('multi'); + self::$initialized = true; + } } /** @@ -69,6 +61,14 @@ public static function getObject($value) return null; } } + + /** + * @return string the DispatchLogicType descriptor string of this DispatchLogicType. Can be "single" or "multi". + */ + public function getValue(): string + { + return $this->value; + } } DispatchLogicType::init(); diff --git a/src/mailings/MailingsService.php b/src/mailings/MailingsService.php index f82faff..6a29180 100644 --- a/src/mailings/MailingsService.php +++ b/src/mailings/MailingsService.php @@ -1736,6 +1736,15 @@ public function addCustomProperties( ); } + public function sxmlAppend( + SimpleXMLElement $to, + SimpleXMLElement $from + ) { + $toDom = dom_import_simplexml($to); + $fromDom = dom_import_simplexml($from); + $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); + } + /** * Updates a custom property of the mailing with the provided id. * @@ -1913,15 +1922,6 @@ public function getMailingBlacklists($mailingId) return $this->get("mailings/$encodedMailingId/mailingblacklists/"); } - public function sxmlAppend( - SimpleXMLElement $to, - SimpleXMLElement $from - ) { - $toDom = dom_import_simplexml($to); - $fromDom = dom_import_simplexml($from); - $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); - } - /** * Get the configured recipient alias for the given mailing * diff --git a/src/reports/Block.php b/src/reports/Block.php index 974f2e6..0ca2d9e 100644 --- a/src/reports/Block.php +++ b/src/reports/Block.php @@ -15,7 +15,7 @@ class Block extends AbstractXMLWrapper { /** - * @var int + * @var string */ public $timestamp; @@ -109,11 +109,11 @@ public function toXML() $xml->addChild('timestamp', $this->timestamp); } - if (isset($this->old_status)) { + if (isset($this->oldStatus)) { $xml->addChild('old_status', $this->oldStatus); } - if (isset($this->new_status)) { + if (isset($this->newStatus)) { $xml->addChild('new_status', $this->newStatus); } diff --git a/src/reports/Bounce.php b/src/reports/Bounce.php index 3eb750c..4e633c0 100644 --- a/src/reports/Bounce.php +++ b/src/reports/Bounce.php @@ -132,7 +132,7 @@ public function toXML() $xml->addChild('contact', $this->contact->toXML()); } - if (isset($this->mailing_id)) { + if (isset($this->mailingId)) { $xml->addChild('mailing_id', $this->mailingId); } @@ -144,7 +144,7 @@ public function toXML() $xml->addChild('type', $this->type); } - if (isset($this->status_code)) { + if (isset($this->statusCode)) { $xml->addChild('status_code', $this->statusCode); } @@ -152,7 +152,7 @@ public function toXML() $xml->addChild('source', $this->source); } - if (isset($this->msg_id)) { + if (isset($this->messageId)) { $xml->addChild('msg_id', $this->messageId); } diff --git a/src/reports/Click.php b/src/reports/Click.php index cfdd95f..28d02fd 100644 --- a/src/reports/Click.php +++ b/src/reports/Click.php @@ -17,7 +17,7 @@ class Click extends AbstractXMLWrapper { /** - * @var int + * @var string */ public $timestamp; diff --git a/src/reports/Conversion.php b/src/reports/Conversion.php index dc74e70..663c51c 100644 --- a/src/reports/Conversion.php +++ b/src/reports/Conversion.php @@ -224,19 +224,19 @@ public function toXML() $xml->addChild('timestamp', $this->timestamp); } - if (isset($this->timestamp_sql)) { + if (isset($this->timestampSql)) { $xml->addChild('timestamp_sql', $this->timestampSql); } - if (isset($this->contact_id)) { + if (isset($this->contactId)) { $xml->addChild('contact_id', $this->contactId); } - if (isset($this->contact_email)) { + if (isset($this->contactEmail)) { $xml->addChild('contact_email', $this->contactEmail); } - if (isset($this->contact_external_id)) { + if (isset($this->contactExternalId)) { $xml->addChild('contact_external_id', $this->contactExternalId); } @@ -244,43 +244,43 @@ public function toXML() $xml->addChild('value', $this->value); } - if (isset($this->mailing_sent_date)) { + if (isset($this->mailingSentTimestamp)) { $xml->addChild('mailing_sent_date', $this->mailingSentTimestamp); } - if (isset($this->mailing_sent_date_sql)) { + if (isset($this->mailingSentTimestampSql)) { $xml->addChild('mailing_sent_date_sql', $this->mailingSentTimestampSql); } - if (isset($this->mailing_id)) { + if (isset($this->mailingId)) { $xml->addChild('mailing_id', $this->mailingId); } - if (isset($this->mailing_name)) { + if (isset($this->mailingName)) { $xml->addChild('mailing_name', $this->mailingName); } - if (isset($this->site_id)) { + if (isset($this->siteId)) { $xml->addChild('site_id', $this->siteId); } - if (isset($this->site_name)) { + if (isset($this->siteName)) { $xml->addChild('site_name', $this->siteName); } - if (isset($this->goal_id)) { + if (isset($this->goalId)) { $xml->addChild('goal_id', $this->goalId); } - if (isset($this->goal_name)) { + if (isset($this->goalName)) { $xml->addChild('goal_name', $this->goalName); } - if (isset($this->link_id)) { + if (isset($this->linkId)) { $xml->addChild('link_id', $this->linkId); } - if (isset($this->link_url)) { + if (isset($this->linkUrl)) { $xml->addChild('link_url', $this->linkUrl); } diff --git a/src/reports/Open.php b/src/reports/Open.php index 7d433fe..62e6f81 100644 --- a/src/reports/Open.php +++ b/src/reports/Open.php @@ -14,7 +14,7 @@ class Open extends AbstractXMLWrapper { /** - * @var int + * @var string */ public $timestamp; diff --git a/src/reports/Recipient.php b/src/reports/Recipient.php index 2147570..8a378f2 100644 --- a/src/reports/Recipient.php +++ b/src/reports/Recipient.php @@ -14,7 +14,7 @@ class Recipient extends AbstractXMLWrapper { /** - * @var int + * @var string */ public $timestamp; @@ -79,6 +79,10 @@ public function fromXML($xmlElement) if (isset($xmlElement->transaction_id)) { $this->transactionId = $xmlElement->transaction_id; } + + if (isset($xmlElement->msg_id)) { + $this->messageId = $xmlElement->msg_id; + } } /** @@ -111,6 +115,10 @@ public function toXML() $xml->addChild('transaction_id', $this->transactionId); } + if (isset($this->messageId)) { + $xml->addChild('msg_id', $this->messageId); + } + return $xml; } } diff --git a/src/reports/ReportsService.php b/src/reports/ReportsService.php index f608fbe..3d0b987 100644 --- a/src/reports/ReportsService.php +++ b/src/reports/ReportsService.php @@ -123,6 +123,84 @@ public function getOpens( ); } + /** + * Creates the common query parameters + * + * @param int $pageIndex The index of the result page. The index must be greater or equal to 1. + * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in + * The range 1 to 1000. + * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of + * from_date must be a numeric value representing a point in time milliseconds after + * January 1, 1970 00:00:00 + * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of + * to_date must be a numeric value representing a point in time milliseconds after + * January 1, 1970 00:00:00 + * @param array|null $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to + * a contact id. + * @param array|null $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses. + * @param array|null $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must + * correspond to a contacts external id. + * @param array|null $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to + * a mailing id. + * @param string|null $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link), + * a reply mail (reply) or other. + * @param bool|null $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been + * backed up for mailings because of a backup instruction. For each unsubscription, the + * corresponding field backups will be returned if available. Note that this only applies for non + * anonymizable field backups. + * + * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() + * + * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred + */ + private function createQueryParameters( + $pageIndex, + $pageSize, + $fromDate, + $toDate, + $contactIds, + $contactEmails, + $contactExternalIds, + $mailingIds, + $source, + $embedFieldBackups + ) { + $queryParameters = [ + 'page_index' => $pageIndex, + 'page_size' => $pageSize, + ]; + + if (isset($fromDate)) { + $queryParameters ['from_date'] = $fromDate; + } + + if (isset($toDate)) { + $queryParameters ['to_date'] = $toDate; + } + + if (isset($source)) { + $queryParameters ['source'] = $source; + } + + $queryParameters = $this->appendArrayFields($queryParameters, 'ids', $contactIds); + $queryParameters = $this->appendArrayFields($queryParameters, 'emails', $contactEmails); + $queryParameters = $this->appendArrayFields($queryParameters, 'eids', $contactExternalIds); + + if (isset($embedFieldBackups)) { + $queryParameters ['embed_field_backups'] = $embedFieldBackups === true ? 'true' : 'false'; + } + + if (isset($mailingIds)) { + $queryParameters ['mailing_id'] = []; + + foreach ($mailingIds as $mailingId) { + $queryParameters ['mailing_id'] [] = $mailingId; + } + } + + return $queryParameters; + } + /** * Returns a page of unique openers. * @@ -280,6 +358,67 @@ public function getOpensCount( ); } + /** + * Creates the common query parameters for count operations + * + * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of + * from_date must be a numeric value representing a point in time milliseconds after + * January 1, 1970 00:00:00 + * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of + * to_date must be a numeric value representing a point in time milliseconds after + * January 1, 1970 00:00:00 + * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to + * a contact id. + * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses. + * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond + * to a contacts external id. + * @param array|null $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to + * a mailing id. + * @param string $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link), + * a reply mail (reply) or other. + * + * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() + * + * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred + */ + private function createCountQueryParameters( + $fromDate, + $toDate, + $contactIds, + $contactEmails, + $contactExternalIds, + $mailingIds, + $source + ) { + $queryParameters = []; + + if (isset($fromDate)) { + $queryParameters ['from_date'] = $fromDate; + } + + if (isset($toDate)) { + $queryParameters ['to_date'] = $toDate; + } + + if (isset($source)) { + $queryParameters ['source'] = $source; + } + + $queryParameters = $this->appendArrayFields($queryParameters, 'ids', $contactIds); + $queryParameters = $this->appendArrayFields($queryParameters, 'emails', $contactEmails); + $queryParameters = $this->appendArrayFields($queryParameters, 'eids', $contactExternalIds); + + if (isset($mailingIds)) { + $queryParameters ['mailing_id'] = []; + + foreach ($mailingIds as $mailingId) { + $queryParameters ['mailing_id'] [] = $mailingId; + } + } + + return $queryParameters; + } + /** * Count unique openers. * @@ -1840,143 +1979,4 @@ public function getRevenue( $params ); } - - /** - * Creates the common query parameters - * - * @param int $pageIndex The index of the result page. The index must be greater or equal to 1. - * @param int $pageSize The maximum count of items in the result page. If provided, the value of page_size must be in - * The range 1 to 1000. - * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of - * from_date must be a numeric value representing a point in time milliseconds after - * January 1, 1970 00:00:00 - * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of - * to_date must be a numeric value representing a point in time milliseconds after - * January 1, 1970 00:00:00 - * @param array|null $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to - * a contact id. - * @param array|null $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses. - * @param array|null $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must - * correspond to a contacts external id. - * @param array|null $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to - * a mailing id. - * @param string|null $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link), - * a reply mail (reply) or other. - * @param bool|null $embedFieldBackups Supported values: true / false. Field Backups are the values of contact fields that have been - * backed up for mailings because of a backup instruction. For each unsubscription, the - * corresponding field backups will be returned if available. Note that this only applies for non - * anonymizable field backups. - * - * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() - * - * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred - */ - private function createQueryParameters( - $pageIndex, - $pageSize, - $fromDate, - $toDate, - $contactIds, - $contactEmails, - $contactExternalIds, - $mailingIds, - $source, - $embedFieldBackups - ) { - $queryParameters = [ - 'page_index' => $pageIndex, - 'page_size' => $pageSize, - ]; - - if (isset($fromDate)) { - $queryParameters ['from_date'] = $fromDate; - } - - if (isset($toDate)) { - $queryParameters ['to_date'] = $toDate; - } - - if (isset($source)) { - $queryParameters ['source'] = $source; - } - - $queryParameters = $this->appendArrayFields($queryParameters, 'ids', $contactIds); - $queryParameters = $this->appendArrayFields($queryParameters, 'emails', $contactEmails); - $queryParameters = $this->appendArrayFields($queryParameters, 'eids', $contactExternalIds); - - if (isset($embedFieldBackups)) { - $queryParameters ['embed_field_backups'] = $embedFieldBackups === true ? 'true' : 'false'; - } - - if (isset($mailingIds)) { - $queryParameters ['mailing_id'] = []; - - foreach ($mailingIds as $mailingId) { - $queryParameters ['mailing_id'] [] = $mailingId; - } - } - - return $queryParameters; - } - - /** - * Creates the common query parameters for count operations - * - * @param int $fromDate If provided, only the unsubscriptions after the given date will be returned. The value of - * from_date must be a numeric value representing a point in time milliseconds after - * January 1, 1970 00:00:00 - * @param int $toDate If provided, only the unsubscriptions before the given date will be returned. The value of - * to_date must be a numeric value representing a point in time milliseconds after - * January 1, 1970 00:00:00 - * @param array $contactIds Multivalued parameter to filter the unsubscriptions by contacts. Each value must correspond to - * a contact id. - * @param array $contactEmails Multivalued parameter to filter the unsubscriptions by email addresses. - * @param array $contactExternalIds Multivalued parameter to filter the unsubscriptions by external ids. Each value must correspond - * to a contacts external id. - * @param array|null $mailingIds Multivalued parameter to filter the unsubscriptions by mailings. Each value must correspond to - * a mailing id. - * @param string $source Filters the unsubscriptions by their source. The source can be an unsubscription link (link), - * a reply mail (reply) or other. - * - * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() - * - * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred - */ - private function createCountQueryParameters( - $fromDate, - $toDate, - $contactIds, - $contactEmails, - $contactExternalIds, - $mailingIds, - $source - ) { - $queryParameters = []; - - if (isset($fromDate)) { - $queryParameters ['from_date'] = $fromDate; - } - - if (isset($toDate)) { - $queryParameters ['to_date'] = $toDate; - } - - if (isset($source)) { - $queryParameters ['source'] = $source; - } - - $queryParameters = $this->appendArrayFields($queryParameters, 'ids', $contactIds); - $queryParameters = $this->appendArrayFields($queryParameters, 'emails', $contactEmails); - $queryParameters = $this->appendArrayFields($queryParameters, 'eids', $contactExternalIds); - - if (isset($mailingIds)) { - $queryParameters ['mailing_id'] = []; - - foreach ($mailingIds as $mailingId) { - $queryParameters ['mailing_id'] [] = $mailingId; - } - } - - return $queryParameters; - } } diff --git a/src/reports/Subscriber.php b/src/reports/Subscriber.php index 6d509d1..0f6e23a 100644 --- a/src/reports/Subscriber.php +++ b/src/reports/Subscriber.php @@ -16,7 +16,7 @@ class Subscriber extends AbstractXMLWrapper { /** - * @var int + * @var string */ public $timestamp; diff --git a/src/reports/Unsubscriber.php b/src/reports/Unsubscriber.php index 377ec1f..40cdf71 100644 --- a/src/reports/Unsubscriber.php +++ b/src/reports/Unsubscriber.php @@ -16,7 +16,7 @@ class Unsubscriber extends AbstractXMLWrapper { /** - * @var int + * @var string */ public $timestamp; diff --git a/src/transactions/DataType.php b/src/transactions/DataType.php index e971046..25a3813 100644 --- a/src/transactions/DataType.php +++ b/src/transactions/DataType.php @@ -31,21 +31,6 @@ class DataType */ public $value; - public static function init() - { - if (self::$initialized === false) { - self::$STRING = new DataType('string'); - self::$DOUBLE = new DataType('double'); - self::$FLOAT = new DataType('float'); - self::$INTEGER = new DataType('integer'); - self::$BOOLEAN = new DataType('boolean'); - self::$TIMESTAMP = new DataType('timestamp'); - self::$DATE = new DataType('date'); - self::$JSON = new DataType('json'); - self::$initialized = true; - } - } - /** * Creates a new DataType object. * @@ -58,12 +43,19 @@ public function __construct($value) $this->value = $value; } - /** - * @return string The type descriptor string of this DataType. Can be "string", "double", "float", "integer", "boolean", "timestamp" or "json". - */ - public function getValue(): string + public static function init() { - return $this->value; + if (self::$initialized === false) { + self::$STRING = new DataType('string'); + self::$DOUBLE = new DataType('double'); + self::$FLOAT = new DataType('float'); + self::$INTEGER = new DataType('integer'); + self::$BOOLEAN = new DataType('boolean'); + self::$TIMESTAMP = new DataType('timestamp'); + self::$DATE = new DataType('date'); + self::$JSON = new DataType('json'); + self::$initialized = true; + } } /** @@ -96,6 +88,14 @@ public static function getDataType($value) return null; } } + + /** + * @return string The type descriptor string of this DataType. Can be "string", "double", "float", "integer", "boolean", "timestamp" or "json". + */ + public function getValue(): string + { + return $this->value; + } } DataType::init(); diff --git a/src/transactions/TransactionsService.php b/src/transactions/TransactionsService.php index fae2925..c60c857 100644 --- a/src/transactions/TransactionsService.php +++ b/src/transactions/TransactionsService.php @@ -54,22 +54,6 @@ public function getTransactionTypes( ); } - /** - * Gets information about a transaction type. - * - * @param int $id the id of the transaction type to get information about - * - * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() - * - * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred - */ - public function getTransactionType($id) - { - $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8')); - - return $this->get("transactions/types/$encodedId"); - } - /** * Gets information about a transaction type by its name. * @@ -259,6 +243,22 @@ public function findTransactionTypeByName($type_name) return $this->getTransactionType($type_name); } + /** + * Gets information about a transaction type. + * + * @param int $id the id of the transaction type to get information about + * + * @return MaileonAPIResult|null The result object of the API call, internal result object available at MaileonAPIResult::getResult() + * + * @throws MaileonAPIException|Exception If there was a connection problem or a server error occurred + */ + public function getTransactionType($id) + { + $encodedId = rawurlencode(mb_convert_encoding((string) $id, 'UTF-8')); + + return $this->get("transactions/types/$encodedId"); + } + /** * Gets the last $count transaction events of a given transaction type. * diff --git a/src/xml/AbstractXMLWrapper.php b/src/xml/AbstractXMLWrapper.php index 800de6f..c05f406 100644 --- a/src/xml/AbstractXMLWrapper.php +++ b/src/xml/AbstractXMLWrapper.php @@ -15,13 +15,6 @@ */ abstract class AbstractXMLWrapper { - /** - * Initialization from a simple xml element. - * - * @param SimpleXMLElement $xmlElement the SimpleXMLElement to initialize the object from - */ - abstract public function fromXML($xmlElement); - /** * Initialization from a xml serialized string. * @@ -35,13 +28,11 @@ public function fromXMLString($xmlString) } /** - * Serialization to a simple XML element. - * - * @return SimpleXMLElement contains the serialized representation of the object + * Initialization from a simple xml element. * - * @throws Exception + * @param SimpleXMLElement $xmlElement the SimpleXMLElement to initialize the object from */ - abstract public function toXML(); + abstract public function fromXML($xmlElement); /** * Serialization to an XML string. @@ -55,6 +46,15 @@ public function toXMLString(): string return $this->toXML()->asXML(); } + /** + * Serialization to a simple XML element. + * + * @return SimpleXMLElement contains the serialized representation of the object + * + * @throws Exception + */ + abstract public function toXML(); + /** * Human-readable representation of the object * diff --git a/src/xml/XMLUtils.php b/src/xml/XMLUtils.php index 43f85d1..2acfbe8 100644 --- a/src/xml/XMLUtils.php +++ b/src/xml/XMLUtils.php @@ -16,22 +16,6 @@ abstract class XMLUtils { - /** - * This function appends one SimpleXMLElement to another one as addChild does not support deep copies - * - * @param SimpleXMLElement $to - * @param SimpleXMLElement $from - */ - public static function appendChild( - SimpleXMLElement $to, - SimpleXMLElement $from - ) { - $toDom = dom_import_simplexml($to); - $fromDom = dom_import_simplexml($from); - - $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); - } - /** * Adds a child with $value inside CDATA * @@ -57,4 +41,20 @@ public static function addChildAsCDATA( return $new_child; } + + /** + * This function appends one SimpleXMLElement to another one as addChild does not support deep copies + * + * @param SimpleXMLElement $to + * @param SimpleXMLElement $from + */ + public static function appendChild( + SimpleXMLElement $to, + SimpleXMLElement $from + ) { + $toDom = dom_import_simplexml($to); + $fromDom = dom_import_simplexml($from); + + $toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true)); + } } diff --git a/version.txt b/version.txt index aef099f..63b81f8 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ -dist.version = 1.12.1 -dist.version.stable = 1.12.1 +dist.version = 1.12.2 +dist.version.stable = 1.12.2