-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSingleton.php
53 lines (50 loc) · 1.29 KB
/
Singleton.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Flipside;
/**
* Singleton class
*
* This file describes the Singleton parent class
*
* PHP version 5 and 7
*
* @author Patrick Boyd / [email protected]
* @copyright Copyright (c) 2015, Austin Artistic Reconstruction
* @license http://www.apache.org/licenses/ Apache 2.0 License
*/
/**
* A class that only allows a single instance to be created.
*
* This class only allows a single instance to be created. This is especially useful for
* database and other abstractions to reduce the number of connections.
*/
class Singleton
{
/**
* Return the instance of the object
*
* This function returns the object instance if it exists and if not it will create a new copy
*/
public static function getInstance()
{
static $instances = array();
$class = get_called_class();
if(!isset($instances[$class]))
{
$instances[$class] = new static();
}
return $instances[$class];
}
/**
* A singleton constructor should not be publically accessible. All callers should use getInstance()
*/
protected function __construct()
{
}
/**
* A singleton can not be cloned
*/
private function __clone()
{
}
}
/* vim: set tabstop=4 shiftwidth=4 expandtab: */