Catalog.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\Consul;
  12. class Catalog extends Client implements CatalogInterface
  13. {
  14. public function register($node): ConsulResponse
  15. {
  16. $params = [
  17. 'body' => json_encode($node),
  18. ];
  19. return $this->request('PUT', '/v1/catalog/register', $params);
  20. }
  21. public function deregister($node): ConsulResponse
  22. {
  23. $params = [
  24. 'body' => json_encode($node),
  25. ];
  26. return $this->request('PUT', '/v1/catalog/deregister', $params);
  27. }
  28. public function datacenters(): ConsulResponse
  29. {
  30. return $this->request('GET', '/v1/catalog/datacenters');
  31. }
  32. public function nodes(array $options = []): ConsulResponse
  33. {
  34. $params = [
  35. 'query' => $this->resolveOptions($options, ['dc']),
  36. ];
  37. return $this->request('GET', '/v1/catalog/nodes', $params);
  38. }
  39. public function node($node, array $options = []): ConsulResponse
  40. {
  41. $params = [
  42. 'query' => $this->resolveOptions($options, ['dc']),
  43. ];
  44. return $this->request('GET', '/v1/catalog/node/' . $node, $params);
  45. }
  46. public function services(array $options = []): ConsulResponse
  47. {
  48. $params = [
  49. 'query' => $this->resolveOptions($options, ['dc']),
  50. ];
  51. return $this->request('GET', '/v1/catalog/services', $params);
  52. }
  53. public function service($service, array $options = []): ConsulResponse
  54. {
  55. $params = [
  56. 'query' => $this->resolveOptions($options, ['dc', 'tag']),
  57. ];
  58. return $this->request('GET', '/v1/catalog/service/' . $service, $params);
  59. }
  60. }