PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / traits / abstract-singleton.php

abstract-singleton.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/traits/abstract-singleton.php

50 lines 980 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Singleton that can be used inside abstract classes.
4 *
5 * @version 1.0.0
6 * @since StoreEngine v1.6.7
7 */
8
9 namespace StoreEngine\Traits;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 trait AbstractSingleton {
16
17 protected static array $instances = [];
18
19 public static function init() {
20 return self::get_instance();
21 }
22
23 public static function get_instance() {
24 $called = static::class;
25
26 if ( ! isset( self::$instances[ $called ] ) ) {
27 self::$instances[ $called ] = new $called();
28 }
29
30 return self::$instances[ $called ];
31 }
32
33 protected function __construct() {
34 }
35
36 /**
37 * Cloning is forbidden.
38 */
39 public function __clone() {
40 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'storeengine' ), '1.6.7' );
41 }
42
43 /**
44 * Unserializing instances of this class is forbidden.
45 */
46 public function __wakeup() {
47 _doing_it_wrong( __FUNCTION__, esc_html__( 'Unserializing instances of this class is forbidden.', 'storeengine' ), '1.6.7' );
48 }
49 }
50