Schema
in package
uses
BaseTraits
Defines a class that is used to represent a specific schema for this API. This class is intended to be extended by a child class to implement custom schema definitions using Endpoints, Models and Fields defined in this package.
Generated schema files are generally saved to /usr/local/www/api/v2/schemas/*. Schemas provide a way to define and represent this API's data structure in a format that can be easily shared and understood by developers such as OpenAPI, GraphQL, etc.
Table of Contents
Constants
- SCHEMA_DIR = '/usr/local/pkg/RESTAPI/.resources/schemas/'
- The directory where schema files are stored.
Properties
- $content_type : string
- $file_name : string
- $file_path : string
Methods
- __construct() : mixed
- build_schema_url() : void
- Builds a unique endpoint URL for this schema in the pfSense webroot directory.
- get_class_fqn() : string
- Obtains the fully qualified name of the called class.
- get_class_shortname() : string
- Obtains the shortname of the called class.
- get_classes_in_namespace() : array<string|int, mixed>
- Obtains all classes associated with this class's current namespace.
- get_schema_str() : string
- Obtains the schema as a string. This method must be implemented by the child class and is used to generate the schema file for this class.
- log_error() : void
- Logs an error to the syslog.
- read_schema_from_file() : string
- Reads the schema from file.
- save_schema() : void
- Saves the schema to file.
Constants
SCHEMA_DIR
The directory where schema files are stored.
public
mixed
SCHEMA_DIR
= '/usr/local/pkg/RESTAPI/.resources/schemas/'
Properties
$content_type
public
string
$content_type
= 'text/plain'
The content type for this schema. This is used to determine how the schema is formatted and displayed when accessed via the URL.
$file_name
public
string
$file_name
= 'unnamed_schema.txt'
The file name for this schema.
$file_path
public
string
$file_path
The full file path to the schema file.
Methods
__construct()
public
__construct() : mixed
build_schema_url()
Builds a unique endpoint URL for this schema in the pfSense webroot directory.
public
build_schema_url() : void
get_class_fqn()
Obtains the fully qualified name of the called class.
public
get_class_fqn() : string
Return values
string —The FQN for this object's class.
get_class_shortname()
Obtains the shortname of the called class.
public
get_class_shortname() : string
Return values
string —The shortname for this object's class.
get_classes_in_namespace()
Obtains all classes associated with this class's current namespace.
public
get_classes_in_namespace([bool $shortnames = false ]) : array<string|int, mixed>
Parameters
- $shortnames : bool = false
Return values
array<string|int, mixed> —An array of classes currently in this object's namespace
get_schema_str()
Obtains the schema as a string. This method must be implemented by the child class and is used to generate the schema file for this class.
public
abstract get_schema_str() : string
Return values
string —The schema as a string.
log_error()
Logs an error to the syslog.
public
static log_error(string $message) : void
Parameters
- $message : string
-
The error message to write to the syslog
read_schema_from_file()
Reads the schema from file.
public
read_schema_from_file() : string
Return values
string —The schema as a string.
save_schema()
Saves the schema to file.
public
save_schema() : void