Last active
August 29, 2015 14:25
-
-
Save tleilax/2c98d6b6a37cb60f2db6 to your computer and use it in GitHub Desktop.
Stud.IP: PluginManager Plugin construction loop fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PluginManager | |
{ | |
// ... | |
/** | |
* Get instance of the plugin specified by plugin meta data. | |
* | |
* @param Array $plugin_info plugin meta data | |
* @param mixed $context context range id (optional and deprecated) | |
* @throws Exception when running into a plugin's constructor loop | |
*/ | |
protected function getCachedPlugin ($plugin_info, $context = NULL) | |
{ | |
$class = $plugin_info['class']; | |
$path = $plugin_info['path']; | |
if (isset($this->plugin_cache[$class])) { | |
return $this->plugin_cache[$class]; | |
} | |
if (array_key_exists($class, $this->plugin_cache) && $this->plugin_cache[$class] === null) { | |
throw new Exception("Plugin constructor loop detected. Avoid refering to the same plugin through PluginEngine in the plugin's constructor"); | |
} | |
$this->plugin_cache[$class] = null; | |
$plugin_class = $this->loadPlugin($class, $path); | |
if ($plugin_class) { | |
$plugin = $plugin_class->newInstance(); | |
} | |
return $this->plugin_cache[$class] = $plugin; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment