summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2011-06-06 16:20:29 +0200
committerAdrian Lang <lang@cosmocode.de>2011-06-06 16:21:38 +0200
commitd54ac87747635038aaaf9b4c7a2df7a8a0cd450d (patch)
treee6bb5b3182a8fadef62d743cf63bbf6beeae7f2e
parent1b595a184f93048f862a231951436b3c3f3d1951 (diff)
downloadrpg-d54ac87747635038aaaf9b4c7a2df7a8a0cd450d.tar.gz
rpg-d54ac87747635038aaaf9b4c7a2df7a8a0cd450d.tar.bz2
Use autoloading for plugin classes
-rw-r--r--inc/load.php13
-rw-r--r--inc/plugincontroller.class.php21
2 files changed, 17 insertions, 17 deletions
diff --git a/inc/load.php b/inc/load.php
index ef6f7f31c..d30397f6e 100644
--- a/inc/load.php
+++ b/inc/load.php
@@ -43,7 +43,7 @@ require_once(DOKU_INC.'inc/auth.php');
* require()s their associated php files when an object is instantiated.
*
* @author Andreas Gohr <andi@splitbrain.org>
- * @todo add generic loading of plugins and other generically named classes
+ * @todo add generic loading of renderers and auth backends
*/
function load_autoload($name){
static $classes = null;
@@ -87,5 +87,16 @@ function load_autoload($name){
require_once($classes[$name]);
return;
}
+
+ // Plugin loading
+ if(preg_match('/^(helper|syntax|action|admin|renderer)_plugin_([^_]+)(?:_([^_]+))?$/',
+ $name, $m)) {
+ //try to load the wanted plugin file
+ // include, but be silent. Maybe some other autoloader has an idea
+ // how to load this class.
+ $c = ((count($m) === 4) ? "/{$m[3]}" : '');
+ @include DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
+ return;
+ }
}
diff --git a/inc/plugincontroller.class.php b/inc/plugincontroller.class.php
index cec5c73a9..ea5725d47 100644
--- a/inc/plugincontroller.class.php
+++ b/inc/plugincontroller.class.php
@@ -72,32 +72,21 @@ class Doku_Plugin_Controller {
return null;
}
+ $class = $type.'_plugin_'.$name;
+
//plugin already loaded?
if(!empty($DOKU_PLUGINS[$type][$name])){
if ($new || !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
- $class = $type.'_plugin_'.$name;
- return class_exists($class) ? new $class : null;
+ return class_exists($class, true) ? new $class : null;
} else {
return $DOKU_PLUGINS[$type][$name];
}
}
- //try to load the wanted plugin file
- $dir = $this->get_directory($plugin);
- $file = $component ? "$type/$component.php" : "$type.php";
-
- if(!is_file(DOKU_PLUGIN."$dir/$file")){
- return null;
- }
-
- if (!include_once(DOKU_PLUGIN."$dir/$file")) {
- return null;
- }
-
//construct class and instantiate
- $class = $type.'_plugin_'.$name;
- if (!class_exists($class)){
+ if (!class_exists($class, true)) {
# the plugin might be in the wrong directory
+ $dir = $this->get_directory($plugin);
$inf = confToHash(DOKU_PLUGIN."$dir/plugin.info.txt");
if($inf['base'] && $inf['base'] != $plugin){
msg("Plugin installed incorrectly. Rename plugin directory '".