BIGACE PHP Cross Reference Content Management Systems

Source: /system/classes/event/EventDispatcher.php - 73 lines - 2886 bytes - Summary - Text - Print

Description: BIGACE - a PHP and MySQL based Web CMS. Copyright (C) Kevin Papst. BIGACE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

   1  <?php
   2  /**
   3   * BIGACE - a PHP and MySQL based Web CMS.
   4   * Copyright (C) Kevin Papst.
   5   *
   6   * BIGACE is free software; you can redistribute it and/or
   7   * modify it under the terms of the GNU General Public License
   8   * as published by the Free Software Foundation; either version 2
   9   * of the License, or (at your option) any later version.
  10   *
  11   * BIGACE is distributed in the hope that it will be useful,
  12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14   * GNU General Public License for more details.
  15   *
  16   * You should have received a copy of the GNU General Public License
  17   * along with this program; if not, write to the Free Software Foundation,
  18   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19   *
  20   * For further information visit {@link http://www.bigace.de http://www.bigace.de}.
  21   *
  22   * @package bigace.classes
  23   * @subpackage event
  24   */
  25  
  26  import('classes.event.Event');
  27  import('classes.util.ObjectHelper');
  28  
  29  /**
  30   * Broadcast messages through the system to registered listener usig this class.
  31   *
  32   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  33   * @author Kevin Papst 
  34   * @copyright Copyright (C) Kevin Papst
  35   * @version $Id: EventDispatcher.php 2 2011-01-31 13:29:57Z kevin $
  36   * @package bigace.classes
  37   * @subpackage event
  38   */
  39  class EventDispatcher
  40  {
  41      
  42      
  43      //TODO add a simple - static - way of registering event listener with the database
  44      
  45      /**
  46        * Call EventDispatcher::propagateEvent('foo', array()); for sending the event 'foo' with no parameter.
  47       * Call EventDispatcher::propagateEvent('bar', array('id' => 1)); for sending the event 'bar' with the parameter id = 1.
  48       *
  49       * @param String $type the event type to broadcast
  50       * @param Array $params the parameter to send along
  51       */
  52  	function propagateEvent($type, $params = array()) {
  53          $event = new Event($type, $params);
  54          $sqlString = $GLOBALS['_BIGACE']['SQL_HELPER']->loadStatement('events_load_type');
  55          $sqlString = $GLOBALS['_BIGACE']['SQL_HELPER']->prepareStatement($sqlString, array('EVENT' => $type), true);
  56          $events = $GLOBALS['_BIGACE']['SQL_HELPER']->execute($sqlString);
  57          for($i = 0; $i < $events->count(); $i++) {
  58              $listener = $events->next();
  59              $listClass = createInstance($listener['class']);
  60              if(!$event->isCanceled()) {
  61                  if(ObjectHelper::is_class_of($listClass, "EventListener")) {
  62                      try {
  63                      $listClass->handleEvent($event);
  64                      } catch (Exception $e) {
  65                          $GLOBALS['LOGGER']->logError('EventListener '.$listener['class'].' crashed for event "'.$type . 'with message: ' . $e->getMessage());
  66                      }
  67                  } else {
  68                      $GLOBALS['LOGGER']->logError('EventListener '.$listener['id'].' ('.$listener['class'].') for type "'.$type.'" is not subclass of EventListener!' );
  69                  }
  70  }
  71          }
  72      }
  73  }

title

Description

title

Description

title

Description

title

title

Body