DDDBL 2.0
 All Classes Namespaces Files Functions Variables
Static Public Member Functions | List of all members
DDDBL\Singleton Class Reference

Static Public Member Functions

static getInstance ($strClass)
 

Detailed Description

simple implementation of generic singleton for all classes, which allows additional instances if needed

Definition at line 12 of file Singleton.class.php.

Member Function Documentation

static DDDBL\Singleton::getInstance (   $strClass)
static
Parameters
$strClass- the class we want an instance from
Exceptions
UnexpectedParameterTypeException- if given parameter is not a string
\Exception- if given class do not exists
Returns
(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

Definition at line 27 of file Singleton.class.php.

Referenced by DDDBL\get().

27  {
28 
29  if(!is_string($strClass))
30  throw new UnexpectedParameterTypeException('string', $strClass);
31 
32  if(!class_exists($strClass))
33  throw new \Exception ("class do not exists: $strClass");
34 
35  static $arrObjectList = array();
36 
37  if(!isset($arrObjectList[$strClass]))
38  $arrObjectList[$strClass] = new $strClass();
39 
40  return $arrObjectList[$strClass];
41 
42  }

The documentation for this class was generated from the following file: