Attributes
1Presentation
Temma offers optional PHP attributes to control access to controllers and actions.
These attributes can be added together, so you can add several different attributes (and sometimes the same attribute several times, with different parameters) to the same controller or action.
More, you can create your own attributes to manage access to controllers and actions.
Attributes provided by Temma
Temma provides several attributes, which documentation is available in the "Helpers" sections:
2Write your own attributes
You can create your own attributes to manage access to controllers and actions.
2.1Inheritance
Your attributes must derive from the \Temma\Web\Attribute object, which offers several features relatively similar to those of controllers:
-
Access to template variables via the hooked notion.
For example: $this['var'] = 'value'; to define a variable, and $var = $this['var']; to read the value of a variable. -
Access to data sources in the form of direct object properties.
For example: $this->db to access a database named db. -
Methods $this->_httpCode() and $this->_httpError()
to define the HTTP return code, or HTTP error code.
Methods $this->_getHttpCode() and $this->_getHttpError() to retrieve the HTTP code previously defined. - Methods $this->_redirect() and $this->_redirect301() to define redirection commands.
- Methods $this->_view() to define the view, $this->_template() to define the template, and $this->_templatePrefix() to define the template prefix.
In addition, getters are used to access Temma's internal objects:
- $this->_getLoader(): returns the dependency injection component.
- $this->_getSession(): returns the session management object.
- $this->_getConfig(): returns the configuration access object.
- $this->_getRequest(): returns the request management object..
- $this->getResponse(): return the response management object.
2.2Execution flow
To modify the flow of execution, an attribute must raise a specific exception:
- \Temma\Exceptions\FlowHalt: Stops the flow of execution. No other plugins or controllers will be executed, and the framework moves straight on to processing the view or redirection.
- \Temma\Exceptions\FlowRestart: Restarts processing of the current phase (pre-plugins, controller or post-plugins).
- \Temma\Exceptions\FlowReboot: Restarts the entire processing chain (pre-plugins + controller + post-plugins).
- \Temma\ExceptionsFlowQuit: Stops execution of the framework. No further plugins or controllers will be executed. The view will not be executed and redirection requests are ignored.