Jet\MVC_Controller_Router
Having explained the basic meaning and principle of a microrouter, it's time to take a detailed look at the Jet\MVC_Controller_Router class and its Jet\MVC_Controller_Router_Interface.
Overview of methods
Method | Meaning of |
---|---|
public __construct( MVC_Controller $controller ) |
It is necessary to pass to the constructor an instance of the controller that the microrouter will serve. The binding is therefore mutual. The controller is to hold the microrouter instance and the microrouter holds the controller instance. |
public addAction( string $controller_action_name, string $module_action_name = '' ): MVC_Controller_Router_Action |
It creates the action and then returns its instance. So the action is created, but not set - at least the resolver must be defined. Let's look at the parameters, because there you can already find the way how to verify permissions.
|
public getActions( ): MVC_Controller_Router_Action[] |
Returns a list of all defined microrouter actions. |
public getAction( string $controller_action_name ): MVC_Controller_Router_Action |
Returns the defined action. The action must exist. The method does not check if it is defined. This is the intent, so that when a non-existent action is requested, the application would rather "crash" and not get into an undefined state. The definition of actions and their usage must be consistent. |
public action( string $action_name ): MVC_Controller_Router_Action |
This is an alias of the getAction method for shorter writing. |
public setDefaultAction( string $controller_action_name, string $module_action_name = '' ): MVC_Controller_Router_Action |
The microrouter allows you to define a default action. That is, an action that is valid and applied when none of the defined actions have been recognized as relevant. |
public getDefaultAction( ): MVC_Controller_Router_Action |
Returns an instance of the default action. |
public getController( ): MVC_Controller |
Returns the controller instance to which the microrouter belongs. |
public resolve( ): bool|string |
This method performs an evaluation. The method returns either the bool value false or the name of the action to be performed (i.e. string). Let's talk about the evaluation algorithm:
|
And for completeness, please take a look at the MVC_Controller_Router_Action class.