HttpCommonConfig.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\wechat\config;
  12. use crmeb\services\wechat\contract\ConfigHandlerInterface;
  13. use crmeb\services\wechat\contract\ServeConfigInterface;
  14. use crmeb\services\wechat\DefaultConfig;
  15. /**
  16. * Http请求配置
  17. * Class HttpCommonConfig
  18. * @package crmeb\services\wechat\config
  19. */
  20. class HttpCommonConfig implements ConfigHandlerInterface
  21. {
  22. /**
  23. * @var bool[]
  24. */
  25. protected $config = [
  26. 'verify' => false,
  27. ];
  28. /**
  29. * @var string
  30. */
  31. protected $serve;
  32. /**
  33. * @param string $serve
  34. * @return $this
  35. */
  36. public function setServe(string $serve)
  37. {
  38. $this->serve = $serve;
  39. return $this;
  40. }
  41. /**
  42. * 获取服务端实例
  43. * @return ServeConfigInterface
  44. */
  45. public function getServe()
  46. {
  47. return app()->make($this->serve);
  48. }
  49. /**
  50. * 直接获取配置
  51. * @param string $key
  52. * @param null $default
  53. * @return mixed
  54. */
  55. public function getConfig(string $key, $default = null)
  56. {
  57. return $this->getServe()->getConfig(DefaultConfig::value($key), $default);
  58. }
  59. /**
  60. * @param string $key
  61. * @param $value
  62. * @return $this|mixed
  63. */
  64. public function set(string $key, $value)
  65. {
  66. $this->config[$key] = $value;
  67. return $this;
  68. }
  69. /**
  70. * @param string|null $key
  71. * @return bool|bool[]|mixed
  72. */
  73. public function get(string $key = null)
  74. {
  75. if ($key) {
  76. return $this->config[$key];
  77. }
  78. return $this->config;
  79. }
  80. /**
  81. * @return array|bool[]
  82. */
  83. public function all(): array
  84. {
  85. return $this->config;
  86. }
  87. }