VisitorInterface.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. function prepare($data);
  39. /**
  40. * Controls whether keys will be preserved when serializing null values
  41. *
  42. * @param bool $serializeNull
  43. */
  44. public function setSerializeNull($serializeNull);
  45. /**
  46. * @param mixed $data
  47. * @param array $type
  48. *
  49. * @return mixed
  50. */
  51. function visitNull($data, array $type);
  52. /**
  53. * @param mixed $data
  54. * @param array $type
  55. *
  56. * @return mixed
  57. */
  58. function visitString($data, array $type);
  59. /**
  60. * @param mixed $data
  61. * @param array $type
  62. *
  63. * @return mixed
  64. */
  65. function visitBoolean($data, array $type);
  66. /**
  67. * @param mixed $data
  68. * @param array $type
  69. *
  70. * @return mixed
  71. */
  72. function visitDouble($data, array $type);
  73. /**
  74. * @param mixed $data
  75. * @param array $type
  76. *
  77. * @return mixed
  78. */
  79. function visitInteger($data, array $type);
  80. /**
  81. * @param mixed $data
  82. * @param array $type
  83. *
  84. * @return mixed
  85. */
  86. function visitArray($data, array $type);
  87. /**
  88. * Called before the properties of the object are being visited.
  89. *
  90. * @param ClassMetadata $metadata
  91. * @param mixed $data
  92. * @param array $type
  93. *
  94. * @return void
  95. */
  96. function startVisitingObject(ClassMetadata $metadata, $data, array $type);
  97. /**
  98. * @param PropertyMetadata $metadata
  99. * @param mixed $data
  100. *
  101. * @return void
  102. */
  103. function visitProperty(PropertyMetadata $metadata, $data);
  104. /**
  105. * Called after all properties of the object have been visited.
  106. *
  107. * @param ClassMetadata $metadata
  108. * @param mixed $data
  109. * @param array $type
  110. *
  111. * @return mixed
  112. */
  113. function endVisitingObject(ClassMetadata $metadata, $data, array $type);
  114. /**
  115. * Called before serialization/deserialization starts.
  116. *
  117. * @param GraphNavigator $navigator
  118. *
  119. * @return void
  120. */
  121. function setNavigator(GraphNavigator $navigator);
  122. /**
  123. * @return GraphNavigator
  124. */
  125. function getNavigator();
  126. /**
  127. * @return object|array|scalar
  128. */
  129. function getResult();
  130. }