Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

106 lines (97 sloc) 3.601 kb
* Lithium: the most rad php framework
* @copyright Copyright 2012, Union of RAD (
* @license The BSD License
* This console front-controller file is the gateway to your application
* through the command line. It is responsible for intercepting requests, and
* handing them off to the `Dispatcher` for processing.
* Determine if we're in an application context by moving up the directory tree
* looking for a `config` directory with a `bootstrap.php` file in it. If no
* application context is found, just boot up the core framework.
$params = getopt("", array("app::"));
$working = $params ? array_pop($params) : getcwd();
$app = null;
* If we're not running inside an application (i.e. a self-bootstrapping library), bootstrap the
* core automatically with the default settings.
$bootstrap = function() use ($working) {
define('LITHIUM_LIBRARY_PATH', dirname(dirname(__DIR__)));
define('LITHIUM_APP_PATH', $working);
if (!include LITHIUM_LIBRARY_PATH . '/lithium/core/Libraries.php') {
$message = "Lithium core could not be found. Check the value of LITHIUM_LIBRARY_PATH in ";
$message .= __FILE__ . ". It should point to the directory containing your ";
$message .= "/libraries directory.";
throw new ErrorException($message);
lithium\core\Libraries::add(basename($working), array(
'default' => true,
'path' => $working,
'resources' => sys_get_temp_dir()
* The following will dispatch the request and exit with the status code as
* provided by the `Response` object returned from `run()`.
* The following will instantiate a new `Request` object and pass it off to the
* `Dispatcher` class. By default, the `Request` will automatically aggregate
* all the server / environment settings, and request content (i.e. options and
* arguments passed to the command) information.
* The `Request` is then used by the `Dispatcher` (in conjunction with the
* `Router`) to determine the correct command to dispatch to. The response
* information is then encapsulated in a `Response` object, which is returned
* from the command to the `Dispatcher`.
* The `Response` object will contain information about the status code which
* is used as the exit code when ending the execution of this script and
* returned to the callee.
* @see lithium\console\Request
* @see lithium\console\Response
* @see lithium\console\Dispatcher
* @see lithium\console\Router
$run = function() {
return lithium\console\Dispatcher::run(new lithium\console\Request())->status;
* Look to see if there's a bootstrap file. If there is, this is either a Lithium application or
* plugin.
if (file_exists("{$working}/config/bootstrap.php")) {
$app = $working;
} elseif (file_exists("{$working}/app/config/bootstrap.php")) {
$app = "{$working}/app";
* Attempt to bootstrap the application and execute the request. On failure, use the default
* bootstrap.
if ($app) {
foreach (array("bootstrap.php", "bootstrap/libraries.php") as $file) {
if (!file_exists($path = "{$app}/config/{$file}")) {
if (preg_match("/^define\([\"']LITHIUM_LIBRARY_PATH[\"']/m", file_get_contents($path))) {
include "{$app}/config/bootstrap.php";
* We're not running inside a Lithium application. Use the default bootstrap and execute the
* request.
$app ? include "{$app}/config/bootstrap.php" : null;
Jump to Line
Something went wrong with that request. Please try again.