Browse Source

Use Configure to load plugin paths.

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.
Mark Story 11 years ago
parent
commit
b60cd1f8f6
2 changed files with 10 additions and 30 deletions
  1. 6 30
      src/Core/Plugin.php
  2. 4 0
      tests/test_app/config/plugins.php

+ 6 - 30
src/Core/Plugin.php

@@ -15,6 +15,7 @@
 namespace Cake\Core;
 
 use Cake\Core\ClassLoader;
+use Cake\Core\Configure;
 use DirectoryIterator;
 
 /**
@@ -42,13 +43,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.
      *
@@ -125,8 +119,8 @@ class Plugin
             }
             return;
         }
-        if (static::$_config === null) {
-            static::_loadConfigMap();
+        if (!Configure::check('pluginPaths')) {
+            Configure::load('plugins');
         }
 
         $config += [
@@ -137,8 +131,8 @@ class Plugin
             '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'])) {
@@ -146,7 +140,7 @@ class 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;
                 }
             }
@@ -184,24 +178,6 @@ class Plugin
     }
 
     /**
-     * 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.
      *
      * If passed an options array, it will be used as a common default for all plugins to be loaded

+ 4 - 0
tests/test_app/config/plugins.php

@@ -0,0 +1,4 @@
+<?php
+$config = [
+    'plugins' => []
+];