1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230:
<?php
/**
* Persistable object registry
*
* @copyright http://www.impresscms.org/ The ImpressCMS Project
* @license LICENSE.txt
* @category ICMS
* @package Ipf
* @subpackage Registry
* @since 1.1
* @author marcan <marcan@impresscms.org>
* @version SVN: $Id:Handler.php 19775 2010-07-11 18:54:25Z malanciault $
*/
defined('ICMS_ROOT_PATH') or die('ImpressCMS root path not defined');
/**
* Registry of icms_ipf_Object
*
* Class responsible of caching objects to make them easily reusable without querying the database
*
* @copyright The ImpressCMS Project http://www.impresscms.org/
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @category ICMS
* @package Ipf
* @subpackage Object
* @since 1.1
* @author marcan <marcan@impresscms.org>
*/
class icms_ipf_registry_Handler {
/**
*
* @var unknown_type
*/
private $_registryArray;
/**
* Access the only instance of this class
*
* @return object
*
* @static
* @staticvar object
*/
static public function &getInstance() {
static $instance;
if (!isset($instance)) {
$instance = new icms_ipf_registry_Handler();
}
return $instance;
}
/**
* Adding objects to the registry
*
* @param icms_ipf_Handler $handler of the objects to add
* @param icms_db_criteria_Compo $criteria to pass to the getObjects method of the handler (with id_as_key)
*
* @return FALSE if an error occured
*/
public function addObjectsFromHandler(&$handler, $criteria = false) {
if (method_exists($handler, 'getObjects')) {
$objects = $handler->getObjects($criteria, true);
$this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects;
return $objects;
} else {
return false;
}
}
/**
* Adding objects as list to the registry
*
* @param icms_ipf_Handler $handler of the objects to add
* @param icms_db_criteria_Compo $criteria to pass to the getObjects method of the handler (with id_as_key)
*
* @return FALSE if an error occured
*/
public function addListFromHandler(&$handler, $criteria = false) {
if (method_exists($handler, 'getList')) {
$list = $handler->getList($criteria);
$this->_registryArray['list'][$handler->_moduleName][$handler->_itemname] = $list;
return $list;
} else {
return false;
}
}
/**
* Adding objects to the registry from an item name
* This method will fetch the handler of the item / module and call the addObjectsFromHandler
*
* @param string $item name of the item
* @param string $modulename name of the module
* @param icms_db_criteria_Compo $criteria to pass to the getObjects method of the handler (with id_as_key)
*
* @return FALSE if an error occured
*/
public function addObjectsFromItemName($item, $modulename = false, $criteria = false) {
if (!$modulename) {
global $icmsModule;
if (!is_object($icmsModule)) {
return false;
} else {
$modulename = $icmsModule->getVar("dirname");
}
}
$object_handler = icms_getModuleHandler($item, $modulename);
return $this->addObjectsFromHandler($object_handler, $criteria);
}
/**
* Adding objects as a list to the registry from an item name
* This method will fetch the handler of the item / module and call the addListFromHandler
*
* @param string $item name of the item
* @param string $modulename name of the module
* @param icms_db_criteria_Compo $criteria to pass to the getObjects method of the handler (with id_as_key)
*
* @return FALSE if an error occured
*/
public function addListFromItemName($item, $modulename = false, $criteria = false) {
if (!$modulename) {
global $icmsModule;
if (!is_object($icmsModule)) {
return false;
} else {
$modulename = $icmsModule->getVar("dirname");
}
}
$object_handler = icms_getModuleHandler($item, $modulename);
return $this->addListFromHandler($object_handler, $criteria);
}
/**
* Fetching objects from the registry
*
* @param string $itemname
* @param string $modulename
*
* @return the requested objects or FALSE if they don't exists in the registry
*/
public function getObjects($itemname, $modulename) {
if (!$modulename) {
global $icmsModule;
if (!is_object($icmsModule)) {
return false;
} else {
$modulename = $icmsModule->getVar("dirname");
}
}
if (isset($this->_registryArray['objects'][$modulename][$itemname])) {
return $this->_registryArray['objects'][$modulename][$itemname];
} else {
// if they were not in registry, let's fetch them and add them to the reigistry
$module_handler = icms_getModuleHandler($itemname, $modulename);
if (method_exists($module_handler, 'getObjects')) {
$objects = $module_handler->getObjects();
}
$this->_registryArray['objects'][$modulename][$itemname] = $objects;
return $objects;
}
}
/**
* Fetching objects from the registry, as a list : objectid => identifier
*
* @param string $itemname
* @param string $modulename
*
* @return the requested objects or FALSE if they don't exists in the registry
*/
public function getList($itemname, $modulename) {
if (!$modulename) {
global $icmsModule;
if (!is_object($icmsModule)) {
return false;
} else {
$modulename = $icmsModule->getVar("dirname");
}
}
if (isset($this->_registryArray['list'][$modulename][$itemname])) {
return $this->_registryArray['list'][$modulename][$itemname];
} else {
// if they were not in registry, let's fetch them and add them to the reigistry
$module_handler = icms_getModuleHandler($itemname, $modulename);
if (method_exists($module_handler, 'getList')) {
$objects = $module_handler->getList();
}
$this->_registryArray['list'][$modulename][$itemname] = $objects;
return $objects;
}
}
/**
* Retreive a single object
*
* @param string $itemname
* @param string $key
*
* @return the requestd object or FALSE if they don't exists in the registry
*/
public function getSingleObject($itemname, $key, $modulename = false) {
if (!$modulename) {
global $icmsModule;
if (!is_object($icmsModule)) {
return false;
} else {
$modulename = $icmsModule->getVar("dirname");
}
}
if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) {
return $this->_registryArray['objects'][$modulename][$itemname][$key];
} else {
$objectHandler = icms_getModuleHandler($itemname, $modulename);
$object = $objectHandler->get($key);
if (!$object->isNew()) {
$this->_registryArray['objects'][$modulename][$itemname][$key] = $object;
return $object;
} else {
return false;
}
}
}
}