/** * Type instantiation * * Gets the singleton of a configured object. $id could be any identifier * defined in $GLOBALS['cfg']. * * An internal register is mantained to avoid singleton() calls with the * same $id. * * @param mixed $id Instance identifier * @param bool $required true if errors must be fatals * @return TIP_Type The reference to the requested instance or * false on errors */ public static function &getInstance($id, $required = true) { static $register = array(); global $cfg; $id = strtolower($id); if (class_exists('TIP_Application')) { $namespace = TIP_Application::getGlobal('namespace'); if (!empty($namespace) && isset($cfg[$namespace . '_' . $id])) { $id = $namespace . '_' . $id; } } if (array_key_exists($id, $register)) { return $register[$id]; } if (isset($cfg[$id])) { $options = $cfg[$id]; isset($options['id']) || ($options['id'] = $id); $instance =& TIP_Type::singleton($options); } else { $instance = null; } if (is_null($instance) && $required) { TIP::fatal("unable to instantiate the requested object ({$id})"); exit; } $register[$id] =& $instance; return $instance; }
/** * Get an option * * Gets a configuration option for a specified type. All the option values * are defined in the config file. * * @param string $type Descriptor of the type * @param string $option The option to retrieve * @return mixed|null The requested option or null on errors */ public static function getOption($type, $option, $required = false) { $value = @$GLOBALS['cfg'][$type][$option]; if ($required && !isset($value)) { TIP::fatal("Required option not defined (\$cfg['{$type}']['{$option}'])"); } return $value; }