SystemConfigService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services;
  12. use app\services\system\config\SystemConfigServices;
  13. use crmeb\utils\Arr;
  14. /** 获取系统配置服务类
  15. * Class SystemConfigService
  16. * @package service
  17. */
  18. class SystemConfigService
  19. {
  20. const CACHE_SYSTEM = 'system_config';
  21. /**
  22. * 获取单个配置效率更高
  23. * @param string $key
  24. * @param $default
  25. * @param bool $isCaChe 是否获取缓存配置
  26. * @return bool|mixed|string
  27. */
  28. public static function get(string $key, $default = '', bool $isCaChe = false)
  29. {
  30. /** @var SystemConfigServices $service */
  31. $service = app()->make(SystemConfigServices::class);
  32. $callable = function () use ($service, $key) {
  33. return $service->getConfigValue($key);
  34. };
  35. try {
  36. return $callable();
  37. } catch (\Throwable $e) {
  38. return $default;
  39. }
  40. }
  41. /**
  42. * 获取多个配置
  43. * @param array $keys 示例 [['appid','1'],'appkey']
  44. * @param bool $isCaChe 是否获取缓存配置
  45. * @return array
  46. */
  47. public static function more(array $keys, bool $isCaChe = false)
  48. {
  49. /** @var SystemConfigServices $service */
  50. $service = app()->make(SystemConfigServices::class);
  51. $callable = function () use ($service, $keys) {
  52. return Arr::getDefaultValue($keys, $service->getConfigAll($keys));
  53. };
  54. try {
  55. return $callable();
  56. } catch (\Throwable $e) {
  57. return Arr::getDefaultValue($keys);
  58. }
  59. }
  60. }