Table of Contents
The Event System
The Basics
One of the main feature of Phile is new event system, which replace the hook system of pico.
In the core Phile triggers a lot of events, and for every event you can register your plugin to get informed. Depending on the event data is passed along and can be manipulated by the plugin.
Subscribing to Events
The easiest way to subscribe to events is using the $events
property in your plugin:
class Plugin extends \Phile\Plugin\AbstractPlugin {
protected $events = ['after_load_content' => 'doStuff'];
protected function doStuff($eventData) {
// do stuff on the "after_load_content"-event
}
}
Choosing the Right Event
A plugin may subsribe to one or multiple events. Plug-ins should consider when they do what. The two major stages in Phile are:
- Bootstrap the environment (load configs, load plugins, populate services).
- Process request into response (evaluate incoming request, find content, render content, serve response).
As a rule of thumb:
If a plugin provides facilities to the core (e.g. implements a ServiceLocator), then it probably wants to register its functionality during the bootstrap stage (e.g. plugins_loaded
event). The bootstrap phase should not create or send output.
The more common case is that a plugin requires facilities from the core (current page, template engine) to create or manipulate output. This should be done in events during the processing phase.
List of Events
In the core we trigger a lot of events, which help to manipulate content or other stuff within a plugin. To use the event system, you only have to register your plugin for a specific event, look at the example plugin for more an example.
The following list shows all events.
plugins_loaded
this event is triggered after the plugins loaded
param | type | description |
---|---|---|
plugins |
array | Plugin classes of all loaded plugins |
config_loaded
this event is triggered after the configuration is fully loaded
param | type | description |
---|---|---|
config |
array | the complete configuration |
after_init_core
this event is triggered after the core is initialized
param | type | description |
---|---|---|
response |
\Phile\Core\Response | the response, set a PSR-7 response to send output early |
request_uri
this event is triggered after the request uri is detected.
param | type | description |
---|---|---|
uri |
string | the requested uri (without install_path) |
response |
Psr\Http\Message\ResponseInterface | set a PSR-7 response to send output early |
after_404
this event is triggered after a requested page is not found
after_resolve_page
this event is triggered after a request is resolved to a page
param | type | description |
---|---|---|
pageId |
string | the requested page-ID |
page |
Phile\Model\Page | the page served |
response |
Psr\Http\Message\ResponseInterface | set a PSR-7 response to send output early |
before_init_template
this event is triggered before the the template engine is init
before_render_template
this event is triggered before the template is rendered
param | type | description |
---|---|---|
templateEngine |
\Phile\Template\TemplateInterface | the template engine |
response |
Psr\Http\Message\ResponseInterface | set a PSR-7 response to send output early |
template_engine_registered
this event is triggered before the template is rendered
param | type | description |
---|---|---|
engine |
\Phile\Template\TemplateInterface | the raw template engine |
data |
array | the variables being sent to the template engine |
after_render_template
this event is triggered after the template is rendered
param | type | description |
---|---|---|
templateEngine |
\Phile\Template\TemplateInterface | the template engine |
output |
string | the parsed and ready output |
after_response_created
This event is triggered after the response is created with the rendered template.
param | type | description |
---|---|---|
response |
Psr\Http\Message\ResponseInterface | Response with output |
before_read_file_meta
this event is triggered before the meta data is read and parsed
param | type | description |
---|---|---|
rawData |
string | the unparsed data |
meta |
\Phile\Model\Meta | the meta model |
after_read_file_meta
this event is triggered after the meta data is read and parsed
param | type | description |
---|---|---|
rawData |
string | the unparsed data |
meta |
\Phile\Model\Meta | the meta model |
before_load_content
this event is triggered before the content is loaded
param | type | description |
---|---|---|
filePath |
string | the path to the file |
page |
\Phile\Model\Page | the page model |
after_load_content
this event is triggered after the content is loaded
param | type | description |
---|---|---|
filePath |
string | the path to the file |
rawData |
string | the raw data |
page |
\Phile\Model\Page | the page model |
before_parse_content
this event is triggered before the content is parsed
param | type | description |
---|---|---|
content |
string | the raw data |
page |
\Phile\Model\Page | the page model |
after_parse_content
this event is triggered after the content is parsed
param | type | description |
---|---|---|
content |
string | the raw data |
page |
\Phile\Model\Page | the page model |