1 | <?php |
||
2 | |||
3 | namespace CmdrSharp\NetBox\Ipam; |
||
4 | |||
5 | use CmdrSharp\NetBox\Dcim\Site; |
||
6 | use CmdrSharp\NetBox\NetBox; |
||
7 | use CmdrSharp\NetBox\Tenancy\Tenant; |
||
8 | use CmdrSharp\NetBox\Traits\HandlesNetBoxResults; |
||
9 | use Psr\Http\Message\ResponseInterface; |
||
10 | |||
11 | class Prefix extends NetBox |
||
12 | { |
||
13 | use HandlesNetBoxResults; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
14 | |||
15 | /** @var string */ |
||
16 | const API_PATH = parent::API_PATH . 'ipam/prefixes/'; |
||
17 | |||
18 | /** @var array|string[] */ |
||
19 | protected array $fillable = [ |
||
20 | 'prefix', |
||
21 | 'role', |
||
22 | 'site', |
||
23 | 'tenant', |
||
24 | 'vlan', |
||
25 | 'is_pool', |
||
26 | 'description', |
||
27 | 'vrf', |
||
28 | 'status' |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * @param string $prefix |
||
33 | * @return ResponseInterface |
||
34 | */ |
||
35 | public static function wherePrefix(string $prefix): ResponseInterface |
||
36 | { |
||
37 | return parent::where("?prefix={$prefix}"); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param string $ip |
||
42 | * @return ResponseInterface |
||
43 | */ |
||
44 | public static function whereContains(string $ip): ResponseInterface |
||
45 | { |
||
46 | return parent::where("?contains={$ip}"); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $prefix |
||
51 | * @return ResponseInterface |
||
52 | */ |
||
53 | public static function whereWithin(string $prefix): ResponseInterface |
||
54 | { |
||
55 | return parent::where("?within={$prefix}"); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param string $prefix |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function setPrefix(string $prefix): Prefix |
||
63 | { |
||
64 | $this->setAttribute('prefix', $prefix); |
||
65 | |||
66 | return $this; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param int $role |
||
71 | * @return $this |
||
72 | */ |
||
73 | public function setRole(int $role): Prefix |
||
74 | { |
||
75 | $this->setAttribute('role', $role); |
||
76 | |||
77 | return $this; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param string $role |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function setRoleByName(string $role): Prefix |
||
85 | { |
||
86 | $roleQuery = Role::whereName($role); |
||
87 | $role = $this->getOnlyResult($roleQuery); |
||
88 | |||
89 | $this->setAttribute('role', $role->id); |
||
90 | |||
91 | return $this; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param int $site |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setSite(int $site): Prefix |
||
99 | { |
||
100 | $this->setAttribute('site', $site); |
||
101 | |||
102 | return $this; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param string $site |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function setSiteByName(string $site): Prefix |
||
110 | { |
||
111 | $siteQuery = Site::whereName($site); |
||
112 | $site = $this->getOnlyResult($siteQuery); |
||
113 | |||
114 | $this->setAttribute('site', $site->id); |
||
115 | |||
116 | return $this; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param int $tenant |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function setTenant(int $tenant): Prefix |
||
124 | { |
||
125 | $this->setAttribute('tenant', $tenant); |
||
126 | |||
127 | return $this; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param string $tenant |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function setTenantByName(string $tenant): Prefix |
||
135 | { |
||
136 | $tenantQuery = Tenant::whereName($tenant); |
||
137 | $tenant = $this->getOnlyResult($tenantQuery); |
||
138 | |||
139 | $this->setAttribute('tenant', $tenant->id); |
||
140 | |||
141 | return $this; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param int $vlan |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function setVlan(int $vlan): Prefix |
||
149 | { |
||
150 | $this->setAttribute('vlan', $vlan); |
||
151 | |||
152 | return $this; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param string $vlan |
||
157 | * @return $this |
||
158 | */ |
||
159 | public function setVlanByName(string $vlan): Prefix |
||
160 | { |
||
161 | $vlanQuery = Vlan::whereName($vlan); |
||
162 | $vlan = $this->getOnlyResult($vlanQuery); |
||
163 | |||
164 | $this->setAttribute('vlan', $vlan->id); |
||
165 | |||
166 | return $this; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @param bool $isPool |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setPool(bool $isPool): Prefix |
||
174 | { |
||
175 | $this->setAttribute('is_pool', $isPool); |
||
176 | |||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param string $description |
||
182 | * @return $this |
||
183 | */ |
||
184 | public function setDescription(string $description): Prefix |
||
185 | { |
||
186 | $this->setAttribute('description', $description); |
||
187 | |||
188 | return $this; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param int $vrf |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function setVrf(int $vrf): Prefix |
||
196 | { |
||
197 | $this->setAttribute('vrf', $vrf); |
||
198 | |||
199 | return $this; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @param string $status |
||
204 | * @return $this |
||
205 | */ |
||
206 | public function setStatus(string $status): Prefix |
||
207 | { |
||
208 | $this->setAttribute('status', $status); |
||
209 | |||
210 | return $this; |
||
211 | } |
||
212 | } |
||
213 |