DOCS

EXC | DEV | Documentation | Version 1.0

Messages

This topic applies to the Back-End framework.

Suggested readings: controllers

EXC uses messages to decouple the logic of an application. The execution of your application is in essence your code responding to messages.

A message is send to indicate an event or to require an action. Messages are broadcasted by event emitters like the appController. The appController is the main controller responsible for the life-cycle of your application and in EXC most messages are generated by the appController.

Handling messages is done mainly by controllers. The main job of a controller is to responde to messages. A message may be an action from your front-end or you may get an event from the framework itself. See "Adding your own controllers" to learn more about creating your own controllers.

When a message is broadcasted to all active controllers is called publishing a message. In addition a controller maybe directed to perform a message.

A controller my handle a message as the first responder or as a callback to an event message.

Registering a handler for an event or action

In a controller a message handler is a function, who's name follows a simple naming convention that we call the "message handler signature".

A function name that starts with "on" , for example onAppStart is considered a handler for the message "AppStart".

<?php
class recordController extends \exc\controller\viewController {
	public function onAppStart(){
		//my code here...
	}
}

We use the prefix "on" to identify functions as message handlers that EXC will automatically register as a callback. These automatic message handlers in your controller class are used when your controller class is loaded on request or explicitly by the user when calling \exc\app::registerController($className, $classInstance).

We can also implement message handlers by registering a callback manually.

<?php
$app = \exc\controller\appController::instance(); //get an instance of the app controller

$app->on( 'appStart', $callback ); //register for the event appStart

Backend Messages

The following is a list of events broadcasted by the appController.

Name Type Description
appInit publish Your application is about to run. Initialize things required for your app to run.

Arguments: None.
appEnd event The backend finished a request and the app instance will be terminated. Arguments: None.
appAbort event The backend is aborting a request and the app instance will be terminated. Arguments: None.
appClientReady event The $client was initialized and is ready for interactions. Arguments: $client.
appClientCommit event The backend is about to send any $client interactions and the app's state to the front-end. Arguments: None.
appSendHeaders event The backend is sending the HTTP headers. Arguments: None.
appSendOutput event The backend is about to send output to the front-end. Usually HTML. Arguments: None.
appSendJSON event The backend is sending a JSON payload. Arguments: None.
appSendJS event The backend is sending a JS payload. Arguments: None.
viewCommit event About to send the default view to the output buffer. Arguments: $view.
sessionInit event A new session store was created. Arguments: None.
Fork me on GitHub