Skip to content

Instantly share code, notes, and snippets.

@tleilax
Last active August 29, 2015 14:25
Show Gist options
  • Save tleilax/2c98d6b6a37cb60f2db6 to your computer and use it in GitHub Desktop.
Save tleilax/2c98d6b6a37cb60f2db6 to your computer and use it in GitHub Desktop.
Stud.IP: PluginManager Plugin construction loop fix
<?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