Config.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Nacos;
  12. use JetBrains\PhpStorm\ArrayShape;
  13. class Config
  14. {
  15. protected string $baseUri = 'http://127.0.0.1:8848/';
  16. protected ?string $username = null;
  17. protected ?string $password = null;
  18. protected ?string $accessKey = null;
  19. protected ?string $accessSecret = null;
  20. protected string $host = '127.0.0.1';
  21. protected int $port = 8848;
  22. protected array $grpc = [
  23. 'enable' => true,
  24. 'heartbeat' => 10,
  25. ];
  26. protected array $guzzleConfig = [
  27. 'headers' => [
  28. 'charset' => 'UTF-8',
  29. ],
  30. 'http_errors' => false,
  31. ];
  32. public function __construct(
  33. #[ArrayShape([
  34. 'base_uri' => 'string',
  35. 'username' => 'string',
  36. 'password' => 'string',
  37. 'access_key' => 'string',
  38. 'access_secret' => 'string',
  39. 'guzzle_config' => 'array',
  40. 'host' => 'string',
  41. 'port' => 'int',
  42. ])]
  43. array $config = []
  44. ) {
  45. isset($config['base_uri']) && $this->baseUri = (string) $config['base_uri'];
  46. isset($config['username']) && $this->username = (string) $config['username'];
  47. isset($config['password']) && $this->password = (string) $config['password'];
  48. isset($config['access_key']) && $this->accessKey = (string) $config['access_key'];
  49. isset($config['access_secret']) && $this->accessSecret = (string) $config['access_secret'];
  50. isset($config['guzzle_config']) && $this->guzzleConfig = (array) $config['guzzle_config'];
  51. isset($config['host']) && $this->host = (string) $config['host'];
  52. isset($config['port']) && $this->port = (int) $config['port'];
  53. isset($config['grpc']) && $this->grpc = array_replace($this->grpc, $config['grpc']);
  54. }
  55. public function getBaseUri(): string
  56. {
  57. return $this->baseUri;
  58. }
  59. public function getUsername(): ?string
  60. {
  61. return $this->username;
  62. }
  63. public function getPassword(): ?string
  64. {
  65. return $this->password;
  66. }
  67. public function getAccessKey(): ?string
  68. {
  69. return $this->accessKey;
  70. }
  71. public function getAccessSecret(): ?string
  72. {
  73. return $this->accessSecret;
  74. }
  75. public function getGuzzleConfig(): array
  76. {
  77. return $this->guzzleConfig;
  78. }
  79. public function getHost(): string
  80. {
  81. return $this->host;
  82. }
  83. public function getPort(): int
  84. {
  85. return $this->port;
  86. }
  87. public function getGrpc(): array
  88. {
  89. return $this->grpc;
  90. }
  91. }