/** * Check if a module exists * * Expands to true if the module module exists or to false * otherwise. This tag only checks if the logic file for the $params * module exists, does not load the module itsself nor change * the default module. * * Useful to provide conditional links between different modules. */ protected function tagModuleExists($params) { $file = TIP::buildLogicPath('module', $params) . '.php'; return is_readable($file) ? 'true' : 'false'; }
/** * Singleton method * * Manages the singletons. Given a hierarchy of parent types and a string * identifier, this method returns a singleton of the instantiated object. * If the object is not found, it is dinamically defined and instantiated. * * The singletons are stored in a static tree, called register, containing * all the hierarchy of the instantiated types. * * If $options is not specified, the whole register is returned. * * If $options is a string, it must specify a valid type: a partial * register content of this type is returned. * * In the other cases, $options must be an array of options, and a * singleton for the specified object is returned. In this situation, * $options must have at least the following items: * - $options['id']: the instance identifier * - $options['type']: an array containing the parent types of the instance. * These types must be lowercase strings specifying the * parent classes of the instance (TIP_Type excluded) * without TIP_PREFIX. Using array('module', 'content'), * for instance, will instantiate a TIP_Content object. * * Some type automatically fills $options['id'] after the checkOptions() * call: check the documentation for each class for further information. * * @param array|string|null $options Constructor options * @param bool $dont_store Don't store the instance * in the register * @return array|object|null The register content, a reference * to the requested instance or null * on instantiation errors */ protected static function &singleton($options = null, $dont_store = false) { static $register = array(); static $flat_register = array(); if (empty($options)) { // Return the whole register content return $register; } elseif (is_string($options)) { // Return a partial register content return $flat_register[$options]; } $type = end($options['type']); if (array_key_exists($type, $flat_register)) { // Hierarchy yet defined $list =& $flat_register[$type]; } elseif (array_key_exists('include', $options)) { // Explicit include file: suppose the parents are yet defined if (include_once $options['include']) { $list[$type] = array(); $flat_register[$type] =& $list[$type]; } else { // Definition impossible: this avoid next attempts die("cazzo!\n"); $list[$type] = $flat_register[$type] = null; return $list[$type]; } $list =& $list[$type]; } else { // Hierarchy to be defined $path = TIP::buildLogicPath('Type'); $list =& $register; foreach ($options['type'] as $type) { $path .= DIRECTORY_SEPARATOR . $type; if (!array_key_exists($type, $list)) { // Dynamic type definition $file = $path . '.php'; if (include_once $file) { $list[$type] = array(); $flat_register[$type] =& $list[$type]; } else { // Definition impossible: this avoid next attempts $list[$type] = $flat_register[$type] = null; return $list[$type]; } } $list =& $list[$type]; } } $class = TIP_PREFIX . $type; if (!call_user_func_array(array($class, 'checkOptions'), array(&$options))) { // Invalid options, maybe a requested option is not specified $fake_null = null; return $fake_null; } if ($dont_store) { $instance = new $class($options); $instance->postConstructor(); } else { $id = $options['id']; if (!array_key_exists($id, $list)) { // Object instantiation $instance = new $class($options); // Registration $list[$id] =& $instance; // postConstructor() call: must be done after the registration // to avoid circular dependency $instance->postConstructor(); } else { $instance =& $list[$id]; } } return $instance; }
* but also Text_Wiki, HTML_QuickForm and HTML_Menu). */ error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); /** * The default encoding for TIP based sites is utf8. */ mb_internal_encoding('UTF-8'); /** * Defs.php must precede anything */ require_once 'Defs.php'; require_once 'Renderer.php'; set_include_path(TIP::buildLogicPath('pear')); require_once 'PEAR.php'; require_once 'HTTP.php'; require_once TIP::buildLogicPath('Type.php'); /** * A collection of global functions * * A static class root of all the TIP hierarchy. It provides some global useful * functions. * * * @package TIP */ class TIP { //{{{ Internal methods private static function _getTyped($id, $type, &$collection) { $value = @$collection[$id];