Commit: a890a6acc8d9a3f8690d5c2ae6bdf11e99c5490a

Author: nate | Date: 2009-12-18 18:19:04 -0500
Implementing CakePHP bootstrapping, and adding initial documentation.
diff --git a/.gitignore b/.gitignore index e69de29..e43b0f9 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/config/bootstrap.php b/config/bootstrap.php new file mode 100644 index 0000000..3774638 --- /dev/null +++ b/config/bootstrap.php @@ -0,0 +1,52 @@ +<?php +/** + * Li3_Cake: Connecting the most rad framework with CakePHP + * + * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +use \lithium\core\Libraries; + +$config = Libraries::get('li3_cake') + array('name' => 'cakephp', 'core' => null); + +defined('DS') ?: define('DS', DIRECTORY_SEPARATOR); +defined('ROOT') ?: define('ROOT', dirname(LITHIUM_APP_PATH)); +defined('APP_DIR') ?: define('APP_DIR', basename(LITHIUM_APP_PATH)); +defined('WEBROOT_DIR') ?: define('WEBROOT_DIR', 'webroot'); +defined('WWW_ROOT') ?: define('WWW_ROOT', LITHIUM_APP_PATH . DS . 'webroot' . DS); + +defined('E_DEPRECATED') ?: define('E_DEPRECATED', 8192); +error_reporting(E_ALL & ~E_DEPRECATED); + +if (!defined('CAKE_CORE_INCLUDE_PATH')) { + if (!$config['core']) { + $app = LITHIUM_APP_PATH; + $core = LITHIUM_LIBRARY_PATH; + $paths = array("{$app}/libraries/{$config['name']}", "{$core}/{$config['name']}"); + + foreach ($paths as $path) { + if (is_dir($path)) { + define('CAKE_CORE_INCLUDE_PATH', $path); + break; + } + } + if (!defined('CAKE_CORE_INCLUDE_PATH')) { + throw new Exception("CakePHP core not found"); + } + } else { + define('CAKE_CORE_INCLUDE_PATH', $config['core']); + } +} + +if (!defined('CORE_PATH')) { + $ps = PATH_SEPARATOR; + $path = CAKE_CORE_INCLUDE_PATH . $ps . ROOT . DS . APP_DIR . DS . $ps . ini_get('include_path'); + ini_set('include_path', $path); + define('APP_PATH', null); + define('CORE_PATH', null); +} + +include CAKE_CORE_INCLUDE_PATH . '/cake/bootstrap.php'; + +?> \ No newline at end of file diff --git a/config/core.php b/config/core.php new file mode 100644 index 0000000..ad6d0cd --- /dev/null +++ b/config/core.php @@ -0,0 +1,13 @@ +<?php +/** + * Li3_Cake: Connecting the most rad framework with CakePHP + * + * @copyright Copyright 2009, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +if (file_exists(LITHIUM_APP_PATH . '/config/core.php')) { + require LITHIUM_APP_PATH . '/config/core.php'; +} + +?> \ No newline at end of file diff --git a/readme.wiki b/readme.wiki new file mode 100644 index 0000000..1713343 --- /dev/null +++ b/readme.wiki @@ -0,0 +1,53 @@ +# Li3_Cake + + _Integrating the most rad framework with CakePHP_ + +The `li3_cake` plugin allows you to develop applications that use CakePHP and Lithium together, leveraging classes and exposing resources using both frameworks in unison. + +First, get a fresh copy of CakePHP by downloading or cloning, and install it in `app/libraries/cakephp` or `/libraries/cakephp` (this director should contain `app`, `cake`, etc). Then load the `li3_cake` plugin in your bootstrap file: + +{{{ +Libraries::add('plugin', 'li3_cake'); +}}} + +Finally, since CakePHP will also try to load `bootstrap.php`, we need to add a check at the top to make sure it doesn't get executed twice: + +{{{ +if (defined("LITHIUM_APP_PATH")) { + return true; +} +}}} + +Finally, we can return to `webroot/index.php`, where you have a couple of options. If you're only using Lithium classes, and not dispatching to any Lithium controllers, you can simply call CakePHP's dispatcher, as you normally would: + +{{{ +<?php + +require dirname(__DIR__) . '/config/bootstrap.php'; + +$dispatcher = new Dispatcher(); +$dispatcher->dispatch(); + +?> +}}} + +Alternatively, you can set it up such that requests are dispatched to Lithium first, and then to Cake, if no Lithium controllers can respond to the request: + +{{{ +<?php + +require dirname(__DIR__) . '/config/bootstrap.php'; + +try { + echo lithium\action\Dispatcher::run(); +} catch (Exception $e) { + if ($e->getMessage() == 'Could not route request') { + $dispatcher = new Dispatcher(); + $dispatcher->dispatch(); + } +} + +?> +}}} + +This allows you to replace only specific parts of your CakePHP application with Lithium controllers or responders, or incrementally migrate your application to Lithium. \ No newline at end of file