If you need a Model that does not interact with the pfSense XML configuration (e.g., for fetching real-time data, interacting with services, or executing commands), you can create a non-configuration based Model.
To do this, omit the config_path property and instead define the internal_callable property. The internal_callable must point to a method within your class that fetches the data.
Return Value Requirements:
- For Models with
$this->many = true;: The callable must return an array of objects. - For Models with
$this->many = false; (default): The callable must return a single object.
Pagination Support:
To handle large datasets efficiently, your internal_callable can implement pagination by accepting three specific parameters: limit, offset, and reverse. If these are present, the responsibility for returning the correct subset of data shifts to your callable.
namespace RESTAPI\
Models;
use RESTAPI\Core\Model;
class MyCustomModel extends Model {
public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], mixed ...$options) {
# Use internal_callable instead of config_path
$this->internal_callable = 'fetch_data';
$this->many = true;
# Define fields as usual
$this->name = new StringField(required: true);
parent::__construct($id, $parent_id, $data, ...$options);
}
/**
* Fetches data for the Model object.
* @return array The data for the Model object.
*/
public function fetch_data(): array {
return [
['name' => 'EXAMPLE_1', 'enabled' => true],
['name' => 'EXAMPLE_2', 'enabled' => false],
];
}
}