Operations.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace YdbPlatform\Ydb;
  3. use Psr\Log\LoggerInterface;
  4. use Ydb\Operations\V1\OperationServiceClient as ServiceClient;
  5. class Operations
  6. {
  7. use Traits\RequestTrait;
  8. use Traits\ParseResultTrait;
  9. use Traits\LoggerTrait;
  10. /**
  11. * @var ServiceClient
  12. */
  13. protected $client;
  14. /**
  15. * @var array
  16. */
  17. protected $meta;
  18. /**
  19. * @var LoggerInterface
  20. */
  21. protected $logger;
  22. /**
  23. * @var Iam
  24. */
  25. protected $credentials;
  26. /**
  27. * @param Ydb $ydb
  28. * @param LoggerInterface|null $logger
  29. */
  30. public function __construct(Ydb $ydb, LoggerInterface $logger = null)
  31. {
  32. $this->ydb = $ydb;
  33. $this->client = new ServiceClient($ydb->endpoint(), [
  34. 'credentials' => $ydb->iam()->getCredentials(),
  35. ]);
  36. $this->meta = $ydb->meta();
  37. $this->credentials = $ydb->iam();
  38. $this->logger = $logger;
  39. }
  40. /**
  41. * @param string $id
  42. * @return bool|mixed|void
  43. */
  44. public function get(string $id)
  45. {
  46. return $this->request('GetOperation', [
  47. 'id' => $id,
  48. ]);
  49. }
  50. /**
  51. * @param string $id
  52. * @return bool|mixed|void
  53. */
  54. public function cancel(string $id)
  55. {
  56. return $this->request('CancelOperation', [
  57. 'id' => $id,
  58. ]);
  59. }
  60. /**
  61. * @param string $id
  62. * @return bool|mixed|void
  63. */
  64. public function forget(string $id)
  65. {
  66. return $this->request('ForgetOperation', [
  67. 'id' => $id,
  68. ]);
  69. }
  70. /**
  71. * @param $kind
  72. * @param int $page_size
  73. * @param string $page_token
  74. * @return bool|mixed|void
  75. */
  76. public function list($kind, int $page_size = 0, string $page_token = '')
  77. {
  78. return $this->request('ListOperations', [
  79. 'kind' => $kind,
  80. 'page_size' => $page_size,
  81. 'page_token' => $page_token,
  82. ]);
  83. }
  84. /**
  85. * @param string $method
  86. * @param array $data
  87. * @return bool|mixed|void
  88. */
  89. protected function request(string $method, array $data = [])
  90. {
  91. return $this->doRequest('Operations', $method, $data);
  92. }
  93. }