Skip to content

Commit

Permalink
Use Configure to load plugin paths.
Browse files Browse the repository at this point in the history
Switch to using more standard framework features to load the plugin
configuration file. This will also allow us to dump() to export files
from the plugin-installer.
  • Loading branch information
markstory committed Jan 13, 2015
1 parent a9bc1d7 commit b60cd1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
36 changes: 6 additions & 30 deletions src/Core/Plugin.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Core;

use Cake\Core\ClassLoader;
use Cake\Core\Configure;
use DirectoryIterator;

/**
Expand All @@ -41,13 +42,6 @@ class Plugin
*/
protected static $_loader;

/**
* The config map of plugins and their paths.
*
* @var array
*/
protected static $_config;

/**
* Loads a plugin and optionally loads bootstrapping,
* routing files or runs an initialization function.
Expand Down Expand Up @@ -125,8 +119,8 @@ public static function load($plugin, array $config = [])
}
return;
}
if (static::$_config === null) {
static::_loadConfigMap();
if (!Configure::check('pluginPaths')) {
Configure::load('plugins');
}

$config += [
Expand All @@ -137,16 +131,16 @@ public static function load($plugin, array $config = [])
'ignoreMissing' => false
];

if (!isset($config['path']) && isset(static::$_config[$plugin])) {
$config['path'] = static::$_config[$plugin];
if (!isset($config['path'])) {
$config['path'] = Configure::read('plugins.' . $plugin);
}

if (empty($config['path'])) {
$paths = App::path('Plugin');
foreach ($paths as $path) {
$pluginPath = str_replace('/', DS, $plugin);
if (is_dir($path . $pluginPath)) {
$config += ['path' => $path . $pluginPath . DS];
$config['path'] = $path . $pluginPath . DS;
break;
}
}
Expand Down Expand Up @@ -183,24 +177,6 @@ public static function load($plugin, array $config = [])
}
}

/**
* Loads the config mappings for plugins.
*
* The map data in CONFIG/plugins.php map data is used set default paths
* for where plugins are located.
*
* @return void
*/
protected static function _loadConfigMap()
{
if (!file_exists(CONFIG . 'plugins.php')) {
static::$_config = [];
return;
}
$config = include CONFIG . 'plugins.php';
static::$_config = $config;
}

/**
* Will load all the plugins located in the default plugin folder.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/test_app/config/plugins.php
@@ -0,0 +1,4 @@
<?php
$config = [
'plugins' => []
];

0 comments on commit b60cd1f

Please sign in to comment.