AbstractMessage.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. /**
  11. * AbstractMessage.php.
  12. *
  13. * @author overtrue <i@overtrue.me>
  14. * @copyright 2015 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\Message;
  20. use EasyWeChat\Support\Attribute;
  21. /**
  22. * Class AbstractMessage.
  23. */
  24. abstract class AbstractMessage extends Attribute
  25. {
  26. /**
  27. * Message type.
  28. *
  29. * @var string
  30. */
  31. protected $type;
  32. /**
  33. * Message id.
  34. *
  35. * @var int
  36. */
  37. protected $id;
  38. /**
  39. * Message target user open id.
  40. *
  41. * @var string
  42. */
  43. protected $to;
  44. /**
  45. * Message sender open id.
  46. *
  47. * @var string
  48. */
  49. protected $from;
  50. /**
  51. * Message attributes.
  52. *
  53. * @var array
  54. */
  55. protected $properties = [];
  56. /**
  57. * Return type name message.
  58. *
  59. * @return string
  60. */
  61. public function getType()
  62. {
  63. return $this->type;
  64. }
  65. /**
  66. * Magic getter.
  67. *
  68. * @param string $property
  69. *
  70. * @return mixed
  71. */
  72. public function __get($property)
  73. {
  74. if (property_exists($this, $property)) {
  75. return $this->$property;
  76. }
  77. return parent::__get($property);
  78. }
  79. /**
  80. * Magic setter.
  81. *
  82. * @param string $property
  83. * @param mixed $value
  84. *
  85. * @return AbstractMessage
  86. */
  87. public function __set($property, $value)
  88. {
  89. if (property_exists($this, $property)) {
  90. $this->$property = $value;
  91. } else {
  92. parent::__set($property, $value);
  93. }
  94. return $this;
  95. }
  96. }