Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 112 lines (102 sloc) 3.77 kb
e7f3c31 @gwoo going lithium
gwoo authored
1 <?php
2 /**
3 * Lithium: the most rad php framework
4 *
f99a12f @mehlah Happy 2013!
mehlah authored
5 * @copyright Copyright 2013, 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.php...
nateabele authored
18 $params = getopt("", array("app::"));
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detecting w...
nateabele authored
19 $working = $params ? array_pop($params) : getcwd();
3e9ed1c @nateabele Fixing issues in `lithium` console file that prevented tests from being ...
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.php...
nateabele authored
22 /**
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detecting w...
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.php...
nateabele authored
25 */
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detecting w...
nateabele authored
26 $bootstrap = function() use ($working) {
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.php...
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 detecting w...
nateabele authored
36
dff4513 @blainesch Create the correct file structure in the systems tmp directory
blainesch authored
37 $resources = sys_get_temp_dir();
38 $templates = $resources . '/tmp/cache/templates/';
39 if (!is_dir($templates)) {
40 mkdir($resources . '/tmp/cache/templates/', 0777, true);
41 }
42
9a6448b @nateabele Fixing detection issues between applications and plugins in `lithium.php...
nateabele authored
43 lithium\core\Libraries::add('lithium');
44 lithium\core\Libraries::add(basename($working), array(
99f687c @nateabele Fixing console front controller issue where bootstrap files would not be...
nateabele authored
45 'default' => true,
338fad7 @nateabele Use system temp directory as default application resources directory whe...
nateabele authored
46 'path' => $working,
dff4513 @blainesch Create the correct file structure in the systems tmp directory
blainesch authored
47 'resources' => $resources
3e9ed1c @nateabele Fixing issues in `lithium` console file that prevented tests from being ...
nateabele authored
48 ));
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detecting w...
nateabele authored
49 };
9f4b435 @davidpersson Updating and adding docblocks to console front-controller.
davidpersson authored
50
51 /**
52 * The following will dispatch the request and exit with the status code as
53 * provided by the `Response` object returned from `run()`.
54 *
55 * The following will instantiate a new `Request` object and pass it off to the
56 * `Dispatcher` class. By default, the `Request` will automatically aggregate
57 * all the server / environment settings, and request content (i.e. options and
58 * arguments passed to the command) information.
59 *
60 * The `Request` is then used by the `Dispatcher` (in conjunction with the
61 * `Router`) to determine the correct command to dispatch to. The response
62 * information is then encapsulated in a `Response` object, which is returned
63 * from the command to the `Dispatcher`.
64 *
65 * The `Response` object will contain information about the status code which
66 * is used as the exit code when ending the execution of this script and
67 * returned to the callee.
68 *
69 * @see lithium\console\Request
70 * @see lithium\console\Response
71 * @see lithium\console\Dispatcher
72 * @see lithium\console\Router
73 */
066d41b @nateabele Rewriting console bootstrap file to do a slightly better job detecting w...
nateabele authored
74 $run = function() {
75 return lithium\console\Dispatcher::run(new lithium\console\Request())->status;
76 };
77
78 /**
79 * Look to see if there's a bootstrap file. If there is, this is either a Lithium application or
80 * plugin.
81 */
82 if (file_exists("{$working}/config/bootstrap.php")) {
83 $app = $working;
84 } elseif (file_exists("{$working}/app/config/bootstrap.php")) {
85 $app = "{$working}/app";
86 }
87
88 /**
89 * Attempt to bootstrap the application and execute the request. On failure, use the default
90 * bootstrap.
91 */
92 if ($app) {
93 foreach (array("bootstrap.php", "bootstrap/libraries.php") as $file) {
94 if (!file_exists($path = "{$app}/config/{$file}")) {
95 continue;
96 }
97 if (preg_match("/^define\([\"']LITHIUM_LIBRARY_PATH[\"']/m", file_get_contents($path))) {
98 include "{$app}/config/bootstrap.php";
99 exit($run());
100 }
101 }
102 }
103
104 /**
105 * We're not running inside a Lithium application. Use the default bootstrap and execute the
106 * request.
107 */
108 $bootstrap();
109 $app ? include "{$app}/config/bootstrap.php" : null;
110 exit($run());
e7f3c31 @gwoo going lithium
gwoo authored
111
112 ?>
Something went wrong with that request. Please try again.