AddressInterface.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. * @example 32 for IPv4
  21. * @example 128 for IPv6
  22. */
  23. public static function getNumberOfBits();
  24. /**
  25. * Get the string representation of this address.
  26. *
  27. * @param bool $long set to true to have a long/full representation, false otherwise
  28. *
  29. * @return string
  30. *
  31. * @example If $long is true, you'll get '0000:0000:0000:0000:0000:0000:0000:0001', '::1' otherwise.
  32. */
  33. public function toString($long = false);
  34. /**
  35. * Get the byte list of the IP address.
  36. *
  37. * @return int[]
  38. *
  39. * @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)
  40. */
  41. public function getBytes();
  42. /**
  43. * Get the full bit list the IP address.
  44. *
  45. * @return string
  46. *
  47. * @example For localhost: For IPv4 you'll get '01111111000000000000000000000001' (32 digits), for IPv6 '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001' (128 digits)
  48. */
  49. public function getBits();
  50. /**
  51. * Get the type of the IP address.
  52. *
  53. * @return int One of the \IPLib\Address\Type::T_... constants
  54. */
  55. public function getAddressType();
  56. /**
  57. * Get the default RFC reserved range type.
  58. *
  59. * @return int One of the \IPLib\Range\Type::T_... constants
  60. */
  61. public static function getDefaultReservedRangeType();
  62. /**
  63. * Get the RFC reserved ranges (except the ones of type getDefaultReservedRangeType).
  64. *
  65. * @return \IPLib\Address\AssignedRange[] ranges are sorted
  66. */
  67. public static function getReservedRanges();
  68. /**
  69. * Get the type of range of the IP address.
  70. *
  71. * @return int One of the \IPLib\Range\Type::T_... constants
  72. */
  73. public function getRangeType();
  74. /**
  75. * Get a string representation of this address than can be used when comparing addresses and ranges.
  76. *
  77. * @return string
  78. */
  79. public function getComparableString();
  80. /**
  81. * Check if this address is contained in an range.
  82. *
  83. * @param \IPLib\Range\RangeInterface $range
  84. *
  85. * @return bool
  86. */
  87. public function matches(RangeInterface $range);
  88. /**
  89. * Get the address right after this IP address (if available).
  90. *
  91. * @return \IPLib\Address\AddressInterface|null
  92. */
  93. public function getNextAddress();
  94. /**
  95. * Get the address right before this IP address (if available).
  96. *
  97. * @return \IPLib\Address\AddressInterface|null
  98. */
  99. public function getPreviousAddress();
  100. /**
  101. * Get the Reverse DNS Lookup Address of this IP address.
  102. *
  103. * @return string
  104. *
  105. * @example for IPv4 it returns something like x.x.x.x.in-addr.arpa
  106. * @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
  107. */
  108. public function getReverseDNSLookupName();
  109. }