123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- /*
- * This file is part of the overtrue/easy-sms.
- *
- * (c) overtrue <i@overtrue.me>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace Overtrue\EasySms;
- use Overtrue\EasySms\Contracts\GatewayInterface;
- use Overtrue\EasySms\Contracts\MessageInterface;
- /**
- * Class Message.
- */
- class Message implements MessageInterface
- {
- /**
- * @var array
- */
- protected $gateways = [];
- /**
- * @var string
- */
- protected $type;
- /**
- * @var string
- */
- protected $content;
- /**
- * @var string
- */
- protected $template;
- /**
- * @var array
- */
- protected $data = [];
- /**
- * Message constructor.
- *
- * @param array $attributes
- * @param string $type
- */
- public function __construct(array $attributes = [], $type = MessageInterface::TEXT_MESSAGE)
- {
- $this->type = $type;
- foreach ($attributes as $property => $value) {
- if (property_exists($this, $property)) {
- $this->$property = $value;
- }
- }
- }
- /**
- * Return the message type.
- *
- * @return string
- */
- public function getMessageType()
- {
- return $this->type;
- }
- /**
- * Return message content.
- *
- * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway
- *
- * @return string
- */
- public function getContent(GatewayInterface $gateway = null)
- {
- return is_callable($this->content) ? call_user_func($this->content, $gateway) : $this->content;
- }
- /**
- * Return the template id of message.
- *
- * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway
- *
- * @return string
- */
- public function getTemplate(GatewayInterface $gateway = null)
- {
- return is_callable($this->template) ? call_user_func($this->template, $gateway) : $this->template;
- }
- /**
- * @param $type
- *
- * @return $this
- */
- public function setType($type)
- {
- $this->type = $type;
- return $this;
- }
- /**
- * @param mixed $content
- *
- * @return $this
- */
- public function setContent($content)
- {
- $this->content = $content;
- return $this;
- }
- /**
- * @param mixed $template
- *
- * @return $this
- */
- public function setTemplate($template)
- {
- $this->template = $template;
- return $this;
- }
- /**
- * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway
- *
- * @return array
- */
- public function getData(GatewayInterface $gateway = null)
- {
- return is_callable($this->data) ? call_user_func($this->data, $gateway) : $this->data;
- }
- /**
- * @param array|callable $data
- *
- * @return $this
- */
- public function setData($data)
- {
- $this->data = $data;
- return $this;
- }
- /**
- * @return array
- */
- public function getGateways()
- {
- return $this->gateways;
- }
- /**
- * @param array $gateways
- *
- * @return $this
- */
- public function setGateways(array $gateways)
- {
- $this->gateways = $gateways;
- return $this;
- }
- /**
- * @param $property
- *
- * @return string
- */
- public function __get($property)
- {
- if (property_exists($this, $property)) {
- return $this->$property;
- }
- }
- }
|