Completed
Push — master ( 40e591...8b2a4b )
by Alex
03:04
created

PhpIPAM::subnetFreeAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Axsor\PhpIPAM;
4
5
use Axsor\PhpIPAM\Http\Controllers\SubnetController;
6
use GuzzleHttp\Client;
7
use Axsor\PhpIPAM\Http\Requests\AddressRequest;
8
use Axsor\PhpIPAM\Http\Controllers\AddressController;
9
use Axsor\PhpIPAM\Http\Controllers\SectionController;
10
11
class PhpIPAM
12
{
13
    private $config;
14
15
    private $client;
16
17
    public function __construct()
18
    {
19
        $this->config = config('phpipam');
20
        $this->client = new Client;
21
    }
22
23
    /**
24
     * Set custom config to connect to PhpIPAM.
25
     *
26
     * @param array $config
27
     * @return $this
28
     */
29
    public function use(array $config)
30
    {
31
        $this->config = $config;
32
33
        return $this;
34
    }
35
36
    /**
37
     * Unset custom config to connect to PhpIPAM.
38
     * Config will be read from your environment.
39
     *
40
     * @return $this
41
     */
42
    public function useDefaultConfig()
43
    {
44
        $this->config = config('phpipam');
45
46
        return $this;
47
    }
48
49
    public function setClient(Client $client)
50
    {
51
        $this->client = $client;
52
    }
53
54
    public function getConfig()
55
    {
56
        return $this->config;
57
    }
58
59
    public function getClient()
60
    {
61
        return $this->client;
62
    }
63
64
    // WRAPPED DATA
65
    // ADDRESSES CONTROLLER
66
    public function address($address)
67
    {
68
        return (new AddressController)->show($address);
69
    }
70
71
    public function ping($address)
72
    {
73
        return (new AddressController)->ping($address);
74
    }
75
76
    public function addressByIp(string $ip)
77
    {
78
        return (new AddressController)->byIp($ip);
79
    }
80
81
    public function addressByHostname(string $hostname)
82
    {
83
        return (new AddressController)->byHostname($hostname);
84
    }
85
86
    public function addressCustomFields()
87
    {
88
        return (new AddressController)->customFields();
89
    }
90
91
    public function tags()
92
    {
93
        return (new AddressController)->tags();
94
    }
95
96
    public function tag($tag)
97
    {
98
        return (new AddressController)->tag($tag);
99
    }
100
101
    public function tagAddresses($tag)
102
    {
103
        return (new AddressController)->tagAddresses($tag);
104
    }
105
106
    public function addressCreate(array $address)
107
    {
108
        return (new AddressController)->create($address);
109
    }
110
111
    public function addressUpdate($address, array $newData)
112
    {
113
        return (new AddressController)->update($address, $newData);
114
    }
115
116
    public function addressDrop($address)
117
    {
118
        return (new AddressController)->drop($address);
119
    }
120
121
    // SECTION CONTROLLER
122
    public function sections()
123
    {
124
        return (new SectionController)->index();
125
    }
126
127
    public function section($section)
128
    {
129
        return (new SectionController)->show($section);
130
    }
131
132
    public function sectionSubnets($section)
133
    {
134
        return (new SectionController)->subnets($section);
135
    }
136
137
    public function sectionByName(string $section)
138
    {
139
        return (new SectionController)->byName($section);
140
    }
141
142
    // TODO upgrade PhpIPAM from 1.3 to 1.5
143
    //public function sectionCustomFields()
144
    //{
145
    //    return (new SectionController)->customFields();
146
    //}
147
148
    public function sectionCreate(array $section)
149
    {
150
        return (new SectionController)->create($section);
151
    }
152
153
    public function sectionUpdate($section, array $newData)
154
    {
155
        return (new SectionController)->update($section, $newData);
156
    }
157
158
    public function sectionDrop($section)
159
    {
160
        return (new SectionController)->drop($section);
161
    }
162
163
    // SUBNET CONTROLLER
164
    public function subnet($subnet)
165
    {
166
        return (new SubnetController)->show($subnet);
167
    }
168
169
    public function subnetUsage($subnet)
170
    {
171
        return (new SubnetController)->usage($subnet);
172
    }
173
174
    public function subnetFreeAddress($subnet)
175
    {
176
        return (new SubnetController)->freeAddress($subnet);
177
    }
178
179
    public function subnetSlaves($subnet)
180
    {
181
        return (new SubnetController)->slaves($subnet);
182
    }
183
184
    public function subnetSlavesRecursive($subnet)
185
    {
186
        return (new SubnetController)->slavesRecursive($subnet);
187
    }
188
189
    public function subnetAddresses($subnet)
190
    {
191
        return (new SubnetController)->addresses($subnet);
192
    }
193
194
    public function subnetIp($subnet, string $ip)
195
    {
196
        return (new SubnetController)->ip($subnet, $ip);
197
    }
198
199
    public function subnetFreeSubnet($subnet, int $mask)
200
    {
201
        return (new SubnetController)->freeSubnet($subnet, $mask);
202
    }
203
204
    public function subnetFreeSubnets($subnet, int $mask)
205
    {
206
        return (new SubnetController)->freeSubnets($subnet, $mask);
207
    }
208
209
    public function subnetCustomFields()
210
    {
211
        return (new SubnetController)->customFields();
212
    }
213
214
    public function subnetByCidr(string $cidr)
215
    {
216
        return (new SubnetController)->byCidr($cidr);
217
    }
218
219
    // RAW DATA
220
    // ADDRESS REQUEST
221
    public function addressRaw($address)
222
    {
223
        return (new AddressRequest)->show($address);
224
    }
225
226
    public function pingRaw($address)
227
    {
228
        return (new AddressRequest)->ping($address);
229
    }
230
}
231