diff options
author | Hannes Kindströmmer <hannes@kindstrommer.se> | 2017-03-07 15:05:10 +0100 |
---|---|---|
committer | Hannes Kindströmmer <hannes@kindstrommer.se> | 2017-03-07 15:05:10 +0100 |
commit | 1dca08e87e4e9a7bb67b4b4689ab420577487c94 (patch) | |
tree | 22522a1adc646da33bad109bf023c9da1101e652 /src | |
parent | 05713de0aaac0f1836f27dbfba40dc3fa9c3d9e6 (diff) | |
download | ip1-php-sdk-1dca08e87e4e9a7bb67b4b4689ab420577487c94.zip ip1-php-sdk-1dca08e87e4e9a7bb67b4b4689ab420577487c94.tar.gz ip1-php-sdk-1dca08e87e4e9a7bb67b4b4689ab420577487c94.tar.bz2 |
jsonSerialize returns assoc array
Diffstat (limited to 'src')
-rw-r--r-- | src/SMS/OutGoingSMS.php | 22 | ||||
-rw-r--r-- | src/SMS/ProcessedOutGoingSMS.php | 17 | ||||
-rw-r--r-- | src/SMS/SMS.php | 15 |
3 files changed, 36 insertions, 18 deletions
diff --git a/src/SMS/OutGoingSMS.php b/src/SMS/OutGoingSMS.php index b78b6f7..4cbdb67 100644 --- a/src/SMS/OutGoingSMS.php +++ b/src/SMS/OutGoingSMS.php @@ -43,6 +43,7 @@ class OutGoingSMS extends SMS implements \JsonSerializable * Adds the number to the recipient list. * @param string $number A number that should be added to the recipient list */ + public function addNumber(string $number): void { $this->numbers[] = $number; @@ -153,25 +154,24 @@ class OutGoingSMS extends SMS implements \JsonSerializable /** {@inheritDoc} */ - public function jsonSerialize(): \stdClass + public function jsonSerialize(): array { - $returnObject = parent::jsonSerialize(); - $returnObject->Email = $this->email; - if (count($this->numbers) > 0) { - $returnObject->Numbers = $this->numbers; - } + + $returnArray = parent::jsonSerialize(); + $returnArray['Email'] = $this->email; + $returnArray['Numbers'] = $this->numbers; if (count($this->contacts) > 0) { - $returnObject->Contacts = []; + $returnArray['Contacts'] = []; foreach ($this->contacts as $contact) { - $returnObject->Contacts[] = $contact->getID(); + $returnArray['Contacts'][] = $contact->getID(); } } if (count($this->groups) > 0) { - $returnObject->Groups = []; + $returnArray['Groups'] = []; foreach ($this->groups as $group) { - $returnObject->Groups[] = $group->getID(); + $returnArray['Groups'][] = $group->getID(); } } - return $returnObject; + return $returnArray; } } diff --git a/src/SMS/ProcessedOutGoingSMS.php b/src/SMS/ProcessedOutGoingSMS.php index 7fce1d8..9c4e67f 100644 --- a/src/SMS/ProcessedOutGoingSMS.php +++ b/src/SMS/ProcessedOutGoingSMS.php @@ -66,5 +66,22 @@ class ProcessedOutGoingSMS extends OutGoingSMS $returnObject->Recipient = $this->recipient; } return $returnObject; + /** {@inheritDoc} */ + public function jsonSerialize(): array + { + $parentArray = parent::jsonSerialize(); + + $returnArray = [ + 'ID' => $this->smsID, + 'BundleID' => $this->bundleID, + 'Status' => $this->status, + 'StatusDescription' => $this->statusDescription, + 'To' => $this->recipient, + 'ModifiedDate' => $this->updated->format("Y-m-d\TH:i:s."). + substr($this->updated->format('u'), 0, 3) ?? null, + 'CreatedDate' => $this->created->format("Y-m-d\TH:i:s."). + substr($this->updated->format('u'), 0, 3) ?? null, + ]; + return array_filter(array_merge($parentArray, $returnArray)); } } diff --git a/src/SMS/SMS.php b/src/SMS/SMS.php index 9422e72..64455df 100644 --- a/src/SMS/SMS.php +++ b/src/SMS/SMS.php @@ -71,7 +71,7 @@ abstract class SMS implements \JsonSerializable "Sender number too long, max length is 18 digits", E_USER_WARNING ); - } elseif (strlen($sender) > 11) { + } elseif (preg_match("/[a-zA-Z]+/m", $sender) && strlen($sender) > 11) { trigger_error( "Sender string too long, non numeric senders have max length of 11 characters.", E_USER_WARNING @@ -83,12 +83,13 @@ abstract class SMS implements \JsonSerializable /** * {@inheritDoc} */ - public function jsonSerialize(): \stdClass + public function jsonSerialize(): array { - $returnObject = new \stdClass(); - $returnObject->Prio = $this->prio; - $returnObject->From = $this->from; - $returnObject->Message = $this->message; - return $returnObject; + $returnArray = [ + 'Prio' => $this->prio, + 'From' => $this->from, + 'Message'=> $this->message + ]; + return $returnArray; } } |