RangeInterface.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace IPLib\Range;
  3. use IPLib\Address\AddressInterface;
  4. /**
  5. * Interface of all the range types.
  6. */
  7. interface RangeInterface
  8. {
  9. /**
  10. * Get the short string representation of this address.
  11. *
  12. * @return string
  13. */
  14. public function __toString();
  15. /**
  16. * Get the string representation of this address.
  17. *
  18. * @param bool $long set to true to have a long/full representation, false otherwise
  19. *
  20. * @return string
  21. *
  22. * @example If $long is true, you'll get '0000:0000:0000:0000:0000:0000:0000:0001/128', '::1/128' otherwise.
  23. */
  24. public function toString($long = false);
  25. /**
  26. * Get the type of the IP addresses contained in this range.
  27. *
  28. * @return int One of the \IPLib\Address\Type::T_... constants
  29. */
  30. public function getAddressType();
  31. /**
  32. * Get the type of range of the IP address.
  33. *
  34. * @return int One of the \IPLib\Range\Type::T_... constants
  35. */
  36. public function getRangeType();
  37. /**
  38. * Check if this range contains an IP address.
  39. *
  40. * @param \IPLib\Address\AddressInterface $address
  41. *
  42. * @return bool
  43. */
  44. public function contains(AddressInterface $address);
  45. /**
  46. * Check if this range contains another range.
  47. *
  48. * @param \IPLib\Range\RangeInterface $range
  49. *
  50. * @return bool
  51. */
  52. public function containsRange(RangeInterface $range);
  53. /**
  54. * Get the initial address contained in this range.
  55. *
  56. * @return \IPLib\Address\AddressInterface
  57. */
  58. public function getStartAddress();
  59. /**
  60. * Get the final address contained in this range.
  61. *
  62. * @return \IPLib\Address\AddressInterface
  63. */
  64. public function getEndAddress();
  65. /**
  66. * Get a string representation of the starting address of this range than can be used when comparing addresses and ranges.
  67. *
  68. * @return string
  69. */
  70. public function getComparableStartString();
  71. /**
  72. * Get a string representation of the final address of this range than can be used when comparing addresses and ranges.
  73. *
  74. * @return string
  75. */
  76. public function getComparableEndString();
  77. /**
  78. * Get the subnet mask representing this range (only for IPv4 ranges).
  79. *
  80. * @return \IPLib\Address\IPv4|null return NULL if the range is an IPv6 range, the subnet mask otherwise
  81. */
  82. public function getSubnetMask();
  83. /**
  84. * Get the subnet/CIDR representation of this range.
  85. *
  86. * @return \IPLib\Range\Subnet
  87. */
  88. public function asSubnet();
  89. /**
  90. * Get the pattern/asterisk representation (if applicable) of this range.
  91. *
  92. * @return \IPLib\Range\Pattern|null return NULL if this range can't be represented by a pattern notation
  93. */
  94. public function asPattern();
  95. /**
  96. * Get the Reverse DNS Lookup Addresses of this IP range.
  97. *
  98. * @return string[]
  99. *
  100. * @example for IPv4 it returns something like array('x.x.x.x.in-addr.arpa', 'x.x.x.x.in-addr.arpa') (where the number of 'x.' ranges from 1 to 4)
  101. * @example for IPv6 it returns something like array('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', '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') (where the number of 'x.' ranges from 1 to 32)
  102. */
  103. public function getReverseDNSLookupName();
  104. }