CreatedByDeserializeCheck.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. *
  4. * Copyright 2018 gRPC authors.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. */
  19. namespace Grpc\Gcp;
  20. /**
  21. * DeserializeCheck is used to check whether _ChannelRef is created by deserialization or not.
  22. * If it is, $real_channel is invalid thus we need to recreate it using $opts.
  23. * If not, we can use $real_channel directly instead of creating a new one.
  24. * It is useful to handle 'force_new' channel option.
  25. * This is a private class
  26. */
  27. class CreatedByDeserializeCheck implements \Serializable
  28. {
  29. // TODO(ddyihai): remove it once the serialzer handler for \Grpc\Channel is implemented.
  30. private $data;
  31. public function __construct()
  32. {
  33. $this->data = 1;
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function serialize()
  39. {
  40. return '0';
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function __serialize()
  46. {
  47. return $this->serialize();
  48. }
  49. /**
  50. * @param string $data
  51. */
  52. public function unserialize($data)
  53. {
  54. $this->data = 1;
  55. }
  56. /**
  57. * @param string $data
  58. */
  59. public function __unserialize($data)
  60. {
  61. $this->unserialize($data);
  62. }
  63. /**
  64. * @param $data
  65. */
  66. public function setData($data)
  67. {
  68. $this->data = $data;
  69. }
  70. /**
  71. * @return int
  72. */
  73. public function getData()
  74. {
  75. return $this->data;
  76. }
  77. }