123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Libs\Push\HuaWei\Admin\Msg\Notification;
- use Exception;
- class Notification
- {
- /**
- * optional
- */
- private $title;
- /**
- * optional
- */
- private $body;
- /**
- * optional
- */
- private $image;
- private $fields;
- public function __construct($title, $body, $image)
- {
- $this->title = $title;
- $this->body = $body;
- $this->image = $image;
- $this->fields = array();
- }
- public function title($value)
- {
- $this->title = $value;
- }
- public function body($value)
- {
- $this->body = $value;
- }
- public function image($value)
- {
- $this->image = $value;
- }
- public function getFields()
- {
- return $this->fields;
- }
- public function buildFields()
- {
- try {
- $this->check_parameter();
- } catch (Exception $e) {
- echo $e;
- }
- $keys = array(
- 'title',
- 'body',
- 'image'
- );
- foreach ($keys as $key) {
- if (isset($this->$key)) {
- $this->fields[$key] = $this->$key;
- }
- }
- }
- private function check_parameter()
- {
- if (empty($this->title)) {
- throw new Exception("title should be set");
- }
- if (empty($this->body)) {
- throw new Exception("body should be set");
- }
- }
- }
|