New database system that uses PDO if present/Test script for doing database upgrades.
This commit is contained in:
parent
2846dfeb05
commit
405dd794fe
13 changed files with 3256 additions and 0 deletions
44
library/dddbl2/inc/Singleton.class.php
Normal file
44
library/dddbl2/inc/Singleton.class.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace DDDBL;
|
||||
|
||||
/**
|
||||
* simple implementation of generic singleton
|
||||
* for all classes, which allows additional instances
|
||||
* if needed
|
||||
*
|
||||
**/
|
||||
|
||||
class Singleton {
|
||||
|
||||
/**
|
||||
* @param $strClass - the class we want an instance from
|
||||
*
|
||||
* @throws UnexpectedParameterTypeException - if given parameter is not a string
|
||||
* @throws \Exception - if given class do not exists
|
||||
*
|
||||
* @return (object) - an instance of the given classname
|
||||
*
|
||||
* get a reference to the instance of the given class.
|
||||
* if instance do not exists, create one. after creation
|
||||
* always return reference to this reference
|
||||
*
|
||||
**/
|
||||
static function getInstance($strClass) {
|
||||
|
||||
if(!is_string($strClass))
|
||||
throw new UnexpectedParameterTypeException('string', $strClass);
|
||||
|
||||
if(!class_exists($strClass))
|
||||
throw new \Exception ("class do not exists: $strClass");
|
||||
|
||||
static $arrObjectList = array();
|
||||
|
||||
if(!isset($arrObjectList[$strClass]))
|
||||
$arrObjectList[$strClass] = new $strClass();
|
||||
|
||||
return $arrObjectList[$strClass];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue