You are here

class _menu_editor_NotifyEngine in Menu Editor 6.3

Hierarchy

Expanded class hierarchy of _menu_editor_NotifyEngine

File

./menu_editor.admin.inc, line 340

View source
class _menu_editor_NotifyEngine {
  protected $_trail = array();
  protected $_listeners = array();
  public function __construct($menu) {
    foreach (menu_editor_module_implements_class('menu_editor_Listener') as $module => $classname) {
      if (method_exists($classname, 'construct')) {

        // Use the factory method.
        // This method could return NULL in some cases.
        $listener = call_user_func("{$classname}::construct", $menu);
      }
      else {

        // use the normal constructor
        $listener = new $classname($menu);
      }
      if (is_object($listener)) {
        foreach (get_class_methods($listener) as $methodname) {
          $this->_listeners[$methodname][$module] = $listener;
        }
      }
    }
  }
  public function notifyItem(&$item) {
    while (TRUE) {
      $last_item = end($this->_trail);
      if (!$last_item || $last_item['mlid'] === $item['plid']) {
        $this->_trail[$item['mlid']] = $item;
        break;
      }
      array_pop($this->_trail);
    }
    $module_run = array();
    foreach (array(
      'notifyItem__' . preg_replace('/[^a-z0-9]/', '_', strtolower($item['router_path'])),
      'notifyItem',
    ) as $method) {
      if (isset($this->_listeners[$method])) {
        foreach ($this->_listeners[$method] as $module => $listener) {
          if (!isset($module_run[$module])) {
            $listener
              ->{$method}($item, $this->_trail);
            $module_run[$module] = TRUE;
          }
        }
      }
    }
  }
  public function flush() {
    foreach ($this->_listeners['flush'] as $module => $listener) {
      $listener
        ->flush();
    }
  }

}

Members