Location: PHPKode > scripts > Dispatcher > dispatcher/Dispatcher.php
<?php
/**
 * @li gnu/agpl v3 or later
 * @code utf8
 * @version 0.1
 * @author cojack from Aichra.pl
 * @date 22.09.09
 *
 **/

/**
 * We require a event handler
 */
require_once('HandlerShow.php');


/**
 * @class Dispatcher
 * @throw Exceptions
 * @access final
 * 
 * Can't extend from it, it's a finall class.
 * Class auto call a handled class "name" from event.
 * 
 */

final class Dispatcher {

  private $_handle;
  private $_response;

  /**
   * @method __construct
   * @access public
   * @param string a event name
   * @return void
   * 
   * Method set a event.
   * 
   */
  public function __construct($event) {
    $this->_handle = $event;
  }

  /**
   * @method handleEvent
   * @access public
   * @param void
   * @return void
   * 
   * That event handle is a class "name".
   * Method check that handle exist.
   * 
   */
  public function handleEvent() {
    try {
      $name = 'Handler'.ucfirst($this->_handle);
      if ( class_exists("$name") ) {
	$handObj = new $name($this->_handle);
	$this->_response = $handObj->handledEvent();
      } else {
	throw new Exception ('Can\'t handle this Event');
      }
    } catch (Exception $e) {
      printf ('Error: %s',$e->getMessage());
    }
  }

  /**
   * @method getResponse
   * @access public
   * @param void
   * @return String plain text, etc.
   * 
   * Method return a _response.
   * 
   */
  public function getResponse() {
    return $this->_response;
  }

}
Return current item: Dispatcher