-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleton.php
More file actions
49 lines (44 loc) · 933 Bytes
/
Singleton.php
File metadata and controls
49 lines (44 loc) · 933 Bytes
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
<?php
namespace Colibri\Pattern;
/**
* Represent a singleton pattern:
* not public __construct, __clone & __wakeup,
* implement ::getInstance().
*/
abstract class Singleton
{
/**
* @var static
*/
protected static $instance = null;
/**
* Singleton constructor.
*/
abstract protected function __construct();
/**
* Close public access.
*
* @codeCoverageIgnore
*/
private function __clone()
{
}
/**
* Close public access/.
*
* @codeCoverageIgnore
*/
public function __wakeup()
{
throw new \BadMethodCallException('The class `' . static::class . '` is Singleton and can\'t be `__wakeup()`');
}
/**
* @return static
*/
public static function getInstance()
{
return static::$instance === null
? static::$instance = new static()
: static::$instance;
}
}