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
54
55
56
57
58
59
60
61
62
63
64
|
<?php
namespace Objectiv\Plugins\Checkout;
/** * Enforces a single instance of an object. Useful for mission critical objects that should never be duplicated beyond * plugin initialization * * @link objectiv.co * @since 1.0.0 * @package Objectiv\BoosterSeat\Base * @author Brandon Tassone <[email protected]> */
abstract class SingletonAbstract {
/** * @since 1.0.0 * @access private * @var null */ protected static $instance = array();
/** * Singleton constructor. Just a stub. Do not fill with logic * * @since 1.0.0 * @access private */ private function __construct() {}
/** * Clone method. Just a stub. Do not fill with logic * * @since 1.0.0 * @access private */ private function __clone() {}
/** * Wakeup method. Just a stub. Do not fill with logic * * @since 1.0.0 * @access private */ public function __wakeup() {}
/** * Returns the class instantiated instance. Will return the first instance generated, and nothing else. * * @since 1.0.0 * @access public * @return null|static */ final public static function instance() { $class = (string) get_called_class();
if ( ! array_key_exists( $class, self::$instance ) ) { self::$instance[ $class ] = new static(); }
return self::$instance[ $class ]; } }
|