function xautoload_ClassFinder_Helper_Map::registerNamespacePlugin in X Autoload 7.2
Register a plugin for a namespace or prefix.
Parameters
string $first_part: First part of the path generated from the class name.
xautoload_Plugin_Interface $plugin: The plugin.
File
- lib/
ClassFinder/ Helper/ Map.php, line 88
Class
- xautoload_ClassFinder_Helper_Map
- Helper class for the class finder. This is not part of ClassFinder, because we want to use the same logic for namespaces (PSR-0) and prefixes (PEAR).
Code
function registerNamespacePlugin($first_part, $plugin) {
if (!isset($plugin)) {
throw new Exception("Second argument cannot be NULL.");
}
elseif (!is_a($plugin, 'xautoload_Plugin_Interface')) {
throw new Exception("Second argument must implement xautoload_Plugin_Interface.");
}
if (!isset($this->nsPlugins[$first_part])) {
$id = $this->lastPluginIds[$first_part] = 1;
}
else {
$id = ++$this->lastPluginIds[$first_part];
}
$this->nsPlugins[$first_part][$id] = $plugin;
if (method_exists($plugin, 'setKillswitch')) {
// Give the plugin a red button to unregister or replace itself.
$plugin
->setKillswitch($plugin, $first_part, $id);
}
return $id;
}