Source for file BitSingleton.php
Documentation is available at BitSingleton.php
* Base class for all objects where only one object should be created
* Copyright (c) 2004 bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
* Virtual base class (as much as one can have such things in PHP) for all
* derived tikiwiki classes that require database access.
* @author spider <spider@steelsun.com>
require_once( KERNEL_PKG_PATH . 'BitBase.php' );
protected static $singletons = null;
$class = static::getClass();
$globalVarName = !empty( $pVarName ) ? $pVarName : 'g'. $class;
if( !($ $globalVarName = static::loadFromCache( 'Singleton' )) ) {
$ $globalVarName = new $class;
if(!isset (static::$singletons[$globalVarName])) {
static::$singletons[$globalVarName] = $ $globalVarName;
$gBitSmarty->assign_by_ref( $globalVarName, $ $globalVarName );
return static::$singletons[$globalVarName];
// I don't remember where I found this, but this is to allow php < 5.3 to use this method.
throw new Exception("Cannot find called class -> stack level too deep.");
if (!isset ($bt[$l]['type'])) {
throw new Exception('type not set');
switch ($bt[$l]['type']) {
$lines = file($bt[$l]['file']);
$callerLine = $lines[$bt[$l]['line'] - $i] . $callerLine;
} while (stripos($callerLine, $bt[$l]['function']) === false);
preg_match('/([a-zA-Z0-9\_]+)::' . $bt[$l]['function'] . '/', $callerLine, $matches);
if (!isset ($matches[1])) {
throw new Exception("Could not find caller class: originating method call is obscured.");
case '->': switch ($bt[$l]['function']) {
// edge case -> get class of calling object
throw new Exception("Edge case fail. __get called on non object.");
default: return $bt[$l]['class'];
default: throw new Exception("Unknown backtrace method type");
|