From 2389d66da849798f8d4ec5f10e3b07c11da49185 Mon Sep 17 00:00:00 2001 From: Michael Francis Date: Sat, 28 May 2011 13:28:16 -0400 Subject: Initial Commit --- config/.DS_Store | Bin 0 -> 6148 bytes config/bootstrap.php | 86 ++++++++++++++++++++++ config/bootstrap/.DS_Store | Bin 0 -> 6148 bytes config/bootstrap/action.php | 55 +++++++++++++++ config/bootstrap/auth.php | 135 +++++++++++++++++++++++++++++++++++ config/bootstrap/cache.php | 62 ++++++++++++++++ config/bootstrap/connections.php | 72 +++++++++++++++++++ config/bootstrap/console.php | 19 +++++ config/bootstrap/error.php | 37 ++++++++++ config/bootstrap/errors.php | 28 ++++++++ config/bootstrap/g11n.php | 149 +++++++++++++++++++++++++++++++++++++++ config/bootstrap/libraries.php | 127 +++++++++++++++++++++++++++++++++ config/bootstrap/media.php | 63 +++++++++++++++++ config/bootstrap/session.php | 49 +++++++++++++ config/routes.php | 149 +++++++++++++++++++++++++++++++++++++++ 15 files changed, 1031 insertions(+) create mode 100644 config/.DS_Store create mode 100644 config/bootstrap.php create mode 100644 config/bootstrap/.DS_Store create mode 100644 config/bootstrap/action.php create mode 100644 config/bootstrap/auth.php create mode 100644 config/bootstrap/cache.php create mode 100644 config/bootstrap/connections.php create mode 100644 config/bootstrap/console.php create mode 100644 config/bootstrap/error.php create mode 100644 config/bootstrap/errors.php create mode 100644 config/bootstrap/g11n.php create mode 100644 config/bootstrap/libraries.php create mode 100644 config/bootstrap/media.php create mode 100644 config/bootstrap/session.php create mode 100644 config/routes.php (limited to 'config') diff --git a/config/.DS_Store b/config/.DS_Store new file mode 100644 index 0000000..bd2fe53 Binary files /dev/null and b/config/.DS_Store differ 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 @@ + \ No newline at end of file diff --git a/config/bootstrap/.DS_Store b/config/bootstrap/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/config/bootstrap/.DS_Store differ 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 @@ + $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 @@ + 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 @@ + '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 @@ + '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 @@ +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 @@ + 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 @@ + $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 @@ + '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. ``. + */ +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 @@ +/webroot` to `/webroot/` (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 `/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 @@ +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 @@ + 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 @@ + '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) 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[0-9a-f]{24})(_(?P[0-9]*)x(?P[0-9]*)?)\.(?[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 -- cgit v1.2.3