Browse Source

Strawman for vendor plugins.

This is a basic strawman for changing how plugins are installed. Instead
of putting composer managed plugins into /plugins, this will allow
a path configuration file to define where plugins are located. Having
this configuration file, will allow the plugin-installer to update the
file.

This will require additional changes in cakephp/app, and
cakephp/plugin-installer.
Mark Story 11 years ago
parent
commit
a9bc1d720f
1 changed files with 32 additions and 0 deletions
  1. 32 0
      src/Core/Plugin.php

+ 32 - 0
src/Core/Plugin.php

@@ -42,6 +42,13 @@ 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.
      *
@@ -118,6 +125,9 @@ class Plugin
             }
             return;
         }
+        if (static::$_config === null) {
+            static::_loadConfigMap();
+        }
 
         $config += [
             'autoload' => false,
@@ -127,6 +137,10 @@ class Plugin
             'ignoreMissing' => false
         ];
 
+        if (!isset($config['path']) && isset(static::$_config[$plugin])) {
+            $config['path'] = static::$_config[$plugin];
+        }
+
         if (empty($config['path'])) {
             $paths = App::path('Plugin');
             foreach ($paths as $path) {
@@ -170,6 +184,24 @@ 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