/** * Sets plugin by name. Plugin of same name is replaced when exists. * * @param string $name * @param IPlugin $plugin * @return PluginContainer */ public function setPlugin($name, IPlugin $plugin) { $this->removePlugin($name); $this->plugins[(string) $name] = $plugin; foreach ((array) $plugin->declareHooks() as $hook => $method) { if (is_int($hook)) { // numerical key, method has same name as hook $hook = $method; } $callable = array($plugin, $method); if (!is_callable($callable)) { throw new \InvalidArgumentException(sprintf('Wrong callcable suplied by %s for "%s" hook ', get_class($plugin), $hook)); } $this->hooks[$hook][] = $callable; } return $this; }
public static function add(IPlugin $plugin) { Plugins::$registry[$plugin->name()] = $plugin; }