Permalink
Browse files

Merging "plugin" and "library" concepts; both are now handled uniform…

…ly as "libraries". Removing `app/libraries/plugins` directory, removing plugin loading / configuration code, and refactoring `\core\Libraries::add()`. Adding route auto-loading to filter in `app/config/bootstrap/action.php`.
  • Loading branch information...
1 parent 0c12c78 commit e141ab680db2b9ec7839eab30612c4423f61bf00 @nateabele nateabele committed with gwoo Feb 23, 2010
View
@@ -1,3 +1,3 @@
.DS_Store
-app/libraries/plugins/*
+app/libraries/*
app/resources/tmp/*
@@ -17,18 +17,29 @@
* @see lithium\util\collection\Filters
*/
+use \lithium\core\Libraries;
use \lithium\net\http\Router;
use \lithium\core\Environment;
use \lithium\action\Dispatcher;
/**
- * Loads application routes before the request is dispatched. Change this to `include_once` if
- * more than one request cycle is executed per HTTP request.
+ * This filter 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, or if application
+ * routes must be loaded first (in which case the 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\net\http\Router
*/
Dispatcher::applyFilter('run', function($self, $params, $chain) {
- include __DIR__ . '/../routes.php';
+ foreach (Libraries::get() as $name => $config) {
+ if ($config['default']) {
+ continue;
+ }
+ $file = "{$config['path']}/config/routes.php";
+ file_exists($file) ? include $file : null;
+ }
+ include LITHIUM_APP_PATH . '/config/routes.php';
return $chain->next($self, $params, $chain);
});
File renamed without changes.
@@ -83,10 +83,6 @@ class Libraries {
'{:root}/libraries/{:name}'
),
'models' => '{:library}\models\{:name}',
- 'plugins' => array(
- '{:app}/libraries/plugins/{:name}',
- '{:root}/libraries/plugins/{:name}'
- ),
'test' => array(
'{:library}\extensions\test\{:namespace}\{:class}\{:name}',
'{:library}\test\{:namespace}\{:class}\{:name}' => array('libraries' => 'lithium')
@@ -194,49 +190,52 @@ public static function paths($path = null) {
* which receives the class name as a parameter, and returns a file path as output.
* @return array Returns the resulting set of options created for this library.
*/
- public static function add($name, $config = array()) {
+ public static function add($name, array $config = array()) {
$defaults = array(
'path' => null,
'prefix' => $name . "\\",
'suffix' => '.php',
'loader' => null,
'includePath' => false,
'transform' => null,
- 'bootstrap' => null,
+ 'bootstrap' => true,
'defer' => false,
'default' => false
);
- if ($name == 'lithium') {
- $defaults['path'] = LITHIUM_LIBRARY_PATH . '/lithium';
- $defaults['loader'] = 'lithium\core\Libraries::load';
+ if ($name === 'lithium') {
$defaults['defer'] = true;
- } elseif ($name == 'plugin') {
- return static::_addPlugins((array) $config);
+ $defaults['bootstrap'] = false;
+ $defaults['path'] = dirname(__DIR__);
+ $defaults['loader'] = 'lithium\core\Libraries::load';
}
- $config = (array) $config + $defaults;
- if ($config['default']) {
+ if (isset($config['default']) && $config['default']) {
static::$_default = $name;
- $config['path'] = $config['path'] ?: LITHIUM_APP_PATH;
+ $defaults['path'] = LITHIUM_APP_PATH;
+ $defaults['bootstrap'] = false;
}
+ $config += $defaults;
- if ($config['path']) {
- $config['path'] = str_replace('\\', '/', $config['path']);
- } else {
- $config['path'] = static::locate('libraries', $name);
+ if (!$config['path']) {
+ $config['path'] = static::_locatePath('libraries', compact('name') + array(
+ 'app' => LITHIUM_APP_PATH, 'root' => LITHIUM_LIBRARY_PATH
+ ));
}
+
+ $config['path'] = str_replace('\\', '/', $config['path']);
static::$_configurations[$name] = $config;
if ($config['includePath']) {
$path = ($config['includePath'] === true) ? $config['path'] : $config['includePath'];
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
}
- if (!empty($config['bootstrap'])) {
- if ($config['bootstrap'] === true) {
- $config['bootstrap'] = 'config/bootstrap.php';
- }
+ if ($config['bootstrap'] === true) {
+ $path = "{$config['path']}/config/bootstrap.php";
+ $config['bootstrap'] = file_exists($path) ? '/config/bootstrap.php' : false;
+ }
+ if ($config['bootstrap']) {
require "{$config['path']}/{$config['bootstrap']}";
}
@@ -685,7 +684,7 @@ protected static function _search($config, $options, $name = null) {
if ($exclude = $options['exclude']) {
if (is_string($exclude)) {
$libs = preg_grep($exclude, $libs, PREG_GREP_INVERT);
- } else if (is_callable($exclude)){
+ } elseif (is_callable($exclude)) {
$libs = array_values(array_filter($libs, $exclude));
}
}
@@ -700,43 +699,6 @@ protected static function _search($config, $options, $name = null) {
}
/**
- * Register a Lithium plugin.
- *
- * @param string $plugins
- * @param string $options
- * @return void
- */
- protected static function _addPlugins($plugins) {
- $defaults = array('bootstrap' => null, 'route' => true, 'path' => null);
- $params = array('app' => LITHIUM_APP_PATH, 'root' => LITHIUM_LIBRARY_PATH);
- $result = array();
-
- foreach ($plugins as $name => $options) {
- if (is_int($name)) {
- $name = $options;
- $options = array();
- }
- $options += $defaults;
-
- if ($options['path'] === null) {
- $options['path'] = static::_locatePath('plugins', compact('name') + $params);
- }
- if ($options['bootstrap'] === null) {
- $options['bootstrap'] = file_exists($options['path'] . '/config/bootstrap.php');
- }
- $plugin = static::add($name, $options);
-
- if ($plugin['route']) {
- $defaultRoutes = $plugin['path'] . '/config/routes.php';
- $route = ($plugin['route'] === true) ? $defaultRoutes : $plugin['route'];
- !file_exists($route) ?: include $route;
- }
- $result[$name] = $plugin;
- }
- return $result;
- }
-
- /**
* Get params from type.
*
* @param string $type

0 comments on commit e141ab6

Please sign in to comment.