-
Notifications
You must be signed in to change notification settings - Fork 0
/
Singleton.php
41 lines (34 loc) · 1.18 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
<?php
/************************************************************
* icarus v1.0-beta -- an IRC framework for PHP *
* Author: rintaun - Matthew J. Lanigan <rintaun@gmail.com> *
* *
* Copyright 2011 Matthew J. Lanigan. *
* See LICENSE file for licensing restrictions *
************************************************************/
if (!defined('_ICARUS_')) die('This script may not be invoked directly.' . "\n");
abstract class Singleton extends EventHandler
{
protected static $_instances;
final protected function __construct() {}
abstract protected function _create();
abstract protected function _destroy();
final public static function getInstance()
{
$c = get_called_class();
if (!isset(self::$_instances[$c]))
{
self::$_instances[$c] = new $c;
call_user_func_array(array(self::$_instances[$c], "_create"), func_get_args());
}
return self::$_instances[$c];
}
final public function __destruct()
{
$c = get_called_class();
$this->_destroy();
if (isset(self::$_instances[$c]))
unset(self::$_instances[$c]);
}
final protected function __clone() { }
}