PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
← All changes | includes/GetInstance.php +60 -0 0.2.5.6trunk View file →
@@ -1,0 +1,60 @@
1 +<?php
2 +/**
3 + * GetInstance File
4 + *
5 + * @package NotificationX
6 + */
7 +
8 +namespace NotificationX;
9 +
10 +/**
11 + * Base trait make the instances of called class.
12 + */
13 +trait GetInstance {
14 + /**
15 + * Instance of Called Class.
16 + *
17 + * @var GetInstance
18 + */
19 + protected static $instance = null;
20 +
21 + /**
22 + * Get the instance of called class.
23 + *
24 + */
25 + public static function get_instance($args = null){
26 + $class = get_called_class();
27 + if ( is_null( static::$instance ) || ! static::$instance instanceof self || (strpos($class, "NotificationXPro\\") === 0 && ! static::$instance instanceof $class) ) {
28 + $class = __CLASS__;
29 + if(strpos($class, "NotificationX\\") === 0){
30 + $pro_class = str_replace("NotificationX\\", "NotificationXPro\\", $class);
31 + if(class_exists($pro_class) && is_subclass_of($pro_class, $class)){
32 + $class = $pro_class;
33 + }
34 + }
35 +
36 + if(!empty($args)){
37 + static::$instance = new $class($args);
38 + }
39 + else{
40 + static::$instance = new $class;
41 + }
42 + }
43 + return static::$instance;
44 + }
45 +
46 + // public function __call($name, $arguments){
47 + // $class = __CLASS__ . 'Pro';
48 +
49 + // if(strpos($class, "NotificationX\\") === 0){
50 + // $pro_class = str_replace("NotificationX\\", "NotificationXPro\\", $class);
51 + // if(class_exists($pro_class)){
52 + // $obj = $pro_class::get_instance();
53 + // if($obj && method_exists($obj, $name)){
54 + // $obj->$name($arguments);
55 + // }
56 + // }
57 + // }
58 + // }
59 +
60 +}