Badge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Libs\Push\HuaWei\Admin\Msg\Android;
  3. use Exception;
  4. class Badge
  5. {
  6. private $add_num;
  7. private $class;
  8. private $set_num;
  9. private $fields;
  10. public function __construct()
  11. {
  12. $this->fields = array();
  13. }
  14. public function add_num($value)
  15. {
  16. $this->add_num = $value;
  17. }
  18. public function setclass($value)
  19. {
  20. $this->class = $value;
  21. }
  22. public function set_num($value)
  23. {
  24. $this->set_num = $value;
  25. }
  26. public function getFields()
  27. {
  28. return $this->fields;
  29. }
  30. public function buildFields()
  31. {
  32. try {
  33. $this->check_parameter();
  34. } catch (Exception $e) {
  35. echo $e;
  36. }
  37. $keys = array(
  38. 'add_num',
  39. 'class',
  40. 'set_num'
  41. );
  42. foreach ($keys as $key) {
  43. if (isset($this->$key)) {
  44. $this->fields[$key] = $this->$key;
  45. }
  46. }
  47. }
  48. private function check_parameter()
  49. {
  50. if (($this->add_num) && (gettype($this->add_num) != "integer")) {
  51. throw new Exception("type of add_num is wrong.");
  52. }
  53. if (is_int($this->add_num) && ($this->add_num < 1 || $this->add_num > 100)) {
  54. throw new Exception("add_num should locate between 0 and 100");
  55. }
  56. if (($this->set_num) && (gettype($this->set_num) != "integer")) {
  57. throw new Exception("type of set_num is wrong.");
  58. }
  59. if (is_int($this->set_num) && ($this->set_num < 1 || $this->set_num > 100)) {
  60. throw new Exception("set_num should locate between 0 and 100");
  61. }
  62. }
  63. }