message = $msg; $this->level = $level; } /** * Set delay. * * @param int $delay Delay in ms * * @return void * * @since 1.0.0 */ public function setDelay(int $delay) : void { $this->delay = $delay; } /** * Set delay. * * @param int $stay Stay in ms * * @return void * * @since 1.0.0 */ public function setStay(int $stay) : void { $this->stay = $stay; } /** * Set title. * * @param string $title Title * * @return void * * @since 1.0.0 */ public function setTitle(string $title) : void { $this->title = $title; } /** * Set message. * * @param string $message Message * * @return void * * @since 1.0.0 */ public function setMessage(string $message) : void { $this->message = $message; } /** * Set level/type. * * @param int $level Notification type/level * * @return void * * @since 1.0.0 */ public function setLevel(int $level) : void { $this->level = $level; } /** * Render message. * * @return string * * @since 1.0.0 */ public function __serialize() : string { return \json_encode($this->toArray()); } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } /** * {@inheritdoc} */ public function __unserialize($raw) : void { $unserialized = \json_decode($raw, true); $this->delay = $unserialized['time'] ?? 0; $this->stay = $unserialized['stay'] ?? 0; $this->message = $unserialized['msg'] ?? ''; $this->title = $unserialized['title'] ?? ''; $this->level = $unserialized['level'] ?? 0; } /** * Stringify. * * @return string * * @since 1.0.0 */ public function __toString() { return (string) \json_encode($this->toArray()); } /** * Generate message array. * * @return array * * @since 1.0.0 */ public function toArray() : array { return [ 'type' => self::TYPE, 'time' => $this->delay, 'stay' => $this->stay, 'msg' => $this->message, 'title' => $this->title, 'level' => $this->level, ]; } }