Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 106 lines (97 sloc) 3.601 kB
e7f3c31 @gwoo going lithium
gwoo authored
1 <?php
2 /**
3 * Lithium: the most rad php framework
4 *
14de7bf @gwoo Happy 2012!
gwoo authored
5 * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
e7f3c31 @gwoo going lithium
gwoo authored
6 * @license http://opensource.org/licenses/bsd-license.php The BSD License
7 */
8
9 /**
9f4b435 @davidpersson Updating and adding docblocks to console front-controller.
davidpersson authored
10 * This console front-controller file is the gateway to your application
11 * through the command line. It is responsible for intercepting requests, and
12 * handing them off to the `Dispatcher` for processing.
13 *
14 * Determine if we're in an application context by moving up the directory tree
15 * looking for a `config` directory with a `bootstrap.php` file in it. If no
16 * application context is found, just boot up the core framework.
e7f3c31 @gwoo going lithium
gwoo authored
17 */
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.…
nateabele authored
18 $params = getopt("", array("app::"));
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detectin…
nateabele authored
19 $working = $params ? array_pop($params) : getcwd();
3e9ed1c @nateabele Fixing issues in `lithium` console file that prevented tests from bei…
nateabele authored
20 $app = null;
e05e21e @davidpersson Refactoring determination of application context.
davidpersson authored
21
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.…
nateabele authored
22 /**
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detectin…
nateabele authored
23 * If we're not running inside an application (i.e. a self-bootstrapping library), bootstrap the
24 * core automatically with the default settings.
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.…
nateabele authored
25 */
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detectin…
nateabele authored
26 $bootstrap = function() use ($working) {
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.…
nateabele authored
27 define('LITHIUM_LIBRARY_PATH', dirname(dirname(__DIR__)));
28 define('LITHIUM_APP_PATH', $working);
29
30 if (!include LITHIUM_LIBRARY_PATH . '/lithium/core/Libraries.php') {
31 $message = "Lithium core could not be found. Check the value of LITHIUM_LIBRARY_PATH in ";
32 $message .= __FILE__ . ". It should point to the directory containing your ";
33 $message .= "/libraries directory.";
34 throw new ErrorException($message);
35 }
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detectin…
nateabele authored
36
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.…
nateabele authored
37 lithium\core\Libraries::add('lithium');
38 lithium\core\Libraries::add(basename($working), array(
99f687c @nateabele Fixing console front controller issue where bootstrap files would not…
nateabele authored
39 'default' => true,
338fad7 @nateabele Use system temp directory as default application resources directory …
nateabele authored
40 'path' => $working,
41 'resources' => sys_get_temp_dir()
3e9ed1c @nateabele Fixing issues in `lithium` console file that prevented tests from bei…
nateabele authored
42 ));
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detectin…
nateabele authored
43 };
9f4b435 @davidpersson Updating and adding docblocks to console front-controller.
davidpersson authored
44
45 /**
46 * The following will dispatch the request and exit with the status code as
47 * provided by the `Response` object returned from `run()`.
48 *
49 * The following will instantiate a new `Request` object and pass it off to the
50 * `Dispatcher` class. By default, the `Request` will automatically aggregate
51 * all the server / environment settings, and request content (i.e. options and
52 * arguments passed to the command) information.
53 *
54 * The `Request` is then used by the `Dispatcher` (in conjunction with the
55 * `Router`) to determine the correct command to dispatch to. The response
56 * information is then encapsulated in a `Response` object, which is returned
57 * from the command to the `Dispatcher`.
58 *
59 * The `Response` object will contain information about the status code which
60 * is used as the exit code when ending the execution of this script and
61 * returned to the callee.
62 *
63 * @see lithium\console\Request
64 * @see lithium\console\Response
65 * @see lithium\console\Dispatcher
66 * @see lithium\console\Router
67 */
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detectin…
nateabele authored
68 $run = function() {
69 return lithium\console\Dispatcher::run(new lithium\console\Request())->status;
70 };
71
72 /**
73 * Look to see if there's a bootstrap file. If there is, this is either a Lithium application or
74 * plugin.
75 */
76 if (file_exists("{$working}/config/bootstrap.php")) {
77 $app = $working;
78 } elseif (file_exists("{$working}/app/config/bootstrap.php")) {
79 $app = "{$working}/app";
80 }
81
82 /**
83 * Attempt to bootstrap the application and execute the request. On failure, use the default
84 * bootstrap.
85 */
86 if ($app) {
87 foreach (array("bootstrap.php", "bootstrap/libraries.php") as $file) {
88 if (!file_exists($path = "{$app}/config/{$file}")) {
89 continue;
90 }
91 if (preg_match("/^define\([\"']LITHIUM_LIBRARY_PATH[\"']/m", file_get_contents($path))) {
92 include "{$app}/config/bootstrap.php";
93 exit($run());
94 }
95 }
96 }
97
98 /**
99 * We're not running inside a Lithium application. Use the default bootstrap and execute the
100 * request.
101 */
102 $bootstrap();
103 $app ? include "{$app}/config/bootstrap.php" : null;
104 exit($run());
e7f3c31 @gwoo going lithium
gwoo authored
105
106 ?>
Something went wrong with that request. Please try again.