PluginProbe
DoLogin Security / trunk
DoLogin Security vtrunk
5.0.10 4.8.3 trunk 1.0 1.1 1.1.1 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.6 All 64 releases
dologin / src / instance.cls.php

instance.cls.php in DoLogin Security trunk, at src/instance.cls.php

47 lines 969 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The abstract instance
4 *
5 * @since 1.0
6 */
7 namespace dologin;
8
9 defined( 'WPINC' ) || exit;
10
11 abstract class Instance {
12 private static $_instances;
13
14 /**
15 * Load an instance or create it if not existed
16 *
17 * @since 3.0
18 */
19 public static function cls( $cls = false ) {
20 if ( ! $cls ) {
21 $cls = self::ori_cls();
22 }
23 $cls = __NAMESPACE__ . '\\' . $cls;
24
25 $cls_tag = strtolower( $cls );
26 if ( ! isset( self::$_instances[ $cls_tag ] ) ) {
27 self::$_instances[ $cls_tag ] = new $cls();
28 }
29
30 return self::$_instances[ $cls_tag ];
31 }
32
33 /**
34 * Get called class short name
35 */
36 public static function ori_cls() {
37 $cls = new \ReflectionClass( get_called_class() );
38 $shortname = $cls->getShortName();
39 $namespace = str_replace( __NAMESPACE__ . '\\', '', $cls->getNamespaceName() . '\\' );
40 if ( $namespace ) { // the left namespace after dropped root namespace
41 $shortname = $namespace . $shortname;
42 }
43
44 return $shortname;
45 }
46 }
47