PluginProbe
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables / 2.2.14
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables v2.2.14
2.2.14 2.2.13 2.2.12 2.2.11 2.2.10 2.2.9 2.2.8 2.2.7 2.2.6 2.2.5 2.2.4 2.2.3 trunk 1.0.0 1.0.1 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2
← All changes | includes/Traits/Singleton.php +25 -4 2.2.82.2.14 View file →
@@ -1,15 +1,36 @@
1 1 <?php
2 +/**
3 + * Generic singleton trait for per-class shared instances
4 + *
5 + * @package TableKit
6 + */
2 7
3 8 namespace TableBuilder\Traits;
9 +
10 +/**
11 + * Generic singleton trait: gives any class a shared instance() accessor
12 + * keyed by class name, so subclasses don't each need to reimplement it.
13 + *
14 + * @package TableBuilder\Traits
15 + */
4 16 trait Singleton {
17 + /**
18 + * Shared instances, keyed by class name.
19 + *
20 + * @var array
21 + */
5 22 private static $instances = array();
6 23
24 + /**
25 + * Gets (and lazily creates) the shared instance of the using class.
26 + *
27 + * @return static The shared instance.
28 + */
7 29 public static function instance() {
8 30 $class = get_called_class();
9 - if ( ! isset( self::$instances[$class] ) ) {
10 - self::$instances[$class] = new $class();
31 + if ( ! isset( self::$instances[ $class ] ) ) {
32 + self::$instances[ $class ] = new $class();
11 33 }
12 - return self::$instances[$class];
34 + return self::$instances[ $class ];
13 35 }
14 36 }
15 -