Skip to content

Commit

Permalink
Update Payload.php
Browse files Browse the repository at this point in the history
  • Loading branch information
KoIIIeY committed Mar 19, 2021
1 parent 3e965c1 commit cdeeb24
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/Payload.php
Expand Up @@ -135,7 +135,7 @@ public static function create(): Payload
/**
* Get Alert.
*
* @return Alert|null
* @return Alert|string|array|null
*/
public function getAlert()
{
Expand All @@ -145,13 +145,13 @@ public function getAlert()
/**
* Set Alert.
*
* @param Alert|string $alert
* @param Alert|string $alert|array $alert
*
* @return Payload
*/
public function setAlert($alert): Payload
{
if ($alert instanceof Alert || is_string($alert)) {
if ($alert instanceof Alert || is_string($alert) || is_array($alert)) {
$this->alert = $alert;
}

Expand Down Expand Up @@ -340,6 +340,26 @@ public function setUrlArgs(array $value): Payload
* @throws InvalidPayloadException
*/
public function setCustomValue(string $key, $value): Payload
{
if ($key === self::PAYLOAD_ROOT_KEY) {
throw InvalidPayloadException::reservedKey();
}

$this->customValues[$key] = $value;

return $this;
}

/**
* Merges custom value for Payload.
*
* @param string $key
* @param mixed $value
*
* @return Payload
* @throws InvalidPayloadException
*/
public function addCustomValue(string $key, $value): Payload
{
$this->customValues = array_merge_recursive($this->customValues ? $this->customValues : [], [$key => $value]);

Expand Down Expand Up @@ -417,6 +437,8 @@ public function jsonSerialize()
} else {
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_ALERT_KEY} = $this->alert;
}
} elseif (is_array($this->alert)){
$payload[self::PAYLOAD_ROOT_KEY]->{self::PAYLOAD_ALERT_KEY} = $this->alert;
}

if (is_int($this->badge)) {
Expand Down

0 comments on commit cdeeb24

Please sign in to comment.