Skip to content
nevali edited this page Sep 13, 2010 · 2 revisions

When a request is processed by Eregansu, the code in platform.php (which is included by index.php) sets the global variable $app to an instance of the initial “application”. This is a subclass of Routable which is obtained by calling App::initialApp().

Without any configuration, App::initialApp() will return an instance of DefaultApp, a fairly simple subclass of App which sets up routes according to $HTTP_ROUTES, $CLI_ROUTES and $MQ_ROUTES, all of which can be defined in your appconfig.php.

To change which class App::initialApp() returns an instance of, you can define a number of constants in your appconfig.php:

APP_CLASS specifies the name of initial app class
APP_NAME adjusts the root path ($APP_ROOT) to your application’s class files (i.e., the name of a subdirectory within your app/ directory).
APP_CLASS_PATH specifies the name of the PHP file containing your initial app class, relative to the current $APP_ROOT

(Note that by default, $APP_ROOT is set to the path of the app/ directory).

In addition to the above, you can override the initial app class for a particular SAPI (for example, so that you can specify a particular initial app class just for command-line use of your application). To do this, prefix each of the constant names above with the name of the SAPI, in all-uppercase, and an underscore. Note that all of the various SAPIs for handling web server requests (e.g., apache2handler, cgi, and so on) all use the prefix HTTP_.

So, for the cli SAPI, you would define CLI_APP_CLASS, CLI_APP_NAME and CLI_APP_CLASS_PATH.

If you wanted to set the default initial app class to MyApp, which is defined in myapp.php within your app/ directory, you would include the following in your appconfig.php:

define('APP_CLASS', 'MyApp');
define('APP_CLASS_PATH', 'myapp.php');

And if you wanted to set the default initial app class just for command-line invocation of your application to MyCommandLine, which is defined in a file named clihandler.php in a module called mycli (i.e., its code is contained within app/mycli/clihandler.php), you would set the following:

define('CLI_APP_CLASS', 'MyCommandLine');
define('CLI_APP_NAME', 'mycli');
define('CLI_APP_CLASS_PATH', 'clihandler.php');

Clone this wiki locally