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