/** * Returns a reference to the a Helper object, only creating it if it doesn't already exist * * @param type $type The helper type to instantiate * @param string $prefix A prefix for the helper class name. Optional. * @return helper The Helper Object */ public static function getInstance($type = 'Base', $prefix = 'TiendaHelper') { //parent::getInstance( $type , $prefix ); static $instances; if (!isset($instances)) { $instances = array(); } $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); // The Base helper is in _base.php, but it's named TiendaHelperBase if (strtolower($type) == 'Base') { $helperClass = $prefix . ucfirst($type); $type = '_Base'; } $helperClass = $prefix . ucfirst($type); if (empty($instances[$helperClass])) { if (!class_exists($helperClass)) { jimport('joomla.filesystem.path'); if ($path = JPath::find(TiendaHelperBase::addIncludePath(), strtolower($type) . '.php')) { require_once $path; if (!class_exists($helperClass)) { JError::raiseWarning(0, 'Helper class ' . $helperClass . ' not found in file.'); return false; } } else { JError::raiseWarning(0, 'Helper ' . $type . ' not supported. File not found.'); return false; } } $instance = new $helperClass(); $instances[$helperClass] =& $instance; } return $instances[$helperClass]; }