1<?php 2/** 3 * XOOPS Kernel Class 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) 13 * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) 14 * @package kernel 15 * @since 2.0.0 16 * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ 17 */ 18defined('XOOPS_ROOT_PATH') || exit('Restricted access'); 19 20/** 21 * A registry for holding references to {@link XoopsObjectHandler} classes 22 * 23 * @package kernel 24 * 25 * @author Kazumi Ono <onokazu@xoops.org> 26 * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) 27 */ 28class XoopsHandlerRegistry 29{ 30 /** 31 * holds references to handler class objects 32 * 33 * @var array 34 * @access private 35 */ 36 public $_handlers = array(); 37 38 /** 39 * get a reference to the only instance of this class 40 * 41 * if the class has not been instantiated yet, this will also take 42 * care of that 43 * 44 * @static 45 * @staticvar object The only instance of this class 46 * @return XoopsHandlerRegistry Reference to the only instance of this class 47 */ 48 public function instance() 49 { 50 static $instance; 51 if (!isset($instance)) { 52 $instance = new XoopsHandlerRegistry(); 53 } 54 55 return $instance; 56 } 57 58 /** 59 * Register a handler class object 60 * 61 * @param string $name Short name of a handler class 62 * @param XoopsObjectHandler &$handler {@link XoopsObjectHandler} class object 63 */ 64 public function setHandler($name, XoopsObjectHandler $handler) 65 { 66 $this->_handlers['kernel'][$name] =& $handler; 67 } 68 69 /** 70 * Get a registered handler class object 71 * 72 * @param string $name Short name of a handler class 73 * 74 * @return XoopsObjectHandler {@link XoopsObjectHandler}, FALSE if not registered 75 */ 76 public function getHandler($name) 77 { 78 if (!isset($this->_handlers['kernel'][$name])) { 79 return false; 80 } 81 82 return $this->_handlers['kernel'][$name]; 83 } 84 85 /** 86 * Unregister a handler class object 87 * 88 * @param string $name Short name of a handler class 89 */ 90 public function unsetHandler($name) 91 { 92 unset($this->_handlers['kernel'][$name]); 93 } 94 95 /** 96 * Register a handler class object for a module 97 * 98 * @param string $module Directory name of a module 99 * @param string $name Short name of a handler class 100 * @param XoopsObjectHandler &$handler {@link XoopsObjectHandler} class object 101 */ 102 public function setModuleHandler($module, $name, XoopsObjectHandler $handler) 103 { 104 $this->_handlers['module'][$module][$name] =& $handler; 105 } 106 107 /** 108 * Get a registered handler class object for a module 109 * 110 * @param string $module Directory name of a module 111 * @param string $name Short name of a handler class 112 * 113 * @return XoopsObjectHandler {@link XoopsObjectHandler}, FALSE if not registered 114 */ 115 public function getModuleHandler($module, $name) 116 { 117 if (!isset($this->_handlers['module'][$module][$name])) { 118 return false; 119 } 120 121 return $this->_handlers['module'][$module][$name]; 122 } 123 124 /** 125 * Unregister a handler class object for a module 126 * 127 * @param string $module Directory name of a module 128 * @param string $name Short name of a handler class 129 */ 130 public function unsetModuleHandler($module, $name) 131 { 132 unset($this->_handlers['module'][$module][$name]); 133 } 134} 135