diff options
author | Michael Francis <edude03@gmail.com> | 2011-05-28 13:28:16 -0400 |
---|---|---|
committer | Michael Francis <edude03@gmail.com> | 2011-05-28 13:28:16 -0400 |
commit | 2389d66da849798f8d4ec5f10e3b07c11da49185 (patch) | |
tree | e22556d12982395b469a23420c662662e3e064cc /config | |
download | otakuhub-2389d66da849798f8d4ec5f10e3b07c11da49185.tar.xz |
Initial Commit
Diffstat (limited to 'config')
-rw-r--r-- | config/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | config/bootstrap.php | 86 | ||||
-rw-r--r-- | config/bootstrap/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | config/bootstrap/action.php | 55 | ||||
-rw-r--r-- | config/bootstrap/auth.php | 135 | ||||
-rw-r--r-- | config/bootstrap/cache.php | 62 | ||||
-rw-r--r-- | config/bootstrap/connections.php | 72 | ||||
-rw-r--r-- | config/bootstrap/console.php | 19 | ||||
-rw-r--r-- | config/bootstrap/error.php | 37 | ||||
-rw-r--r-- | config/bootstrap/errors.php | 28 | ||||
-rw-r--r-- | config/bootstrap/g11n.php | 149 | ||||
-rw-r--r-- | config/bootstrap/libraries.php | 127 | ||||
-rw-r--r-- | config/bootstrap/media.php | 63 | ||||
-rw-r--r-- | config/bootstrap/session.php | 49 | ||||
-rw-r--r-- | config/routes.php | 149 |
15 files changed, 1031 insertions, 0 deletions
diff --git a/config/.DS_Store b/config/.DS_Store Binary files differnew file mode 100644 index 0000000..bd2fe53 --- /dev/null +++ b/config/.DS_Store diff --git a/config/bootstrap.php b/config/bootstrap.php new file mode 100644 index 0000000..ceadfaf --- /dev/null +++ b/config/bootstrap.php @@ -0,0 +1,86 @@ +<?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 is the primary bootstrap file of your application, and is loaded immediately after the front + * controller (`webroot/index.php`) is invoked. It includes references to other feature-specific + * bootstrap files that you can turn on and off to configure the services needed for your + * application. + * + * Besides global configuration of external application resources, these files also include + * configuration for various classes to interact with one another, usually through _filters_. + * Filters are Lithium's system of creating interactions between classes without tight coupling. See + * the `Filters` class for more information. + * + * If you have other services that must be configured globally for the entire application, create a + * new bootstrap file and `require` it here. + * + * @see lithium\util\collection\Filters + */ + +/** + * The libraries file contains the loading instructions for all plugins, frameworks and other 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. This + * file also statically loads common classes to improve bootstrap performance. + */ +require __DIR__ . '/bootstrap/libraries.php'; + +/** + * The error configuration allows you to use the filter system along with the advanced matching + * rules of the `ErrorHandler` class to provide a high level of control over managing exceptions in + * your application, with no impact on framework or application code. + */ +require __DIR__ . '/bootstrap/errors.php'; + +/** + * This file contains configurations for connecting to external caching resources, as well as + * default caching rules for various systems within your application + */ +require __DIR__ . '/bootstrap/cache.php'; + +/** + * Include this file if your application uses one or more database connections. + */ +require __DIR__ . '/bootstrap/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 configuration for session (and/or cookie) storage, and user or web service + * authentication. + */ + require __DIR__ . '/bootstrap/session.php'; + require __DIR__ . '/bootstrap/auth.php'; +// require __DIR__ . '/bootstrap/error.php'; + +/** + * This file contains your application's globalization rules, including inflections, + * transliterations, localized validation, and how localized text should be loaded. Uncomment this + * line if you plan to globalize your site. + */ +// require __DIR__ . '/bootstrap/g11n.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'; + +/** + * This file configures console filters and settings, specifically output behavior and coloring. + */ +// require __DIR__ . '/bootstrap/console.php'; + + +?>
\ No newline at end of file diff --git a/config/bootstrap/.DS_Store b/config/bootstrap/.DS_Store Binary files differnew file mode 100644 index 0000000..5008ddf --- /dev/null +++ b/config/bootstrap/.DS_Store diff --git a/config/bootstrap/action.php b/config/bootstrap/action.php new file mode 100644 index 0000000..41b4d5e --- /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()` method 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); +}); + +?>
\ No newline at end of file diff --git a/config/bootstrap/auth.php b/config/bootstrap/auth.php new file mode 100644 index 0000000..11c963f --- /dev/null +++ b/config/bootstrap/auth.php @@ -0,0 +1,135 @@ +<?php +use lithium\storage\Session; +use lithium\security\Auth; +use lithium\util\String; +use app\models\User; +use lithium\core\Libraries; +use lithium\action\Dispatcher; +use lithium\net\http\Router; +use lithium\action\Response; + + +Session::config(array( + 'cookie' => array('adapter' => 'Cookie'), + 'default' => array('adapter' => 'Php'), + 'flash_message' => array('adapter' => 'Php') +)); + +Auth::config(array( + 'default' => array( + 'adapter' => 'Form', + 'model' => 'User', + 'cookie' => '', + 'fields' => array('username', 'password'), + //'scope' => array('active' => 'true'), //The active field must be true otherwise they can't auth, though we need + //to eventually send them to a page that explains they are banned. + 'session' => array('options' => array('name' => 'default')), + 'filters' => array( + 'password' => function($password) { + return $password; //prevents li3 from hashing the password before hand. + }, + + function($data) { + if (!empty($data['username'])) { + + //Find the first element record that matches the username in the request and get the salt field + $salt = User::find('first', array('conditions' => array('username' => $data['username']))); + + //The password to query is the password from the request + //hashed with the users stored salt + $data['password'] = String::hashPassword($data['password'], $salt->salt); + } + return $data; + }) + ) +)); + +$secret = "cake"; + +// Adds remember feature for form-based authentications. +Auth::applyFilter('check', function($self, $params, $chain) use ($secret) { + $query = 'first'; + $scope = array(); + extract($self::invokeMethod('_config', array($params['name']))); + if ($result = $chain->next($self, $params, $chain)) { + $request = $params['credentials']; + if ($request && $adapter == 'Form' && !empty($request->data['remember'])) { + $data = array_intersect_key($result, array_combine($fields, $fields)); + $data = serialize($data); + Session::write( + "Auth.{$params['name']}", + base64_encode($data), + array('name' => 'cookie') + ); + } + return $result; + } + if ($adapter == 'Form') { + $data = Session::read("Auth.{$params['name']}", array('name' => 'cookie')); + if ($data) { + $data = base64_decode($data); + $data = unserialize($data); + if (array_keys($data) == $fields) { + $model = Libraries::locate('models', $model); + $data = array_map('strval', $data); + $user = $model::$query($scope + $data); + if ($user) { + return $self::set($params['name'], $user->data()); + } + } + } + } + return $result; +}); + +// Removes remember cookie after sign out. +Auth::applyFilter('clear', function($self, $params, $chain) { + $config = $self::invokeMethod('_config', array($params['name'])); + if ($config['adapter'] == 'Form') { + if (Session::read("Auth.{$params['name']}", array('name' => 'cookie'))) { + Session::delete("Auth.{$params['name']}", array('name' => 'cookie')); + } + } + return $chain->next($self, $params, $chain); +}); + +//So that we can filter a bunch of methods in one +Dispatcher::applyFilter('_callable', function($self, $params, $chain) { + + //Invoke the _callable method, then execute the logic below + $ctrl = $chain->next($self, $params, $chain); + + //if the user is logged in + $user = Auth::check('default'); + if($user) + { + //check if they are accessing an admin function + if ($ctrl->request->controller == 'admin' && !($user['level'] == 'root' || $user['level'] == 'admin')) + { + return function() use ($request) { + + //Users / index isn't public derp. + return new Response(compact('request') + array('location' => '/')); + }; + } + + //If they aren't trying to access admin, return + return $ctrl; + } + //If they are performing a public action continue, + if (isset($ctrl->publicActions) && in_array($params['request']->action, $ctrl->publicActions)) { + return $ctrl; + } + + //Otherwise, send them to the login page + return function() use ($request) { + return new Response(compact('request') + array('location' => '/login')); + }; + + +}); + + + + +?>
\ No newline at end of file diff --git a/config/bootstrap/cache.php b/config/bootstrap/cache.php new file mode 100644 index 0000000..68f11e0 --- /dev/null +++ b/config/bootstrap/cache.php @@ -0,0 +1,62 @@ +<?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 creates a default cache configuration using the most optimized adapter available, and + * uses it to provide default caching for high-overhead operations. + */ +use lithium\storage\Cache; +use lithium\core\Libraries; +use lithium\action\Dispatcher; +use lithium\storage\cache\adapter\Apc; + +if (PHP_SAPI === 'cli') { + return; +} + +/** + * If APC is not available and the cache directory is not writeable, bail out. This block should be + * removed post-install, and the cache should be configured with the adapter you plan to use. + */ +$cachePath = Libraries::get(true, 'resources') . '/tmp/cache'; + +if (!($apcEnabled = Apc::enabled()) && !is_writable($cachePath)) { + return; +} + +/** + * This configures the default cache, based on whether ot not APC user caching is enabled. If it is + * not, file caching will be used. Most of this code is for getting you up and running only, and + * should be replaced with a hard-coded configuration, based on the cache(s) you plan to use. + */ +$default = array('adapter' => 'File', 'strategies' => array('Serializer')); + +if ($apcEnabled) { + $default = array('adapter' => 'Apc'); +} +Cache::config(compact('default')); + +/** + * Caches paths for auto-loaded and service-located classes. + */ +Dispatcher::applyFilter('run', function($self, $params, $chain) { + $key = md5(LITHIUM_APP_PATH) . '.core.libraries'; + + if ($cache = Cache::read('default', $key)) { + $cache = (array) $cache + Libraries::cache(); + Libraries::cache($cache); + } + $result = $chain->next($self, $params, $chain); + + if ($cache != Libraries::cache()) { + Cache::write('default', $key, Libraries::cache(), '+1 day'); + } + return $result; +}); + +?>
\ No newline at end of file diff --git a/config/bootstrap/connections.php b/config/bootstrap/connections.php new file mode 100644 index 0000000..a9355e6 --- /dev/null +++ b/config/bootstrap/connections.php @@ -0,0 +1,72 @@ +<?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 + */ + +/** + * ### Configuring backend database connections + * + * Lithium supports a wide variety relational and non-relational databases, and is designed to allow + * and encourage you to take advantage of multiple database technologies, choosing the most optimal + * one for each task. + * + * As with other `Adaptable`-based configurations, each database configuration is defined by a name, + * and an array of information detailing what database adapter to use, and how to connect to the + * database server. Unlike when configuring other classes, `Connections` uses two keys to determine + * which class to select. First is the `'type'` key, which specifies the type of backend to + * connect to. For relational databases, the type is set to `'database'`. For HTTP-based backends, + * like CouchDB, the type is `'http'`. Some backends have no type grouping, like MongoDB, which is + * unique and connects via a custom PECL extension. In this case, the type is set to `'MongoDb'`, + * and no `'adapter'` key is specified. In other cases, the `'adapter'` key identifies the unique + * adapter of the given type, i.e. `'MySql'` for the `'database'` type, or `'CouchDb'` for the + * `'http'` type. Note that while adapters are always specified in CamelCase form, types are + * specified either in CamelCase form, or in underscored form, depending on whether an `'adapter'` + * key is specified. See the examples below for more details. + * + * ### Multiple environments + * + * As with other `Adaptable` classes, `Connections` supports optionally specifying different + * configurations per named connection, depending on the current environment. For information on + * specifying environment-based configurations, see the `Environment` class. + * + * @see lithium\core\Adaptable + * @see lithium\core\Environment + */ +use lithium\data\Connections; + +/** + * Uncomment this configuration to use MongoDB as your default database. + */ + Connections::add('default', array( + 'type' => 'MongoDb', + 'host' => 'localhost', + 'database' => 'otakuhub', + 'persistent' => 'foo' + )); + +/** + * Uncomment this configuration to use CouchDB as your default database. + */ +// Connections::add('default', array( +// 'type' => 'http', +// 'adapter' => 'CouchDb', +// 'host' => 'localhost', +// 'database' => 'my_app' +// )); + +/** + * Uncomment this configuration to use MySQL as your default database. + */ +// Connections::add('default', array( +// 'type' => 'database', +// 'adapter' => 'MySql', +// 'host' => 'localhost', +// 'login' => 'root', +// 'password' => '', +// 'database' => 'my_app' +// )); + +?>
\ No newline at end of file diff --git a/config/bootstrap/console.php b/config/bootstrap/console.php new file mode 100644 index 0000000..e47e2c0 --- /dev/null +++ b/config/bootstrap/console.php @@ -0,0 +1,19 @@ +<?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\console\Dispatcher; + +Dispatcher::applyFilter('_call', function($self, $params, $chain) { + $params['callable']->response->styles(array( + 'heading' => '\033[1;30;46m' + )); + return $chain->next($self, $params, $chain); +}); + + +?>
\ No newline at end of file diff --git a/config/bootstrap/error.php b/config/bootstrap/error.php new file mode 100644 index 0000000..dc33bf5 --- /dev/null +++ b/config/bootstrap/error.php @@ -0,0 +1,37 @@ +<?php +/** + * First, import the relevant Lithium core classes. + */ +use \lithium\core\ErrorHandler; +use \lithium\analysis\Logger; +use lithium\action\Response; +use lithium\net\http\Media; + +/** + * Then, set up a basic logging configuration that will write to a file. + */ +Logger::config(array( + 'error' => array('adapter' => 'File') +)); + + +ErrorHandler::apply('lithium\action\Dispatcher::run', array(), function($info, $params) { + $response = new Response(array('request' => $params['request'])); + + $message = "/(^Template not found|^Controller '\w+' not found|^Action '\w+' not found)/"; + $template = (preg_match($message, $info['message'])) ? '404' : '500'; + + Logger::write('error', "{$info['file']} : {$info['line']} : {$info['message']}"); + switch($template){ + case '500': + debug($info);die; + break; + } + Media::render($response, compact('info', 'params'), array( + 'controller' => 'errors', + 'template' => $template, + 'layout' => 'default', + 'request' => $params['request'] + )); + return $response; +});
\ No newline at end of file diff --git a/config/bootstrap/errors.php b/config/bootstrap/errors.php new file mode 100644 index 0000000..8354478 --- /dev/null +++ b/config/bootstrap/errors.php @@ -0,0 +1,28 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2011, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +use lithium\core\ErrorHandler; +use lithium\action\Response; +use lithium\net\http\Media; + +ErrorHandler::apply('lithium\action\Dispatcher::run', array(), function($info, $params) { + $response = new Response(array( + 'request' => $params['request'], + 'status' => $info['exception']->getCode() + )); + + Media::render($response, compact('info', 'params'), array( + 'controller' => '_errors', + 'template' => 'development', + 'layout' => 'error', + 'request' => $params['request'] + )); + return $response; +}); + +?>
\ No newline at end of file diff --git a/config/bootstrap/g11n.php b/config/bootstrap/g11n.php new file mode 100644 index 0000000..e96241f --- /dev/null +++ b/config/bootstrap/g11n.php @@ -0,0 +1,149 @@ +<?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 bootstrap file contains class configuration for all aspects of globalizing your application, + * including localization of text, validation rules, setting timezones and character inflections, + * and identifying a user's locale. + */ +use lithium\core\Libraries; +use lithium\core\Environment; +use lithium\g11n\Locale; +use lithium\g11n\Catalog; +use lithium\g11n\Message; +use lithium\util\Inflector; +use lithium\util\Validator; +use lithium\net\http\Media; +use lithium\action\Dispatcher as ActionDispatcher; +use lithium\console\Dispatcher as ConsoleDispatcher; + +/** + * Sets the default timezone used by all date/time functions. + */ +date_default_timezone_set('UTC'); + +/** + * Adds globalization specific settings to the environment. + * + * The settings for the current locale, time zone and currency are kept as environment + * settings. This allows for _centrally_ switching, _transparently_ setting and retrieving + * globalization related settings. + * + * The environment settings are: + * + * - `'locale'` The effective locale. + * - `'locales'` Application locales available mapped to names. The available locales are used + * to negotiate he effective locale, the names can be used i.e. when displaying + * a menu for choosing the locale to users. + */ +$locale = 'en'; +$locales = array('en' => 'English'); + +Environment::set('production', compact('locale', 'locales')); +Environment::set('development', compact('locale', 'locales')); +Environment::set('test', array('locale' => 'en', 'locales' => array('en' => 'English'))); + +/** + * Globalization (g11n) catalog configuration. The catalog allows for obtaining and + * writing globalized data. Each configuration can be adjusted through the following settings: + * + * - `'adapter'` _string_: The name of a supported adapter. The builtin adapters are `Memory` (a + * simple adapter good for runtime data and testing), `Php`, `Gettext`, `Cldr` (for + * interfacing with Unicode's common locale data repository) and `Code` (used mainly for + * extracting message templates from source code). + * + * - `'path'` All adapters with the exception of the `Memory` adapter require a directory + * which holds the data. + * + * - `'scope'` If you plan on using scoping i.e. for accessing plugin data separately you + * need to specify a scope for each configuration, except for those using the `Memory`, + * `Php` or `Gettext` adapter which handle this internally. + */ +Catalog::config(array( + 'runtime' => array( + 'adapter' => 'Memory' + ), + // 'app' => array( + // 'adapter' => 'Gettext', + // 'path' => Libraries::get(true, 'resources') . '/g11n' + // ), + 'lithium' => array( + 'adapter' => 'Php', + 'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php' + ) +) + Catalog::config()); + +/** + * Integration with `Inflector`. + */ +// Inflector::rules('transliteration', Catalog::read(true, 'inflection.transliteration', 'en')); + +/** + * Inflector configuration examples. If your application has custom singular or plural rules, or + * extra non-ASCII characters to transliterate, you can configure that by uncommenting the lines + * below. + */ +// Inflector::rules('singular', array('rules' => array('/rata/' => '\1ratus'))); +// Inflector::rules('singular', array('irregular' => array('foo' => 'bar'))); +// +// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum'))); +// Inflector::rules('plural', array('irregular' => array('bar' => 'foo'))); +// +// Inflector::rules('transliteration', array('/É|Ê/' => 'E')); +// +// Inflector::rules('uninflected', 'bord'); +// Inflector::rules('uninflected', array('bord', 'baird')); + + +/** + * Integration with `View`. Embeds message translation aliases into the `View` + * class (or other content handler, if specified) when content is rendered. This + * enables translation functions, i.e. `<?=$t("Translated content"); ?>`. + */ +Media::applyFilter('_handle', function($self, $params, $chain) { + $params['handler'] += array('outputFilters' => array()); + $params['handler']['outputFilters'] += Message::aliases(); + return $chain->next($self, $params, $chain); +}); + +/** + * Integration with `Validator`. You can load locale dependent rules into the `Validator` + * by specifying them manually or retrieving them with the `Catalog` class. + */ +foreach (array('phone', 'postalCode', 'ssn') as $name) { + Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US')); +} + +/** + * Intercepts dispatching processes in order to set the effective locale by using + * the locale of the request or if that is not available retrieving a locale preferred + * by the client. + */ +ActionDispatcher::applyFilter('_callable', function($self, $params, $chain) { + $request = $params['request']; + $controller = $chain->next($self, $params, $chain); + + if (!$request->locale) { + $request->params['locale'] = Locale::preferred($request); + } + Environment::set(Environment::get(), array('locale' => $request->locale)); + return $controller; +}); + +ConsoleDispatcher::applyFilter('_callable', function($self, $params, $chain) { + $request = $params['request']; + $command = $chain->next($self, $params, $chain); + + if (!$request->locale) { + $request->params['locale'] = Locale::preferred($request); + } + Environment::set(Environment::get(), array('locale' => $request->locale)); + return $command; +}); + +?>
\ No newline at end of file diff --git a/config/bootstrap/libraries.php b/config/bootstrap/libraries.php new file mode 100644 index 0000000..4bffbdd --- /dev/null +++ b/config/bootstrap/libraries.php @@ -0,0 +1,127 @@ +<?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 libraries file is where you configure the various plugins, frameworks, and other libraries + * to be used by your application, including your application itself. This file also defines some + * global constants used to tell Lithium where to find your application and support libraries + * (including Lithium itself). It uses the `Libraries` class to add configurations for the groups of + * classes used in your app. + * + * In Lithium, a _library_ is any collection of classes located in a single base directory, which + * all share the same class-to-file naming convention, and usually a common class or namespace + * prefix. While all collections of classes are considered libraries, there are two special types of + * libraries: + * + * - **Applications**: Applications are libraries which follow the organizational conventions that + * Lithium defines for applications (see `Libraries::locate()` and `Libraries::paths()`), and + * which also include a web-accessible document root (i.e. the `webroot/` folder), and can + * dispatch HTTP requests (i.e. through `webroot/index.php`). + * + * - **Plugins**: Plugins are libraries which generally follow the same organizational conventions + * as applications, but are designed to be used within the context of another application. They + * _may_ include a public document root for supporting assets, but this requires a symlink from + * `libraries/<plugin-name>/webroot` to `<app-name>/webroot/<plugin-name>` (recommended for + * production), or a media filter to load plugin resources (see `/config/bootstrap/media.php`). + * + * Note that a library can be designed as both an application and a plugin, but this requires some + * special considerations in the bootstrap process, such as removing any `require` statements, and + * conditionally defining the constants below. + * + * By default, libraries are stored in the base `/libraries` directory, or in the + * application-specific `<app-name>/libraries` directory. Libraries can be loaded from either place + * without additional configuration, but note that if the same library is in both directories, the + * application-specific `libraries` directory will override the global one. + * + * The one exception to this is the _primary_ library, which is an application configured with + * `'default' => true` (see below); this library uses the `LITHIUM_APP_PATH` constant (also defined + * below) as its path. Note, however, that any library can be overridden with an arbitrary path by + * passing the `'path'` key to its configuration. See `Libraries::add()` for more options. + * + * @see lithium\core\Libraries + */ + +/** + * This is the path to your application's directory. It contains all the sub-folders for your + * application's classes and files. You don't need to change this unless your webroot folder is + * stored outside of your app folder. + */ +define('LITHIUM_APP_PATH', dirname(dirname(__DIR__))); + +/** + * This is the path to the class libraries used by your application, and must contain a copy of the + * Lithium core. By default, this directory is named `libraries`, and resides in the same + * directory as your application. If you use the same libraries in multiple applications, you can + * set this to a shared path on your server. + */ +define('LITHIUM_LIBRARY_PATH', dirname(LITHIUM_APP_PATH) . '/libraries'); + +/** + * Locate and load Lithium core library files. Throws a fatal error if the core can't be found. + * If your Lithium core directory is named something other than `lithium`, change the string below. + */ +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); +} + +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/Message.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)); + +/** + * Add some plugins: + */ +// Libraries::add('li3_docs'); +Libraries::add('li3_flash_message'); +Libraries::add('li3_paginate'); +?>
\ No newline at end of file diff --git a/config/bootstrap/media.php b/config/bootstrap/media.php new file mode 100644 index 0000000..66e002d --- /dev/null +++ b/config/bootstrap/media.php @@ -0,0 +1,63 @@ +<?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\action\Response; +use lithium\net\http\Media; + +Dispatcher::applyFilter('_callable', function($self, $params, $chain) { + list($library, $asset) = explode('/', $params['request']->url, 2) + array("", ""); + + if ($asset && ($path = Media::webroot($library)) && file_exists($file = "{$path}/{$asset}")) { + return function() use ($file) { + $info = pathinfo($file); + $media = Media::type($info['extension']); + $content = (array) $media['content']; + + return new Response(array( + 'headers' => array('Content-type' => reset($content)), + 'body' => file_get_contents($file) + )); + }; + } + return $chain->next($self, $params, $chain); +}); + +Media::type('jpg', 'image/jpeg', array('cast' => false, 'encode' => function($data) { + return $data['photo']->file->getBytes(); + })); + +?>
\ No newline at end of file diff --git a/config/bootstrap/session.php b/config/bootstrap/session.php new file mode 100644 index 0000000..c664be4 --- /dev/null +++ b/config/bootstrap/session.php @@ -0,0 +1,49 @@ +<?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 configures your session storage. The Cookie storage adapter must be connected first, since + * it intercepts any writes where the `'expires'` key is set in the options array. + */ +use lithium\storage\Session; + +/* +Session::config(array( + 'cookie' => array('adapter' => 'Cookie'), + 'default' => array('adapter' => 'Php') +)); +*/ +/** + * Uncomment the lines below to enable forms-based authentication. This configuration will attempt + * to authenticate users against a `Users` model. In a controller, run + * `Auth::check('default', $this->request)` to authenticate a user. This will check the POST data of + * the request (`lithium\action\Request::$data`) to see if the fields match the `'fields'` key of + * the configuration below. If successful, it will write the data returned from `Users::first()` to + * the session using the default session configuration. + * + * Once the session data is written, you can call `Auth::check('default')` to check authentication + * status or retrieve the user's data from the session. Call `Auth::clear('default')` to remove the + * user's authentication details from the session. This effectively logs a user out of the system. + * To modify the form input that the adapter accepts, or how the configured model is queried, or how + * the data is stored in the session, see the `Form` adapter API or the `Auth` API, respectively. + * + * @see lithium\security\auth\adapter\Form + * @see lithium\action\Request::$data + * @see lithium\security\Auth + */ +// use lithium\security\Auth; + +// Auth::config(array( +// 'default' => array( +// 'adapter' => 'Form', +// 'model' => 'Users', +// 'fields' => array('username', 'password') +// ) +// )); + +?>
\ No newline at end of file diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000..bde33dd --- /dev/null +++ b/config/routes.php @@ -0,0 +1,149 @@ +<?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 routes file is where you define your URL structure, which is an important part of the + * [information architecture](http://en.wikipedia.org/wiki/Information_architecture) of your + * application. Here, you can use _routes_ to match up URL pattern strings to a set of parameters, + * usually including a controller and action to dispatch matching requests to. For more information, + * see the `Router` and `Route` classes. + * + * @see lithium\net\http\Router + * @see lithium\net\http\Route + */ +use lithium\net\http\Router; +use lithium\core\Environment; +use app\models\Photo; + +/** + * Here, we are connecting `'/'` (the base path) to controller called `'Pages'`, + * its action called `view()`, and we pass a param to select the view file + * to use (in this case, `/views/pages/home.html.php`; see `app\controllers\PagesController` + * for details). + * + * @see app\controllers\PagesController + */ +Router::connect('/', 'Pages::view'); + +/** + * Connect the rest of `PagesController`'s URLs. This will route URLs like `/pages/about` to + * `PagesController`, rendering `/views/pages/about.html.php` as a static page. + */ +Router::connect('/pages/{:args}', 'Pages::view'); + + +/** + * Add the testing routes. These routes are only connected in non-production environments, and allow + * browser-based access to the test suite for running unit and integration tests for the Lithium + * core, as well as your own application and any other loaded plugins or frameworks. Browse to + * [http://path/to/app/test](/test) to run tests. + */ +if (!Environment::is('production')) { + Router::connect('/test/{:args}', array('controller' => 'lithium\test\Controller')); + Router::connect('/test', array('controller' => 'lithium\test\Controller')); +} + + +/* This is the login and logout routes */ +Router::connect('/login', array('controller' => 'users', 'action' => 'login')); +Router::connect('/logout', array('controller' => 'users', 'action' => 'logout')); + +/* Content routes */ +Router::connect('/anime', array('controller' => 'content', 'action' => 'anime')); +Router::connect('/anime/{:args}', array('controller' => 'content', 'action' => 'anime')); + +//Pagination route +Router::connect('/{:controller}/{:action}/page:{:page:[0-9]+}'); + + +/** +* Define an anonymous function that we will pass to the router instead of linking to a controller action +* The logic is quite simple: +* Call the version() method on the Photo model class with $request->id (MongoId for image) and a set of options. This is passed as an array to allow adding more options later. +* Finally just return a Response object with the image data as body (this is what version() returns) and the appropriate content type for the file ending. +* +* This method is limited, supports few formats etc but its a good start +*/ +$imageSizer = function($request) { + $contentTypeMappings = array( + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'png' => 'image/png', + 'gif' => 'image/gif' + ); + // Generate file based image of this + $imageBody = Photo::version($request->id, array( + 'width' => $request->width, + 'height' => $request->height + )); + return new Response(array( + 'headers' => array('Content-type' => $contentTypeMappings[$request->type]), + 'body' => $imageBody + )); +}; + +/** +This is a little bit more complicated. +We state that the handler for when this route is matched is the anonymous function we've declared and +we set up a pattern to match our two cases of image urls — both with and without size information. +The regex is quite simple even if it looks complex: +^/image/ <- begin with /image/ +(?P<foo>) is for setting up a named capture group. This equals doing {:foo:{pattern}} in Lithium. +So we have 1 capture group named {id} that have to match by 24 signs (mongoid), and an optional part "_{width}x{height}" and finally the filtype. + +Im unsure if the keys array can be handled some other way, but it failed for me without it. +*/ +$imageHandlingOptions = array( + 'handler' => $imageSizer, + 'pattern' => '@^/image/(?P<id>[0-9a-f]{24})(_(?P<width>[0-9]*)x(?P<height>[0-9]*)?)\.(?<type>[a-z]{2,4})@', + 'keys' => array('id'=>'id', 'width'=>'width', 'height'=>'height', 'type'=>'type') +); + +/** +Finally we connect this as a route. The regex sent as the first param here is overriden by the more complex one we have defined in the options array. +*/ +Router::connect('/image/{:id:[0-9a-f]{24}}.jpg', array(), $imageHandlingOptions); + + + +/** + * ### Database object routes + * + * The routes below are used primarily for accessing database objects, where `{:id}` corresponds to + * the primary key of the database object, and can be accessed in the controller as + * `$this->request->id`. + * + * If you're using a relational database, such as MySQL, SQLite or Postgres, where the primary key + * is an integer, uncomment the routes below to enable URLs like `/posts/edit/1138`, + * `/posts/view/1138.json`, etc. + */ +// Router::connect('/{:controller}/{:action}/{:id:\d+}.{:type}', array('id' => null)); +// Router::connect('/{:controller}/{:action}/{:id:\d+}'); + +/** + * If you're using a document-oriented database, such as CouchDB or MongoDB, or another type of + * database which uses 24-character hexidecimal values as primary keys, uncomment the routes below. + */ +Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null)); +Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}'); + +/** + * Finally, connect the default route. This route acts as a catch-all, intercepting requests in the + * following forms: + * + * - `/foo/bar`: Routes to `FooController::bar()` with no parameters passed. + * - `/foo/bar/param1/param2`: Routes to `FooController::bar('param1, 'param2')`. + * - `/foo`: Routes to `FooController::index()`, since `'index'` is assumed to be the action if none + * is otherwise specified. + * + * In almost all cases, custom routes should be added above this one, since route-matching works in + * a top-down fashion. + */ +Router::connect('/{:controller}/{:action}/{:args}'); + +?>
\ No newline at end of file |