AbstractController
in package
Abstract Controller Class
This class serves as the base for module management in the framework. It provides a standardized structure for initializing modules, handling routing, managing permissions, and interacting with models. Controllers that extend this class gain access to automated installation, update, and uninstallation functionality, as well as CLI command registration.
Tags
Table of Contents
Methods
- __construct() : mixed
- Constructor
- _api_init() : mixed
- _bootstrap() : mixed
- _cli_init() : mixed
- Hook initialization method for CLI
- _hook_init() : mixed
- _install_check_data() : mixed
- _install_done() : mixed
- _install_execute() : mixed
- Questo serve solo a caricare il bootstrap della classe se non è già stato caricato.
- _install_get_html_modules() : mixed
- _install_update() : mixed
- _jobs_init() : mixed
- _jobs_start() : mixed
- access() : bool
- Check if the current user has access to the module
- api_init() : mixed
- Hook initialization method for API
- bootstrap() : mixed
- Bootstrap method
- cli_init() : mixed
- Hook initialization method for CLI
- get_model() : mixed
- get_module_name() : string
- Get module name from class name
- get_page() : mixed
- get_title() : mixed
- hook_init() : mixed
- Hook initialization method
- init() : mixed
- Initialize the module for page rendering
- install_check_data() : array<string|int, mixed>
- Validate installation data
- install_done() : string
- Installation completion message
- install_execute() : void
- Execute the module installation
- install_get_html_modules() : string
- Get HTML for the installation page
- install_update() : string
- Update the module
- jobs_init() : mixed
- Hook initialization method for background jobs
- jobs_start() : mixed
- Hook method for job execution start
- setup_cli_hooks() : mixed
- Set up CLI hooks
- shell_install_module() : mixed
- Install the module
- shell_uninstall_module() : mixed
- Uninstall the module
- shell_update_module() : mixed
- Update the module
Methods
__construct()
Constructor
public
__construct() : mixed
Initializes the module, registers hooks, and sets permissions for authorized modules. If the current page matches this module's page or if running in CLI mode, the init() method is called.
_api_init()
public
_api_init() : mixed
_bootstrap()
public
_bootstrap() : mixed
_cli_init()
Hook initialization method for CLI
public
_cli_init() : mixed
This method is called during the 'cli-init' hook phase. It can be overridden in child classes to perform actions when the system is initialized and all modules are loaded in CLI context.
_hook_init()
public
_hook_init() : mixed
_install_check_data()
public
_install_check_data(mixed $errors, mixed $data) : mixed
Parameters
- $errors : mixed
- $data : mixed
_install_done()
public
_install_done(mixed $html) : mixed
Parameters
- $html : mixed
_install_execute()
Questo serve solo a caricare il bootstrap della classe se non è già stato caricato.
public
_install_execute([mixed $data = [] ]) : mixed
Parameters
- $data : mixed = []
_install_get_html_modules()
public
_install_get_html_modules(string $html, mixed $errors) : mixed
Parameters
- $html : string
- $errors : mixed
_install_update()
public
_install_update([mixed $html = '' ]) : mixed
Parameters
- $html : mixed = ''
_jobs_init()
public
_jobs_init() : mixed
_jobs_start()
public
_jobs_start() : mixed
access()
Check if the current user has access to the module
public
access() : bool
Verifies permissions based on the module's access level setting.
Return values
bool —True if the user has access, false otherwise
api_init()
Hook initialization method for API
public
api_init() : mixed
This method is called during the 'api-init' hook phase. It can be overridden in child classes to perform actions when the system is initialized and all modules are loaded in API context.
bootstrap()
Bootstrap method
public
bootstrap() : mixed
This method is called during the 'init', 'jobs-init', 'cli-init' and 'api-init' hook phases. Since controllers are loaded at system startup, to avoid loading all other classes required by the module, it's better to avoid initializing them here when possible. It's not necessary to include class files via require because the system uses lazy loading to load classes when they are needed.
Override this method in child classes to initialize module-specific components like models and routers that should be available across different contexts.
Tags
cli_init()
Hook initialization method for CLI
public
cli_init() : mixed
This method is called during the 'cli-init' hook phase. It can be overridden in child classes to perform actions when the system is initialized and all modules are loaded in CLI context.
get_model()
public
get_model() : mixed
get_module_name()
Get module name from class name
public
get_module_name() : string
Extracts the module name from the controller class name by removing 'Controller' and converting to lowercase.
Return values
string —The module name
get_page()
public
get_page() : mixed
get_title()
public
get_title() : mixed
hook_init()
Hook initialization method
public
hook_init() : mixed
This method is called during the 'init' hook phase. It can be overridden in child classes to perform actions when the system is initialized and all modules are loaded.
init()
Initialize the module for page rendering
public
init() : mixed
This method is called only when the current page matches this module's page. It can be used to load JavaScript and CSS files specific to the module. The parent::init() method starts the bootstrap process and initializes the router if present, ensuring the same model instance is available in the router.
Override this method in child classes to add module-specific assets and perform page-specific initialization tasks.
Tags
install_check_data()
Validate installation data
public
install_check_data(array<string|int, mixed> $errors[, array<string|int, mixed> $data = [] ]) : array<string|int, mixed>
Performs validation on the data submitted in the installation form.
Parameters
- $errors : array<string|int, mixed>
-
Current validation errors
- $data : array<string|int, mixed> = []
-
Data from the installation form
Tags
Return values
array<string|int, mixed> —Updated validation errors
install_done()
Installation completion message
public
install_done(string $html) : string
This method is called after installation and allows modifying the HTML of the installation completion page.
Parameters
- $html : string
-
Current HTML of the completion page
Tags
Return values
string —Modified HTML
install_execute()
Execute the module installation
public
install_execute([array<string|int, mixed> $data = [] ]) : void
Performs the actual installation of the module, typically by creating database tables through the model's build_table method.
Parameters
- $data : array<string|int, mixed> = []
-
Data from the installation form
Tags
install_get_html_modules()
Get HTML for the installation page
public
install_get_html_modules(string $html, array<string|int, mixed> $errors) : string
Allows modifying the installation page with custom form elements. This method is called if the system is not installed or there's a new version.
Parameters
- $html : string
-
The current HTML of the installation page
- $errors : array<string|int, mixed>
-
Any validation errors from the installation form
Return values
string —The modified HTML
install_update()
Update the module
public
install_update(string $html) : string
This method is called when updating the module. It typically rebuilds the database tables to incorporate any schema changes.
Parameters
- $html : string
-
Current HTML of the update page
Return values
string —Modified HTML
jobs_init()
Hook initialization method for background jobs
public
jobs_init() : mixed
This method is called during the 'jobs-init' hook phase. It can be overridden in child classes to perform actions when the system is initialized and all modules are loaded in the background jobs context.
jobs_start()
Hook method for job execution start
public
jobs_start() : mixed
This method is called during the 'jobs-start' hook phase. It can be overridden in child classes to perform actions when background jobs are about to start executing.
setup_cli_hooks()
Set up CLI hooks
public
setup_cli_hooks() : mixed
Registers shell commands for installing, updating, and uninstalling the module if the model has the necessary methods. Also automatically registers any method that starts with 'shell_' as a CLI command.
Tags
shell_install_module()
Install the module
public
shell_install_module() : mixed
This shell command installs the module by calling the install_execute method. It can be run via CLI or by an admin user.
Tags
shell_uninstall_module()
Uninstall the module
public
shell_uninstall_module() : mixed
This shell command uninstalls the module by dropping its tables and disabling the module directory. It can be run via CLI or by an admin user.
Tags
shell_update_module()
Update the module
public
shell_update_module() : mixed
This shell command updates the module by calling the install_update method. It can be run via CLI or by an admin user.