The main application class is the core of the whole application and is responsible for routing actions to controllers based on request objects extended extended from Hazaar\Application\Request.
Supported request objects are:
- Hazaar\Application\Request\Http – A standard HTTP request. This can be either GET or POST requests. POST requests can optionally have a request body. In this case the Content-Type header will be checked to see how to decode the request body. multipart/form-data and application/json are currently accepted.
- Hazaar\Application\Request\Cli – This is a special request type to allow Hazaar applications to be executed from the command line. This is currently used by the config tool
Example usage:
define('APPLICATION_ENV', 'development');
$config = 'application.ini';
$application = new Hazaar\Application(APPLICATION_ENV, $config);
$application->bootstrap()->run();
Methods | Properties | Constants |
---|---|---|
No constants |
The application is basically the center of the Hazaar MVC universe. Everything hangs off of it and controllers are executed within the context of the application. The main constructor prepares the application to begin processing and is the first piece of code executed within the HazaarMVC environment.
Because of this is it responsible for setting up the class loader, starting code execution profiling timers, loading the application configuration and setting up the request object.
Hazaar also has a ‘run direct’ function that allows Hazaar to execute special requests directly without going through the normal application execution path. These requests are used so hazaar can serve static internal content such as error pages, images and style sheets required by these error pages and redistributed JavaScript code libraries.
Tags
Since | 1.0.0 |
Parameters
$env | string | The application environment name. eg: ‘development’ or ‘production’ |
The destructor cleans up any application redirections. ifthe controller hasn’t used it in this run then it loses it. This prevents stale redirect URLs from accidentally being used.
Tags
Since | 1.0.0 |
Bootstrap is the first step in running an application. It will run some checks to make sure sure the server has any required modules loaded as requested by the application (via the config). It will then execute the application bootstrap.php script within the context of the application. Once that step succeeds the requested (or the default) controller will be loaded and initialised so that it is ready for execution by the application.
Tags
Since | 1.0.0 |
Parameters
$simple_mode | No description |
Returns
\Hazaar\Application | Returns a reference to itself to allow chaining |
This method allows access to the raw URL path part, relative to the current application request.
Tags
Since | 1.0.0 |
Parameters
$path | No description | |
$file | No description | |
$force_realpath | No description |
Tags
Since | 1.0.0 |
Parameters
$suffix | No description |
Returns
string | The resolved application path |
The base path is the root your application which contains the application, library and public directories
Tags
Since | 1.0.0 |
Parameters
$suffix | No description |
Returns
string | The resolved base path |
This static function can be used to get a reference to the current application instance from anywhere.
Tags
Since | 1.0.0 |
Returns
\Hazaar\Application | The application instance |
Returns
string | The current controller name |
This method allows access to the raw URL path part, relative to the current application request.
Tags
Since | 1.0.0 |
Parameters
$path | No description |
It’s quite common to redirect the user to an alternative URL. This may be to forward the request to another website, forward them to an authentication page or even just remove processed request parameters from the URL to neaten the URL up.
Tags
Since | 1.0.0 |
Parameters
$location | No description | |
$args | No description | |
$save_url | No description |
This mechanism is used with the $save_url parameter of Application::redirect() so save the current URL into the session so that once we’re done processing the request somewhere else we can come back to where we were. This is useful for when a user requests a page but isn’t authenticated, we can redirect them to a login page and then that page can call this redirectBack() method to redirect the user back to the page they were originally looking for.
Tags
Since | 1.0.0 |
Once the application has been initialised and a controller loaded, it can be executed via the run() method. This will execute the loaded controller and check that it returns a valid Hazaar\Controller\Response object. ifa valid response is not returned an exception will be raised.
Once a valid response object is returned it will be used to write output back to the web server to be returned to the user.
This method also has protection against error loops. ifan exception is thrown while processing a Hazaar\Controller\Error controller object then a new exception will be thrown outside the application context and will display basic fall-back error output.
Tags
Since | 1.0.0 | |
Exception | Application\Exception\ResponseInvalid | if the controller returns an invalid response object |
Parameters
$controller | \Hazaar\Controller | No description |
This method is will accept Hazaar Protocol commands from STDIN and execute them.
Exit codes:
- 1 – Bad Payload – The execution payload could not be decoded.
- 2 – Unknown Payload Type – The payload execution type is unknown.
- 3 – Service Class Not Found – The service could not start because the service class could not be found.
- 4 – Unable to open control channel – The application was unable to open a control channel back to the execution server.
Tags
Since | 1.0.0 |
The runtime directory is a place where HazaarMVC will keep files that it needs to create during normal operation. For example, socket files for background scheduler communication, cached views, and backend applications.
Tags
Since | 1.0.0 |
Parameters
$suffix | No description | |
$create_dir | No description |
Returns
string | The path to the runtime directory |
Parameters
$value | No description |
Parameters
$event | No description | |
$data | No description |
This is the base method for generating URLs in your application. URLs generated directly from here are relative to the application base path. For URLs that are relative to the current controller see Controller::url()
Parameters are dynamic and depend on what you are trying to generate.
For examples see: Generating URLs
Tags
Since | 1.0.0 |