| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
/** |
| 4 |
* The abstract class for maintaing singleton design pattern |
| 5 |
* |
| 6 |
* @link http://rextheme.com/ |
| 7 |
* @since 8.0.0 |
| 8 |
* |
| 9 |
* @package Wpvr |
| 10 |
* @subpackage Wpvr/admin/views |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* Orginial Singleton class |
| 15 |
*/ |
| 16 |
abstract class Singleton { |
| 17 |
|
| 18 |
/** |
| 19 |
* Any Singleton class |
| 20 |
* |
| 21 |
* @var Singleton[] $instances |
| 22 |
* @since 8.0.0 |
| 23 |
*/ |
| 24 |
private static $instances = array(); |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* Private construct to avoid 'new' |
| 29 |
* |
| 30 |
* @since 8.0.0 |
| 31 |
*/ |
| 32 |
private function __construct() |
| 33 |
{ |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* Get Instacne |
| 40 |
* |
| 41 |
* @return Singleton |
| 42 |
* @since 8.0.0 |
| 43 |
*/ |
| 44 |
final public static function get_instance() { |
| 45 |
$class = get_called_class(); |
| 46 |
|
| 47 |
if ( ! isset( $instances[ $class ] ) ) { |
| 48 |
self::$instances[ $class ] = new $class(); |
| 49 |
} |
| 50 |
|
| 51 |
return self::$instances[ $class ]; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
/** |
| 56 |
* Declared to overwrite magic method __clone() |
| 57 |
* In order to prevent object cloning |
| 58 |
* |
| 59 |
* @return void |
| 60 |
* @since 8.0.0 |
| 61 |
*/ |
| 62 |
private function __clone() |
| 63 |
{ |
| 64 |
// Do nothing |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/** |
| 69 |
* Declared to overwrite magic method __sleep() |
| 70 |
* In order to avoid serialize instance |
| 71 |
* |
| 72 |
* @return void |
| 73 |
* @since 8.0.0 |
| 74 |
*/ |
| 75 |
public function __sleep() |
| 76 |
{ |
| 77 |
// Do nothing |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
/** |
| 82 |
* Declared to overwrite magic method __wakeup() |
| 83 |
* In order to avoid unserialize instance |
| 84 |
* |
| 85 |
* @return void |
| 86 |
* @since 8.0.0 |
| 87 |
*/ |
| 88 |
public function __wakeup() |
| 89 |
{ |
| 90 |
// Do nothing |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/** |
| 95 |
* Responsible for rendering setting tabs |
| 96 |
* |
| 97 |
* @param array $postdata |
| 98 |
* |
| 99 |
* @return void |
| 100 |
* @since 8.0.0 |
| 101 |
*/ |
| 102 |
abstract static public function render($postdata); |
| 103 |
|
| 104 |
/** |
| 105 |
* Responsible for rendering setting meta fields |
| 106 |
* |
| 107 |
* @param array $postdata |
| 108 |
* |
| 109 |
* @return void |
| 110 |
* @since 8.0.0 |
| 111 |
*/ |
| 112 |
abstract static public function render_meta_fields($postdata); |
| 113 |
} |