vendor/redjanym/php-firebase-cloud-messaging/src/Notification.php line 7

Open in your IDE?
  1. <?php
  2. namespace sngrl\PhpFirebaseCloudMessaging;
  3. /**
  4.  * @link https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
  5.  */
  6. class Notification extends Message
  7. {
  8.     private $title;
  9.     private $subtitle;
  10.     private $body;
  11.     private $badge;
  12.     private $icon;
  13.     private $image;
  14.     private $color;
  15.     private $sound;
  16.     private $clickAction;
  17.     private $tag;
  18.     private $contentAvailable;
  19.     private $bodyLocKey;
  20.     private $bodyLocArgs;
  21.     private $titleLocKey;
  22.     private $titleLocArgs;
  23.     private $androidChannelId;
  24.     public function __construct($title ''$body '')
  25.     {
  26.         if ($title)
  27.             $this->title $title;
  28.         if ($body)
  29.             $this->body $body;
  30.         parent::__construct();
  31.     }
  32.     public function setTitle($title)
  33.     {
  34.         $this->title $title;
  35.         return $this;
  36.     }
  37.     public function setBody($body)
  38.     {
  39.         $this->body $body;
  40.         return $this;
  41.     }
  42.     public function setImage($image)
  43.     {
  44.         $this->image $image;
  45.         return $this;
  46.     }
  47.     /**
  48.      * iOS only, will add smal red bubbles indicating the number of notifications to your apps icon
  49.      *
  50.      * @param integer $badge
  51.      * @return $this
  52.      */
  53.     public function setBadge($badge)
  54.     {
  55.         $this->badge $badge;
  56.         return $this;
  57.     }
  58.     /**
  59.      * android only, set the name of your drawable resource as string
  60.      *
  61.      * @param string $icon
  62.      * @return $this
  63.      */
  64.     public function setIcon($icon)
  65.     {
  66.         $this->icon $icon;
  67.         return $this;
  68.     }
  69.     
  70.     /**
  71.      * android only, set the color background resource as string
  72.      *
  73.      * @param string $color
  74.      * @return $this
  75.      */
  76.     public function setColor($color)
  77.     {
  78.         $this->color $color;
  79.         return $this;
  80.     }
  81.     public function setClickAction($actionName)
  82.     {
  83.         $this->clickAction $actionName;
  84.         return $this;
  85.     }
  86.     public function setSound($sound)
  87.     {
  88.         $this->sound $sound;
  89.         return $this;
  90.     }
  91.     public function setTag($tag)
  92.     {
  93.         $this->tag $tag;
  94.         return $this;
  95.     }
  96.     public function setContentAvailable($contentAvailable)
  97.     {
  98.         $this->contentAvailable $contentAvailable;
  99.         return $this;
  100.     }
  101.     public function setSubtitle($subtitle)
  102.     {
  103.         $this->subtitle $subtitle;
  104.         return $this;
  105.     }
  106.     public function setBodyLocKey($bodyLocKey)
  107.     {
  108.         $this->bodyLocKey $bodyLocKey;
  109.         return $this;
  110.     }
  111.     public function setBodyLocArgs($bodyLocArgs)
  112.     {
  113.         $this->bodyLocArgs $bodyLocArgs;
  114.         return $this;
  115.     }
  116.     public function setTitleLocKey($titleLocKey)
  117.     {
  118.         $this->titleLocKey $titleLocKey;
  119.         return $this;
  120.     }
  121.     public function setTitleLocArgs($titleLocArgs)
  122.     {
  123.         $this->titleLocArgs $titleLocArgs;
  124.         return $this;
  125.     }
  126.     public function setAndroidChannelId($androidChannelId)
  127.     {
  128.         $this->androidChannelId $androidChannelId;
  129.         return $this;
  130.     }
  131.     public function hasNotificationData()
  132.     {
  133.         return
  134.             $this->title ||
  135.             $this->body ||
  136.             $this->badge ||
  137.             $this->icon ||
  138.             $this->clickAction ||
  139.             $this->sound ||
  140.             $this->tag ||
  141.             $this->contentAvailable ||
  142.             $this->subtitle ||
  143.             $this->titleLocKey ||
  144.             $this->titleLocArgs ||
  145.             $this->bodyLocKey ||
  146.             $this->bodyLocArgs ||
  147.             $this->androidChannelId ||
  148.             $this->image
  149.         ;
  150.     }
  151.     public function jsonSerialize()
  152.     {
  153.         $jsonData = [];
  154.         if ($this->title) {
  155.             $jsonData['title'] = $this->title;
  156.         }
  157.         if ($this->body) {
  158.             $jsonData['body'] = $this->body;
  159.         }
  160.         if ($this->badge) {
  161.             $jsonData['badge'] = $this->badge;
  162.         }
  163.         if ($this->icon) {
  164.             $jsonData['icon'] = $this->icon;
  165.         }
  166.         if ($this->image) {
  167.             $jsonData['image'] = $this->image;
  168.         }
  169.         if ($this->color) {
  170.             $jsonData['color'] = $this->color;
  171.         }
  172.         if ($this->clickAction) {
  173.             $jsonData['click_action'] = $this->clickAction;
  174.         }
  175.         if ($this->sound) {
  176.             $jsonData['sound'] = $this->sound;
  177.         }
  178.         if ($this->tag) {
  179.             $jsonData['tag'] = $this->tag;
  180.         }
  181.         if ($this->contentAvailable) {
  182.             $jsonData['content_available'] = $this->contentAvailable;
  183.         }
  184.         if ($this->subtitle) {
  185.             $jsonData['subtitle'] = $this->subtitle;
  186.         }
  187.         if ($this->androidChannelId) {
  188.             $jsonData['android_channel_id'] = $this->androidChannelId;
  189.         }
  190.         if ($this->titleLocKey) {
  191.             $jsonData['title_loc_key'] = $this->titleLocKey;
  192.         }
  193.         if ($this->titleLocArgs) {
  194.             $jsonData['title_loc_args'] = $this->titleLocArgs;
  195.         }
  196.         if ($this->bodyLocKey) {
  197.             $jsonData['body_loc_key'] = $this->bodyLocKey;
  198.         }
  199.         if ($this->bodyLocArgs) {
  200.             $jsonData['body_loc_args'] = $this->bodyLocArgs;
  201.         }
  202.         return $jsonData;
  203.     }
  204. }