Call.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /*
  3. * Copyright 2018 Google LLC
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. namespace Google\ApiCore;
  33. use Google\Protobuf\Internal\Message;
  34. /**
  35. * Contains information necessary to manage a network request.
  36. */
  37. class Call
  38. {
  39. const UNARY_CALL = 0;
  40. const BIDI_STREAMING_CALL = 1;
  41. const CLIENT_STREAMING_CALL = 2;
  42. const SERVER_STREAMING_CALL = 3;
  43. const LONGRUNNING_CALL = 4;
  44. const PAGINATED_CALL = 5;
  45. private $method;
  46. private $callType;
  47. private $decodeType;
  48. private $message;
  49. private $descriptor;
  50. /**
  51. * @param string $method
  52. * @param string $decodeType
  53. * @param mixed|Message $message
  54. * @param array|null $descriptor
  55. * @param int $callType
  56. */
  57. public function __construct(
  58. string $method,
  59. string $decodeType = null,
  60. $message = null,
  61. $descriptor = [],
  62. int $callType = Call::UNARY_CALL
  63. ) {
  64. $this->method = $method;
  65. $this->decodeType = $decodeType;
  66. $this->message = $message;
  67. $this->descriptor = $descriptor;
  68. $this->callType = $callType;
  69. }
  70. /**
  71. * @return string
  72. */
  73. public function getMethod()
  74. {
  75. return $this->method;
  76. }
  77. /**
  78. * @return int
  79. */
  80. public function getCallType()
  81. {
  82. return $this->callType;
  83. }
  84. /**
  85. * @return string
  86. */
  87. public function getDecodeType()
  88. {
  89. return $this->decodeType;
  90. }
  91. /**
  92. * @return mixed|Message
  93. */
  94. public function getMessage()
  95. {
  96. return $this->message;
  97. }
  98. /**
  99. * @return array|null
  100. */
  101. public function getDescriptor()
  102. {
  103. return $this->descriptor;
  104. }
  105. /**
  106. * @param mixed|Message $message
  107. * @return Call
  108. */
  109. public function withMessage($message)
  110. {
  111. // @phpstan-ignore-next-line
  112. return new static(
  113. $this->method,
  114. $this->decodeType,
  115. $message,
  116. $this->descriptor,
  117. $this->callType
  118. );
  119. }
  120. }