@@ -4,16 +4,15 @@ namespace RESTAPI\Models;
4
4
5
5
use RESTAPI \Core \Model ;
6
6
use RESTAPI \Dispatchers \HAProxyApplyDispatcher ;
7
- use RESTAPI \Fields \ForeignModelField ;
8
7
use RESTAPI \Fields \StringField ;
9
8
10
9
/**
11
10
* Defines a Model for HAProxy Frontend Actions.
12
11
*/
13
12
class HAProxyFrontendAction extends Model {
14
13
public StringField $ action ;
15
- public ForeignModelField $ acl ;
16
- public ForeignModelField $ backend ;
14
+ public StringField $ acl ;
15
+ public StringField $ backend ;
17
16
public StringField $ customaction ;
18
17
public StringField $ deny_status ;
19
18
public StringField $ realm ;
@@ -30,7 +29,7 @@ class HAProxyFrontendAction extends Model {
30
29
public function __construct (mixed $ id = null , mixed $ parent_id = null , mixed $ data = [], ...$ options ) {
31
30
# Set model attributes
32
31
$ this ->parent_model_class = 'HAProxyFrontend ' ;
33
- $ this ->config_path = 'a_actionsitems /item ' ;
32
+ $ this ->config_path = 'a_actionitems /item ' ;
34
33
$ this ->packages = ['pfSense-pkg-haproxy ' ];
35
34
$ this ->package_includes = ['haproxy/haproxy.inc ' , 'haproxy/haproxy_utils.inc ' ];
36
35
$ this ->many = true ;
@@ -86,15 +85,11 @@ class HAProxyFrontendAction extends Model {
86
85
],
87
86
help_text: 'The action to take when an ACL match is found. ' ,
88
87
);
89
- $ this ->acl = new ForeignModelField (
90
- model_name: 'HAProxyBackendACL ' ,
91
- model_field: 'name ' ,
88
+ $ this ->acl = new StringField (
92
89
required: true ,
93
90
help_text: 'The name of the frontend ACL this action is associated with. ' ,
94
91
);
95
- $ this ->backend = new ForeignModelField (
96
- model_name: 'HAProxyBackend ' ,
97
- model_field: 'name ' ,
92
+ $ this ->backend = new StringField (
98
93
required: true ,
99
94
conditions: ['action ' => 'use_backend ' ],
100
95
help_text: 'The backend to use when an ACL match is found. ' ,
@@ -233,15 +228,16 @@ class HAProxyFrontendAction extends Model {
233
228
}
234
229
235
230
/**
236
- * Extends the default `from_internal()` method to automatically set the internal names of fields before calling.
231
+ * Extends the default `from_internal_object()` method to automatically set the internal names of fields before calling.
232
+ * @param array $internal_object The internal representation of this model to load from.
237
233
*/
238
- public function from_internal ( ): void {
234
+ public function from_internal_object ( array $ internal_object ): void {
239
235
# Do an initial load of the object to ensure the `action` is obtained first
240
- parent ::from_internal ( );
236
+ parent ::from_internal_object ( $ internal_object );
241
237
242
238
# Set the internal names of all fields before doing another load to include dynamic field names
243
239
$ this ->set_field_internal_names ();
244
- parent ::from_internal ( );
240
+ parent ::from_internal_object ( $ internal_object );
245
241
}
246
242
247
243
/**
@@ -256,9 +252,9 @@ class HAProxyFrontendAction extends Model {
256
252
# Loop through each field and change it's internal name to be prefixed with the current `action` assigned
257
253
foreach ($ fields as $ field ) {
258
254
# Don't change exempt field's internal names
259
- if (!in_array ($ field , $ exempt_fields )) {
260
- $ field = str_replace ('lua_function ' , 'lua-function ' , $ field );
261
- $ this ->$ field ->internal_name = $ this ->action ->value . $ field ;
255
+ if (!in_array ($ field , $ exempt_fields ) and $ this -> action -> value and $ this -> $ field ) {
256
+ $ corrected_field = str_replace ('lua_function ' , 'lua-function ' , $ field );
257
+ $ this ->$ field ->internal_name = $ this ->action ->value . $ corrected_field ;
262
258
}
263
259
}
264
260
}
0 commit comments