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 Vlan extends NetBox |
||
12 | { |
||
13 | use HandlesNetBoxResults; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
14 | |||
15 | /** @var string */ |
||
16 | const API_PATH = parent::API_PATH . 'ipam/vlans/'; |
||
17 | |||
18 | /** @var array|string[] */ |
||
19 | protected array $fillable = [ |
||
20 | 'site', |
||
21 | 'group', |
||
22 | 'vid', |
||
23 | 'name', |
||
24 | 'tenant', |
||
25 | 'status', |
||
26 | 'role', |
||
27 | 'description', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * @param int $vid |
||
32 | * @return ResponseInterface |
||
33 | */ |
||
34 | public static function whereVlan(int $vid): ResponseInterface |
||
35 | { |
||
36 | return parent::where("?vid={$vid}"); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param int $site |
||
41 | * @return $this |
||
42 | */ |
||
43 | public function setSite(int $site): Vlan |
||
44 | { |
||
45 | $this->setAttribute('site', $site); |
||
46 | |||
47 | return $this; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param string $site |
||
52 | * @return $this |
||
53 | */ |
||
54 | public function setSiteByName(string $site): Vlan |
||
55 | { |
||
56 | $siteQuery = Site::whereName($site); |
||
57 | $site = $this->getOnlyResult($siteQuery); |
||
58 | |||
59 | $this->setAttribute('site', $site->id); |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param int $group |
||
66 | * @return $this |
||
67 | */ |
||
68 | public function setGroup(int $group): Vlan |
||
69 | { |
||
70 | $this->setAttribute('group', $group); |
||
71 | |||
72 | return $this; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param int $vid |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function setVid(int $vid): Vlan |
||
80 | { |
||
81 | $this->setAttribute('vid', $vid); |
||
82 | |||
83 | return $this; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @param string $name |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function setName(string $name): Vlan |
||
91 | { |
||
92 | $this->setAttribute('name', $name); |
||
93 | |||
94 | return $this; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @param int $tenant |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function setTenant(int $tenant): Vlan |
||
102 | { |
||
103 | $this->setAttribute('tenant', $tenant); |
||
104 | |||
105 | return $this; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param string $tenant |
||
110 | * @return $this |
||
111 | */ |
||
112 | public function setTenantByName(string $tenant): Vlan |
||
113 | { |
||
114 | $tenantQuery = Tenant::whereName($tenant); |
||
115 | $tenant = $this->getOnlyResult($tenantQuery); |
||
116 | |||
117 | $this->setAttribute('tenant', $tenant->id); |
||
118 | |||
119 | return $this; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param string $status |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function setStatus(string $status): Vlan |
||
127 | { |
||
128 | $this->setAttribute('status', $status); |
||
129 | |||
130 | return $this; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @param int $role |
||
135 | * @return $this |
||
136 | */ |
||
137 | public function setRole(int $role): Vlan |
||
138 | { |
||
139 | $this->setAttribute('role', $role); |
||
140 | |||
141 | return $this; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param string $role |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function setRoleByName(string $role): Vlan |
||
149 | { |
||
150 | $roleQuery = Role::whereName($role); |
||
151 | $role = $this->getOnlyResult($roleQuery); |
||
152 | |||
153 | $this->setAttribute('role', $role->id); |
||
154 | |||
155 | return $this; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @param string $description |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function setDescription(string $description): Vlan |
||
163 | { |
||
164 | $this->setAttribute('description', $description); |
||
165 | |||
166 | return $this; |
||
167 | } |
||
168 | } |
||
169 |