PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9.3
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9.3
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / abstracts / abstract-singleton.php

abstract-singleton.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9.3, at inc/abstracts/abstract-singleton.php

58 lines 928 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class LP_Abstract_Singleton
4 */
5 abstract class LP_Abstract_Singleton {
6
7 /**
8 * Array of singleton classes.
9 *
10 * @var array
11 */
12 protected static $instances = array();
13
14 /**
15 * LP_Abstract_Singleton constructor.
16 */
17 protected function __construct() {
18 }
19
20 /**
21 * @return mixed
22 */
23 public static function instance() {
24 $name = self::_get_called_class();
25
26 if ( false === $name ) {
27 return false;
28 }
29
30 if ( empty( self::$instances[ $name ] ) ) {
31 self::$instances[ $name ] = new $name();
32 }
33
34 return self::$instances[ $name ];
35 }
36
37 /**
38 * @return bool|string
39 */
40 protected static function _get_called_class() {
41 if ( function_exists( 'get_called_class' ) ) {
42 return get_called_class();
43 }
44
45 $backtrace = debug_backtrace();
46
47 if ( empty( $backtrace[2] ) ) {
48 return false;
49 }
50
51 if ( empty( $backtrace[2]['args'][0] ) ) {
52 return false;
53 }
54
55 return $backtrace[2]['args'][0];
56 }
57 }
58