Bootstrap
The Bootstrap class in the Bootstrap.php file is a core component of the framework, responsible for initializing and configuring the application. It handles the setup of essential configurations, routing, and middleware processing. Below is an overview of its key functionalities:
Namespace and Imports
?php
namespace System\Core;
use System\Libraries\Logger;
use Exception;
if (!defined('ROOT_PATH')) {
exit('No direct access allowed.');
}
require_once ROOT_PATH . '/system/Helpers/Core_helper.php';
load_helpers(['uri', 'security']);Defines the namespace
System\Core.Imports the
Loggerclass and theExceptionclass.Checks if
ROOT_PATHis defined. If not, it prevents direct access to the file.Loads the
Core_helper.phpfile to use theload_helpersfunction.Loads the
uriandsecurityhelpers.
Class Definition
Defines the
Bootstrapclass with protected properties$routesand$uri.The constructor sets the timezone, configures error reporting based on the debug mode, initializes the URI, creates a
Routerinstance, and loads the routes.
init_uri()
Initializes the URI by sanitizing it and redirecting if necessary.
Splits the URI into parts and handles language prefixes.
run()
Runs the framework.
Checks the HTTP method of the request (GET, POST, etc.).
Calls the
dispatch()method to route the URI to the corresponding controller and action.Catches and handles
AppExceptionand other errors, logs the error, and displays an error message.
loadRoutes()
Loads the routes from the
Api.phpandWeb.phproute files.Uses the global
$routesvariable to store the routes.Checks and loads the corresponding route files if they exist.
dispatch()
Routes the URI to the corresponding controller and action.
Uses
Routerto match the URI and HTTP method with the corresponding route.Checks and handles middleware before calling the controller.
Checks the existence of the controller and action, throws an exception if not found.
Calls the controller and action with the corresponding parameters.
Conclusion
The methods in Bootstrap.php help initialize and route the framework, handle the URI, load the routes, and route the request to the corresponding controller and action. These methods also handle exceptions and log errors to ensure the application runs smoothly.
Last updated
Was this helpful?