If you haven't already read about the Application container and Inversion of Control you should do so now. Interaction with the application container will not be re-described below.

The App service acts as the glue for the entire application, it is a Singleton class and provides the application container as well as a central location for storage. It provides the necessary bootstrapping for the default services and application in general.

Methods of Interest #

// Configuration variables ( Initial values come from `app/config/config.php`)
// If you attempt to get a config key that doesn't exist an \Exception will be thrown
$host = App::config('DB_HOST');

// Set 
App::config('DB_HOST', 'localhost');

// Register your own configuration file
App::registerConfig( App::path() . '/app/config/custom.php' );

// Check if a config key exists
if( App::configKeyExists('my-custom-key') ){
    // Yep
}


// Get the absolute path of the application (does not include trailing space).
$path = App::path();

echo $path; // `/var/www/project`


// Get the fully qualified domain of the of the application
// Does not include trailing slash
$domain = App::domain();

echo $domain; // `https://project.com`

// Get whether the app is running in dev mode
if(App::devMode()){
    //in dev mode
}//if


// Add a matching condition used by the Data and Router services
App::registerCondition('alpha', '^[a-zA-Z]+');

// Get the regex for a matching condition
$condition = App::getCondition('alpha');

// Match a condition
$match = App::matchCondition('alpha', 'Failure200');


// Register an alias
// Aliases are used as shorthands for paths
// Register an alias
App::registerAlias('my.alias', '/app/template/really/nested/template/files/');

// Get an alias
$alias = App::getAlias('my.alias');


// Resolve an alias
// Aliases are used by specifying `@my.alias:the/path/file.html`
$alias = App::resolveAlias('@my.alias:the-template.html');

echo $alias; // `/app/template/really/nested/template/files/the-template.html`