AddressInterface.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace IPLib\Address;
  3. use IPLib\Range\RangeInterface;
  4. /**
  5. * Interface of all the IP address types.
  6. */
  7. interface AddressInterface
  8. {
  9. /**
  10. * Get the short string representation of this address.
  11. *
  12. * @return string
  13. */
  14. public function __toString();
  15. /**
  16. * Get the number of bits representing this address type.
  17. *
  18. * @return int
  19. *
  20. * @since 1.14.0
  21. *
  22. * @example 32 for IPv4
  23. * @example 128 for IPv6
  24. */
  25. public static function getNumberOfBits();
  26. /**
  27. * Get the string representation of this address.
  28. *
  29. * @param bool $long set to true to have a long/full representation, false otherwise
  30. *
  31. * @return string
  32. *
  33. * @example If $long is true, you'll get '0000:0000:0000:0000:0000:0000:0000:0001', '::1' otherwise.
  34. */
  35. public function toString($long = false);
  36. /**
  37. * Get the byte list of the IP address.
  38. *
  39. * @return int[]
  40. *
  41. * @example For localhost: for IPv4 you'll get array(127, 0, 0, 1), for IPv6 array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
  42. */
  43. public function getBytes();
  44. /**
  45. * Get the full bit list the IP address.
  46. *
  47. * @return string
  48. *
  49. * @since 1.14.0
  50. *
  51. * @example For localhost: For IPv4 you'll get '01111111000000000000000000000001' (32 digits), for IPv6 '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' (128 digits)
  52. */
  53. public function getBits();
  54. /**
  55. * Get the type of the IP address.
  56. *
  57. * @return int One of the \IPLib\Address\Type::T_... constants
  58. */
  59. public function getAddressType();
  60. /**
  61. * Get the default RFC reserved range type.
  62. *
  63. * @return int One of the \IPLib\Range\Type::T_... constants
  64. *
  65. * @since 1.5.0
  66. */
  67. public static function getDefaultReservedRangeType();
  68. /**
  69. * Get the RFC reserved ranges (except the ones of type getDefaultReservedRangeType).
  70. *
  71. * @return \IPLib\Address\AssignedRange[] ranges are sorted
  72. *
  73. * @since 1.5.0
  74. */
  75. public static function getReservedRanges();
  76. /**
  77. * Get the type of range of the IP address.
  78. *
  79. * @return int One of the \IPLib\Range\Type::T_... constants
  80. */
  81. public function getRangeType();
  82. /**
  83. * Get a string representation of this address than can be used when comparing addresses and ranges.
  84. *
  85. * @return string
  86. */
  87. public function getComparableString();
  88. /**
  89. * Check if this address is contained in an range.
  90. *
  91. * @param \IPLib\Range\RangeInterface $range
  92. *
  93. * @return bool
  94. */
  95. public function matches(RangeInterface $range);
  96. /**
  97. * Get the address at a certain distance from this address.
  98. *
  99. * @param int $n the distance of the address (can be negative)
  100. *
  101. * @return \IPLib\Address\AddressInterface|null return NULL if $n is not an integer or if the final address would be invalid
  102. *
  103. * @since 1.15.0
  104. *
  105. * @example passing 1 to the address 127.0.0.1 will result in 127.0.0.2
  106. * @example passing -1 to the address 127.0.0.1 will result in 127.0.0.0
  107. * @example passing -1 to the address 0.0.0.0 will result in NULL
  108. */
  109. public function getAddressAtOffset($n);
  110. /**
  111. * Get the address right after this IP address (if available).
  112. *
  113. * @return \IPLib\Address\AddressInterface|null
  114. *
  115. * @see \IPLib\Address\AddressInterface::getAddressAtOffset()
  116. * @since 1.4.0
  117. */
  118. public function getNextAddress();
  119. /**
  120. * Get the address right before this IP address (if available).
  121. *
  122. * @return \IPLib\Address\AddressInterface|null
  123. *
  124. * @see \IPLib\Address\AddressInterface::getAddressAtOffset()
  125. * @since 1.4.0
  126. */
  127. public function getPreviousAddress();
  128. /**
  129. * Get the Reverse DNS Lookup Address of this IP address.
  130. *
  131. * @return string
  132. *
  133. * @since 1.12.0
  134. *
  135. * @example for IPv4 it returns something like x.x.x.x.in-addr.arpa
  136. * @example for IPv6 it returns something like x.x.x.x..x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.ip6.arpa
  137. */
  138. public function getReverseDNSLookupName();
  139. }