| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?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\Gateways;
- use Overtrue\EasySms\Contracts\GatewayInterface;
- use Overtrue\EasySms\Support\Config;
- /**
- * Class Gateway.
- */
- abstract class Gateway implements GatewayInterface
- {
- const DEFAULT_TIMEOUT = 5.0;
- /**
- * @var \Overtrue\EasySms\Support\Config
- */
- protected $config;
- /**
- * @var array
- */
- protected $options;
- /**
- * @var float
- */
- protected $timeout;
- /**
- * Gateway constructor.
- *
- * @param array $config
- */
- public function __construct(array $config)
- {
- $this->config = new Config($config);
- }
- /**
- * Return timeout.
- *
- * @return int|mixed
- */
- public function getTimeout()
- {
- return $this->timeout ?: $this->config->get('timeout', self::DEFAULT_TIMEOUT);
- }
- /**
- * Set timeout.
- *
- * @param int $timeout
- *
- * @return $this
- */
- public function setTimeout($timeout)
- {
- $this->timeout = floatval($timeout);
- return $this;
- }
- /**
- * @return \Overtrue\EasySms\Support\Config
- */
- public function getConfig()
- {
- return $this->config;
- }
- /**
- * @param \Overtrue\EasySms\Support\Config $config
- *
- * @return $this
- */
- public function setConfig(Config $config)
- {
- $this->config = $config;
- return $this;
- }
- /**
- * @param $options
- *
- * @return $this
- */
- public function setGuzzleOptions($options)
- {
- $this->options = $options;
- return $this;
- }
- /**
- * @return array
- */
- public function getGuzzleOptions()
- {
- return $this->options ?: $this->config->get('options', []);
- }
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return \strtolower(str_replace([__NAMESPACE__.'\\', 'Gateway'], '', \get_class($this)));
- }
- }
|