-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PHP8: remove frivolous docblocks * Added two new files types for viber * Added new whatsapp sticker type * Tests for ViberVideo * dynamic property
- Loading branch information
Showing
10 changed files
with
399 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Messages/Channel/Viber/MessageObjects/ViberActionObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\Viber\MessageObjects; | ||
|
||
use Vonage\Entity\Hydrator\ArrayHydrateInterface; | ||
|
||
class ViberActionObject implements ArrayHydrateInterface | ||
{ | ||
public function __construct(private string $url, private string $text = '') | ||
{ | ||
} | ||
|
||
public function fromArray(array $data): ViberActionObject | ||
{ | ||
$this->url = $data['url']; | ||
$this->text = $data['text']; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'url' => $this->getUrl(), | ||
'text' => $this->getText() | ||
]; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\Viber; | ||
|
||
use Vonage\Messages\MessageObjects\FileObject; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
class ViberFile extends BaseMessage | ||
{ | ||
use ViberServiceObjectTrait; | ||
|
||
protected string $channel = 'viber_service'; | ||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_FILE; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
protected FileObject $fileObject | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
$returnArray['file'] = $this->fileObject->toArray(); | ||
|
||
if ($this->requiresViberServiceObject()) { | ||
$this->getCategory() ? $returnArray['viber_service']['category'] = $this->getCategory(): null; | ||
$this->getTtl() ? $returnArray['viber_service']['ttl'] = $this->getTtl(): null; | ||
$this->getType() ? $returnArray['viber_service']['type'] = $this->getType(): null; | ||
} | ||
|
||
return $returnArray; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\Viber; | ||
|
||
use Vonage\Messages\MessageObjects\VideoObject; | ||
use Vonage\Messages\MessageTraits\TextTrait; | ||
use Vonage\Messages\Channel\BaseMessage; | ||
|
||
class ViberVideo extends BaseMessage | ||
{ | ||
use TextTrait; | ||
use ViberServiceObjectTrait; | ||
|
||
protected string $subType = BaseMessage::MESSAGES_SUBTYPE_VIDEO; | ||
protected string $channel = 'viber_service'; | ||
protected string $thumbUrl = ""; | ||
|
||
public function __construct( | ||
string $to, | ||
string $from, | ||
string $thumbUrl, | ||
protected VideoObject $videoObject | ||
) { | ||
$this->to = $to; | ||
$this->from = $from; | ||
$this->thumbUrl = $thumbUrl; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$returnArray = $this->getBaseMessageUniversalOutputArray(); | ||
$videoArray = $this->videoObject->toArray(); | ||
$videoArray['thumb_url'] = $this->thumbUrl; | ||
$returnArray['video'] = $videoArray; | ||
|
||
return $returnArray; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Messages/Channel/WhatsApp/MessageObjects/StickerObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Vonage\Messages\Channel\WhatsApp\MessageObjects; | ||
|
||
use Vonage\Entity\Hydrator\ArrayHydrateInterface; | ||
|
||
class StickerObject implements ArrayHydrateInterface | ||
{ | ||
public const STICKER_URL = 'url'; | ||
public const STICKER_ID = 'id'; | ||
|
||
private array $allowedTypes = [ | ||
self::STICKER_URL, | ||
self::STICKER_ID | ||
]; | ||
|
||
public function __construct(private string $type, private string $value = '') | ||
{ | ||
if (! in_array($type, $this->allowedTypes, true)) { | ||
throw new \InvalidArgumentException($type . ' is an invalid type of Sticker'); | ||
} | ||
} | ||
|
||
public function fromArray(array $data): StickerObject | ||
{ | ||
if (! in_array($data['type'], $this->allowedTypes, true)) { | ||
throw new \InvalidArgumentException($data['type'] . ' is an invalid type of Sticker'); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
*/ | ||
public function setType(string $type): void | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @param string $value | ||
*/ | ||
public function setValue(string $value): void | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [$this->getType() => $this->getValue()]; | ||
} | ||
} |
Oops, something went wrong.