PluginProbe
DoLogin Security / 4.2
DoLogin Security v4.2
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 4.2, at src/instance.cls.php

44 lines 957 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 defined( 'WPINC' ) || exit;
9
10 abstract class Instance {
11 private static $_instances;
12
13 /**
14 * Load an instance or create it if not existed
15 * @since 3.0
16 */
17 public static function cls( $cls = false ) {
18 if ( ! $cls ) {
19 $cls = self::ori_cls();
20 }
21 $cls = __NAMESPACE__ . '\\' . $cls;
22
23 $cls_tag = strtolower( $cls );
24 if ( ! isset( self::$_instances[ $cls_tag ] ) ) {
25 self::$_instances[ $cls_tag ] = new $cls();
26 }
27
28 return self::$_instances[ $cls_tag ];
29 }
30
31 /**
32 * Get called class short name
33 */
34 public static function ori_cls() {
35 $cls = new \ReflectionClass( get_called_class() );
36 $shortname = $cls->getShortName();
37 $namespace = str_replace( __NAMESPACE__ . '\\', '', $cls->getNamespaceName() . '\\' );
38 if ( $namespace ) { // the left namespace after dropped root namespace
39 $shortname = $namespace . $shortname;
40 }
41
42 return $shortname;
43 }
44 }