VisitorInterface.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\SerializerBundle\Serializer;
  18. use JMS\SerializerBundle\Metadata\ClassMetadata;
  19. use JMS\SerializerBundle\Metadata\PropertyMetadata;
  20. /**
  21. * Interface for visitors.
  22. *
  23. * This contains the minimal set of values that must be supported for any
  24. * output format.
  25. *
  26. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  27. */
  28. interface VisitorInterface
  29. {
  30. /**
  31. * Allows visitors to convert the input data to a different representation
  32. * before the actual serialization/deserialization process starts.
  33. *
  34. * @param mixed $data
  35. *
  36. * @return mixed
  37. */
  38. public function prepare($data);
  39. /**
  40. * Controls whether keys will be preserved when serializing null values
  41. *
  42. * @param bool $serializeNull
  43. * @return void
  44. */
  45. public function setSerializeNull($serializeNull);
  46. /**
  47. * @param mixed $data
  48. * @param array $type
  49. *
  50. * @return mixed
  51. */
  52. public function visitNull($data, array $type);
  53. /**
  54. * @param mixed $data
  55. * @param array $type
  56. *
  57. * @return mixed
  58. */
  59. public function visitString($data, array $type);
  60. /**
  61. * @param mixed $data
  62. * @param array $type
  63. *
  64. * @return mixed
  65. */
  66. public function visitBoolean($data, array $type);
  67. /**
  68. * @param mixed $data
  69. * @param array $type
  70. *
  71. * @return mixed
  72. */
  73. public function visitDouble($data, array $type);
  74. /**
  75. * @param mixed $data
  76. * @param array $type
  77. *
  78. * @return mixed
  79. */
  80. public function visitInteger($data, array $type);
  81. /**
  82. * @param mixed $data
  83. * @param array $type
  84. *
  85. * @return mixed
  86. */
  87. public function visitArray($data, array $type);
  88. /**
  89. * Called before the properties of the object are being visited.
  90. *
  91. * @param ClassMetadata $metadata
  92. * @param mixed $data
  93. * @param array $type
  94. *
  95. * @return void
  96. */
  97. public function startVisitingObject(ClassMetadata $metadata, $data, array $type);
  98. /**
  99. * @param PropertyMetadata $metadata
  100. * @param mixed $data
  101. *
  102. * @return void
  103. */
  104. public function visitProperty(PropertyMetadata $metadata, $data);
  105. /**
  106. * Called after all properties of the object have been visited.
  107. *
  108. * @param ClassMetadata $metadata
  109. * @param mixed $data
  110. * @param array $type
  111. *
  112. * @return mixed
  113. */
  114. public function endVisitingObject(ClassMetadata $metadata, $data, array $type);
  115. /**
  116. * Called before serialization/deserialization starts.
  117. *
  118. * @param GraphNavigator $navigator
  119. *
  120. * @return void
  121. */
  122. public function setNavigator(GraphNavigator $navigator);
  123. /**
  124. * @return GraphNavigator
  125. */
  126. public function getNavigator();
  127. /**
  128. * @return object|array|scalar
  129. */
  130. public function getResult();
  131. }