You are here

function xautoload_ClassFinder_Helper_Map::registerPlugin in X Autoload 7.3

Register a plugin for a namespace or prefix.

Parameters

string $logical_base_path: First part of the path generated from the class name.

xautoload_FinderPlugin_Interface $plugin: The plugin.

string $base_dir: Id under which the plugin should be registered. This may be a numeric id, or a string key.

Return value

int

Throws

Exception

File

lib/ClassFinder/Helper/Map.php, line 117

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 registerPlugin($logical_base_path, $plugin, $base_dir = NULL) {
  if (!isset($plugin)) {
    throw new Exception("Second argument cannot be NULL.");
  }
  elseif (!is_a($plugin, 'xautoload_FinderPlugin_Interface')) {
    throw new Exception("Second argument must implement xautoload_FinderPlugin_Interface.");
  }
  if (is_string($base_dir) && !is_numeric($base_dir)) {
    $id = $base_dir;
  }
  elseif (!isset($this->plugins[$logical_base_path])) {
    $id = $this->lastPluginIds[$logical_base_path] = 1;
  }
  else {
    $id = ++$this->lastPluginIds[$logical_base_path];
  }
  $this->plugins[$logical_base_path][$id] = $plugin;
  if (method_exists($plugin, 'setKillswitch')) {

    // Give the plugin a red button to unregister or replace itself.
    $plugin
      ->setKillswitch($plugin, $logical_base_path, $id);
  }
  return $id;
}