diff --git a/src/BaseClient.php b/src/BaseClient.php index 3407738..785607c 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -59,9 +59,7 @@ public function __construct() */ public function initConfig() { - $config = require_once __DIR__ . '/config.php'; - - $this->config = $config; + $this->config = (new Config())->toArray(); } /** diff --git a/src/config.php b/src/config.php index 4d6aa25..8441b71 100644 --- a/src/config.php +++ b/src/config.php @@ -1,30 +1,74 @@ 'https://sms.crmeb.net/api/v2', +namespace Crmeb\Yihaotong; - 'base_cache_prefix' => 'sms-crmeb-yihaotong-', +/** + * + */ +class Config +{ - 'base_cache_timeout' => 300, + protected $baseUrl = 'https://sms.crmeb.net/api/v2'; - 'expires' => 3600, + protected $baseCachePrefix = 'sms-crmeb-yihaotong-'; - 'redis' => [ - // 服务器地址 + protected $baseCacheTimeout = 300; + + protected $expires = 3600; + + protected $redis = [ 'host' => '127.0.0.1', - // 端口 'port' => '6379', - // 密码 'password' => '', - // 缓存有效期 0表示永久缓存 'expire' => 0, - // 缓存前缀 'prefix' => '', - // 缓存标签前缀 'tag_prefix' => '', - // 数据库 0号数据库 'select' => 0, - 'timeout' => 0 - ], -]; + ]; + + public function setBaseUrl(string $baseUrl) + { + $this->baseUrl = $baseUrl; + return $this; + } + + public function setBaseCachePrefix(string $baseCachePrefix) + { + $this->baseCachePrefix = $baseCachePrefix; + return $this; + } + + public function setBaseCacheTimeout(int $baseCacheTimeout) + { + $this->baseCacheTimeout = $baseCacheTimeout; + return $this; + } + + public function setExpires(int $expires) + { + $this->expires = $expires; + return $this; + } + + public function setRedis(array $redis) + { + $this->redis = $redis; + return $this; + } + + /** + * @return array + */ + public function toArray() + { + return [ + 'base_url' => $this->baseUrl, + 'base_cache_prefix' => $this->baseCachePrefix, + 'base_cache_timeout' => $this->baseCacheTimeout, + 'expires' => $this->expires, + 'redis' => $this->redis, + ]; + } +} +