Location: PHPKode > projects > Astrocytes > htdocs/include/handlerregistry.php
<?php

//  ------------------------------------------------------------------------ //
//                                                                           //
//            Astrocytes - Medical Managment Systems                         //
//              Copyright (c) 2005 astrocytes.org                            //
//              <http://www.astrocytes.org/>                                 //
//              <http://sourceforge.net/projects/astroarm/>                  //
//              BY YAZID JIBREL                                              //
//              hide@address.com                                       //
//              Based on XOOPS CMS <xoops.org>                               //
//  ------------------------------------------------------------------------ //
//  This program 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.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software <gnu.org>    //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
//  ------------------------------------------------------------------------ //
// Authors: author name (hide@address.com),                      //
// URL: http://www.astrocytes.org                                            //
// Package: Package name                                                     //
// Project: Astrocytes                                                       //
// version: 1.1                                                              //
// ------------------------------------------------------------------------- //

/**
 * A registry for holding references to {@link AstroObjectHandler} classes
 * 
 * @package     include
 * 
 * @author	    Kazumi Ono	<hide@address.com>
 * @copyright	copyright (c) 2000-2003 ASTRO.org
 */

class AstroHandlerRegistry
{
    /**
     * holds references to handler class objects
     * 
     * @var     array
     * @access	private
     */
    var $_handlers = array();

	/**
	 * get a reference to the only instance of this class
     * 
     * if the class has not been instantiated yet, this will also take 
     * care of that
	 * 
     * @static
     * @staticvar   object  The only instance of this class
     * @return      object  Reference to the only instance of this class
	 */
    function &instance()
    {
        static $instance;
        if (!isset($instance)) {
            $instance = new AstroHandlerRegistry();
        }
        return $instance;
    }

    /**
     * Register a handler class object
     * 
     * @param	string  $name     Short name of a handler class
     * @param	object  &$handler {@link AstroObjectHandler} class object
     */
    function setHandler($name, &$handler)
    {
        $this->_handlers['include'][$name] =& $handler;
    }

    /**
     * Get a registered handler class object
     * 
     * @param	string  $name     Short name of a handler class
     * 
     * @return	object {@link AstroObjectHandler}, FALSE if not registered
     */
    function &getHandler($name)
    {
        if (!isset($this->_handlers['include'][$name])) {
            return false;
        }
        return $this->_handlers['include'][$name];
    }

    /**
     * Unregister a handler class object
     * 
     * @param	string  $name     Short name of a handler class
     */
    function unsetHandler($name)
    {
        unset($this->_handlers['include'][$name]);
    }

    /**
     * Register a handler class object for a module
     * 
     * @param	string  $module   Directory name of a module
     * @param	string  $name     Short name of a handler class
     * @param	object  &$handler {@link AstroObjectHandler} class object
     */
    function setModuleHandler($module, $name, &$handler)
    {
        $this->_handlers['module'][$module][$name] =& $handler;
    }

    /**
     * Get a registered handler class object for a module
     * 
     * @param	string  $module   Directory name of a module
     * @param	string  $name     Short name of a handler class
     * 
     * @return	object {@link AstroObjectHandler}, FALSE if not registered
     */
    function &getModuleHandler($module, $name)
    {
        if (!isset($this->_handlers['module'][$module][$name])) {
            return false;
        }
        return $this->_handlers['module'][$module][$name];
    }

    /**
     * Unregister a handler class object for a module
     * 
     * @param	string  $module   Directory name of a module
     * @param	string  $name     Short name of a handler class
     */
    function unsetModuleHandler($module, $name)
    {
        unset($this->_handlers['module'][$module][$name]);
    }

}
?>
Return current item: Astrocytes