Event_Dispatcher::removeObserver PHP Méthode

removeObserver() public méthode

Removes a registered observer that correspond to the given criteria
public removeObserver ( $callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null ) : boolean
Résultat boolean True if an observer was removed, false otherwise
    public function removeObserver($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null)
    {
        if (is_array($callback)) {
            if (is_object($callback[0])) {
                $reg = get_class($callback[0]) . '::' . $callback[1];
            } else {
                $reg = $callback[0] . '::' . $callback[1];
            }
        } else {
            $reg = $callback;
        }
        $removed = false;
        if (isset($this->_ro[$nName][$reg])) {
            if (!empty($class)) {
                if (strcasecmp($this->_ro[$nName][$reg]['class'], $class) == 0) {
                    unset($this->_ro[$nName][$reg]);
                    $removed = true;
                }
            } else {
                unset($this->_ro[$nName][$reg]);
                $removed = true;
            }
        }
        if (isset($this->_ro[$nName]) && count($this->_ro[$nName]) == 0) {
            unset($this->_ro[$nName]);
        }
        return $removed;
    }

Usage Example

 /**
  * @param Piwik_Plugin $plugin
  * @return void
  */
 public function unloadPlugin($plugin)
 {
     if (!$plugin instanceof Piwik_Plugin) {
         $plugin = $this->loadPlugin($plugin);
     }
     $hooks = $plugin->getListHooksRegistered();
     foreach ($hooks as $hookName => $methodToCall) {
         $success = $this->dispatcher->removeObserver(array($plugin, $methodToCall), $hookName);
         if ($success !== true) {
             throw new Exception("Error unloading plugin = " . $plugin->getClassName() . ", method = {$methodToCall}, hook = {$hookName} ");
         }
     }
     unset($this->loadedPlugins[$plugin->getClassName()]);
 }
All Usage Examples Of Event_Dispatcher::removeObserver