Commit: 10e079fdea02acd17641988b87ea137760002135

Author: Joël Perras | Date: 2010-05-11 11:52:57 -0400
Updating to work with lithium 0.9.5.
diff --git a/.gitignore b/.gitignore index 496ee2c..4677418 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -.DS_Store \ No newline at end of file +.DS_Store resources/* \ No newline at end of file diff --git a/config/bootstrap.php b/config/bootstrap.php index c2294b3..52b7ab1 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -38,15 +38,29 @@ if (!include LITHIUM_LIBRARY_PATH . '/lithium/core/Libraries.php') { } /** - * Add the Lithium core library. This sets default paths and initializes the autoloader. You - * generally should not need to override any settings. + * This file contains the loading instructions for all class libraries used in the application, + * including the Lithium core, and the application itself. These instructions include library names, + * paths to files, and any applicable class-loading rules. Also includes any statically-loaded + * classes to improve bootstrap performance. */ -Libraries::add('lithium'); +require __DIR__ . '/bootstrap/libraries.php'; /** - * Add the application. You can pass a `'path'` key here if this bootstrap file is outside of - * your main application, but generally you should not need to change any settings. + * Include this file if your application uses a database connection. */ -Libraries::add('app'); +require __DIR__ . '/connections.php'; + +/** + * This file defines bindings between classes which are triggered during the request cycle, and + * allow the framework to automatically configure its environmental settings. You can add your own + * behavior and modify the dispatch cycle to suit your needs. + */ +require __DIR__ . '/bootstrap/action.php'; + +/** + * This file contains configurations for handling different content types within the framework, + * including converting data to and from different formats, and handling static media assets. + */ +require __DIR__ . '/bootstrap/media.php'; ?> \ No newline at end of file diff --git a/config/bootstrap/action.php b/config/bootstrap/action.php new file mode 100644 index 0000000..27883aa --- /dev/null +++ b/config/bootstrap/action.php @@ -0,0 +1,55 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +/** + * This file contains a series of method filters that allow you to intercept different parts of + * Lithium's dispatch cycle. The filters below are used for on-demand loading of routing + * configuration, and automatically configuring the correct environment in which the application + * runs. + * + * For more information on in the filters system, see `lithium\util\collection\Filters`. + * + * @see lithium\util\collection\Filters + */ + +use \lithium\core\Libraries; +use \lithium\net\http\Router; +use \lithium\core\Environment; +use \lithium\action\Dispatcher; + +/** + * This filter intercepts the `run()` of the `Dispatcher`, and first passes the `'request'` + * parameter (an instance of the `Request` object) to the `Environment` class to detect which + * environment the application is running in. Then, loads all application routes in all plugins, + * loading the default application routes last. + * + * Change this code if plugin routes must be loaded in a specific order (i.e. not the same order as + * the plugins are added in your bootstrap configuration), or if application routes must be loaded + * first (in which case the default catch-all routes should be removed). + * + * If `Dispatcher::run()` is called multiple times in the course of a single request, change the + * `include`s to `include_once`. + * + * @see lithium\action\Request + * @see lithium\core\Environment + * @see lithium\net\http\Router + */ +Dispatcher::applyFilter('run', function($self, $params, $chain) { + Environment::set($params['request']); + + foreach (array_reverse(Libraries::get()) as $name => $config) { + if ($name === 'lithium') { + continue; + } + $file = "{$config['path']}/config/routes.php"; + file_exists($file) ? include $file : null; + } + return $chain->next($self, $params, $chain); +}); + +?> diff --git a/config/bootstrap/libraries.php b/config/bootstrap/libraries.php new file mode 100644 index 0000000..0022efb --- /dev/null +++ b/config/bootstrap/libraries.php @@ -0,0 +1,51 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +use lithium\core\Libraries; + +/** + * Optimize default request cycle by loading common classes. If you're implementing custom + * request/response or dispatch classes, you can safely remove these. Actually, you can safely + * remove them anyway, they're just there to give slightly you better out-of-the-box performance. + */ +require LITHIUM_LIBRARY_PATH . '/lithium/core/Object.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/core/StaticObject.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/util/Collection.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/util/collection/Filters.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/util/Inflector.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/util/String.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/core/Adaptable.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/core/Environment.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/net/http/Message.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/net/http/Media.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/net/http/Request.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/net/http/Response.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/net/http/Route.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/net/http/Router.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/action/Controller.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/action/Dispatcher.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/action/Request.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/action/Response.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/template/View.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/template/view/Renderer.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/template/view/Compiler.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/template/view/adapter/File.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/storage/Cache.php'; +require LITHIUM_LIBRARY_PATH . '/lithium/storage/cache/adapter/Apc.php'; + +/** + * Add the Lithium core library. This sets default paths and initializes the autoloader. You + * generally should not need to override any settings. + */ +Libraries::add('lithium'); + +/** + * Add the application. You can pass a `'path'` key here if this bootstrap file is outside of + * your main application, but generally you should not need to change any settings. + */ +Libraries::add('app', array('default' => true)); \ No newline at end of file diff --git a/config/bootstrap/media.php b/config/bootstrap/media.php new file mode 100644 index 0000000..75a304a --- /dev/null +++ b/config/bootstrap/media.php @@ -0,0 +1,59 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +/** + * The `Collection` class, which serves as the base class for some of Lithium's data objects + * (`RecordSet` and `Document`) provides a way to manage data collections in a very flexible and + * intuitive way, using closures and SPL interfaces. The `to()` method allows a `Collection` (or + * subclass) to be converted to another format, such as an array. The `Collection` class also allows + * other classes to be connected as handlers to convert `Collection` objects to other formats. + * + * The following connects the `Media` class as a format handler, which allows `Collection`s to be + * exported to any format with a handler provided by `Media`, i.e. JSON. This enables things like + * the following: + * {{{ + * $posts = Post::find('all'); + * return $posts->to('json'); + * }}} + */ +use \lithium\util\Collection; + +Collection::formats('\lithium\net\http\Media'); + +/** + * This filter is a convenience method which allows you to automatically route requests for static + * assets stored within active plugins. For example, given a JavaScript file `bar.js` inside the + * `li3_foo` plugin installed in an application, requests to `http://app/path/li3_foo/js/bar.js` + * will be routed to `/path/to/app/libraries/plugins/li3_foo/webroot/js/bar.js` on the filesystem. + * In production, it is recommended that you disable this filter in favor of symlinking each + * plugin's `webroot` directory into your main application's `webroot` directory, or adding routing + * rules in your web server's configuration. + */ +use \lithium\action\Dispatcher; +use \lithium\core\Libraries; +use \lithium\net\http\Media; + +Dispatcher::applyFilter('_callable', function($self, $params, $chain) { + list($plugin, $asset) = explode('/', $params['request']->url, 2) + array("", ""); + if ($asset && $library = Libraries::get($plugin)) { + $asset = "{$library['path']}/webroot/{$asset}"; + + if (file_exists($asset)) { + return function () use ($asset) { + $info = pathinfo($asset); + $type = Media::type($info['extension']); + header("Content-type: {$type['content']}"); + return file_get_contents($asset); + }; + } + } + return $chain->next($self, $params, $chain); +}); + + +?> diff --git a/config/connections.php b/config/connections.php index 5de312c..2ec8c54 100644 --- a/config/connections.php +++ b/config/connections.php @@ -8,7 +8,8 @@ use \lithium\data\Connections; -Connections::add('default', 'MongoDb', array( +Connections::add('default', array( + 'type' => 'MongoDb', 'host' => 'localhost', 'port' => '27017', 'database' => 'myDb' diff --git a/config/routes.php b/config/routes.php index 675c332..883851c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -6,7 +6,7 @@ * @license http://opensource.org/licenses/bsd-license.php The BSD License */ -use \lithium\http\Router; +use \lithium\net\http\Router; /** * Uncomment the line below to enable routing for admin actions. diff --git a/config/switchboard.php b/config/switchboard.php deleted file mode 100644 index 87586cb..0000000 --- a/config/switchboard.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php -/** - * Lithium Mongo: Interactive MongoDB browser built on the Lithium framework. - * - * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) - * @license http://opensource.org/licenses/bsd-license.php The BSD License - */ - -/** - * Welcome to the switchboard. This file contains a series of method filters that allow you to - * intercept different parts of Lithium's request cycle as they happen. You can apply filters to - * any object method that has a `@filter` flag in its API documentation. - * - * For more information on in the filters system, see `lithium\util\collection\Filters`. - * - * @see lithium\util\collection\Filters - */ - -use \lithium\http\Router; -use \lithium\core\Environment; -use \lithium\action\Dispatcher; -use \lithium\g11n\Message; -use \lithium\util\String; - -/** - * Loads application routes before the request is dispatched. Change this to `include_once` if - * more than one request cycle is executed per HTTP request. - * - * @see lithium\http\Router - */ -Dispatcher::applyFilter('run', function($self, $params, $chain) { - include __DIR__ . '/routes.php'; - return $chain->next($self, $params, $chain); -}); - -/** - * Intercepts the `Dispatcher` as it finds a controller object, and passes the `'request'` parameter - * to the `Environment` class to detect which environment the application is running in. - * - * @see lithium\action\Request - * @see lithium\core\Environment - */ -Dispatcher::applyFilter('_callable', function($self, $params, $chain) { - Environment::set($params['request']); - return $chain->next($self, $params, $chain); -}); - -/** - * Implements logic for handling cases where `Message::translate()` returns without a result. - * The message specified for the `'default'` option will be used as a fall back. By - * default the value for the options is the message passed to the method. - */ -Message::applyFilter('translate', function($self, $params, $chain) { - $params['options'] += array('default' => $params['id']); - return $chain->next($self, $params, $chain) ?: $params['options']['default']; -}); - -/** - * Placeholders in translated messages. Adds support for `String::insert()`-style placeholders - * to translated messages. Placeholders may be used within the message and replacements provided - * directly within the `options` argument. - * - * Usage: - * {{{ - * Message::translate('Your {:color} paintings are looking just great.', array( - * 'color' => 'silver', - * 'locale' => 'fr' - * )); - * }}} - * - * @see lithium\util\String::insert() - */ -Message::applyFilter('translate', function($self, $params, $chain) { - return String::insert($chain->next($self, $params, $chain), $params['options']); -}); - -?> \ No newline at end of file diff --git a/resources/tmp/cache/templates/empty b/resources/tmp/cache/templates/empty new file mode 100755 index 0000000..e69de29 diff --git a/views/collections/view.html.php b/views/collections/view.html.php index 9140d76..019ab2a 100644 --- a/views/collections/view.html.php +++ b/views/collections/view.html.php @@ -1,7 +1,4 @@ <?php - -use \lithium\data\model\Document; - $list = function($data, $topLevel = false) use (&$list, $h) { echo "<ul>"; foreach ($data as $key => $value) { @@ -13,7 +10,7 @@ $list = function($data, $topLevel = false) use (&$list, $h) { case (is_bool($value)): echo $value ? 'true' : 'false'; break; - case (is_scalar($value) || (is_object($value)) && !$value instanceof Document): + case (is_scalar($value) || (is_object($value)) && !$value instanceof \lithium\data\collection\Document): echo $h((string) $value); break; case ($value === null): @@ -29,4 +26,4 @@ $list = function($data, $topLevel = false) use (&$list, $h) { }; $list($data, true); -?> +?> \ No newline at end of file diff --git a/views/layouts/default.html.php b/views/layouts/default.html.php index f31066a..a3da708 100644 --- a/views/layouts/default.html.php +++ b/views/layouts/default.html.php @@ -6,7 +6,7 @@ * @license http://opensource.org/licenses/bsd-license.php The BSD License */ -use \lithium\http\Router; +use \lithium\net\http\Router; $urls = array( 'index' => Router::match(array('controller' => 'collections'), $this->request()), @@ -46,4 +46,4 @@ $urls = array( </div> </div> </body> -</html> +</html> \ No newline at end of file diff --git a/webroot/index.php b/webroot/index.php index e5ba58b..bde13a6 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -19,6 +19,6 @@ require dirname(__DIR__) . '/config/bootstrap.php'; /** * Dispatch a new request with the default settings. */ -echo lithium\action\Dispatcher::run(); +echo lithium\action\Dispatcher::run(new lithium\action\Request()); ?> \ No newline at end of file